[ofbiz-framework] branch trunk updated: Improved: Move page-specific script links to html template (OFBIZ-11799)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Improved: Move page-specific script links to html template (OFBIZ-11799)

James Yong-2
This is an automated email from the ASF dual-hosted git repository.

jamesyong pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 39c1e28  Improved: Move page-specific script links to html template (OFBIZ-11799)
39c1e28 is described below

commit 39c1e280f9b4ee8d7b6b4d939b278ab4f653aa4f
Author: James Yong <[hidden email]>
AuthorDate: Sun Aug 16 18:05:32 2020 +0800

    Improved: Move page-specific script links to html template (OFBIZ-11799)
   
    refactoring +
    importLibrary function to use crossDomain = true to allow js file to be shown under browser's sources folder
---
 .../content/template/website/WebSiteCMSNav.ftl     |  3 +-
 .../common-theme/template/includes/GeoLocation.ftl |  4 +-
 .../template/includes/SetMultipleSelectJs.ftl      | 44 +++++++++---------
 .../template/includes/SetMultipleSelectJsList.ftl  | 52 +++++++++++-----------
 .../webapp/common/js/util/OfbizUtil.js             |  9 ++--
 5 files changed, 56 insertions(+), 56 deletions(-)

diff --git a/applications/content/template/website/WebSiteCMSNav.ftl b/applications/content/template/website/WebSiteCMSNav.ftl
index f155685..1a93989 100644
--- a/applications/content/template/website/WebSiteCMSNav.ftl
+++ b/applications/content/template/website/WebSiteCMSNav.ftl
@@ -445,8 +445,7 @@ function createEditor() {
         <#if language?has_content && language != "en">
         libraryFiles.push("/common/js/jquery/plugins/elrte-1.3/js/i18n/elrte.${language!"en"}.js")
         </#if>
-        importLibrary(libraryFiles,
-        function() {
+        importLibrary(libraryFiles, function() {
             var opts = {
                 cssClass : 'el-rte',
                 lang     : '${language!"en"}',
diff --git a/themes/common-theme/template/includes/GeoLocation.ftl b/themes/common-theme/template/includes/GeoLocation.ftl
index c85f722..f87383e 100644
--- a/themes/common-theme/template/includes/GeoLocation.ftl
+++ b/themes/common-theme/template/includes/GeoLocation.ftl
@@ -115,8 +115,8 @@ under the License.
     <#elseif "GEOPT_OSM" == geoChart.dataSourceId>
     <div id="${id}" class="map" style="border:1px solid #979797; background-color:#e5e3df; width:${geoChart.width}; height:${geoChart.height}; margin:2em auto;"></div>
     <script type="application/javascript">
-        importLibrary(["/common/js/plugins/OpenLayers-5.3.0.js", "/common/js/plugins/OpenLayers-5.3.0.css"],
-        function() {
+        var importLibraryFiles = ["/common/js/plugins/OpenLayers-5.3.0.js", "/common/js/plugins/OpenLayers-5.3.0.css"];
+        importLibrary(importLibraryFiles, function() {
             var iconFeatures=[];
 
             <#if geoChart.points?has_content>
diff --git a/themes/common-theme/template/includes/SetMultipleSelectJs.ftl b/themes/common-theme/template/includes/SetMultipleSelectJs.ftl
index ebded16..b02022a 100644
--- a/themes/common-theme/template/includes/SetMultipleSelectJs.ftl
+++ b/themes/common-theme/template/includes/SetMultipleSelectJs.ftl
@@ -19,36 +19,36 @@ under the License.
 <#if asm_multipleSelect??> <#-- we check only this var and suppose the others are also present -->
 <script type="application/javascript">
 jQuery(document).ready(function () {
-    importLibrary(["/common/js/jquery/plugins/select2/js/select2-4.0.6.js",
-            "/common/js/jquery/plugins/select2/css/select2-4.0.6.css",
-            "<@jsLangFilesMap>select2</@jsLangFilesMap>"],
-        function(){
+    var importLibraryFiles = ["/common/js/jquery/plugins/select2/js/select2-4.0.6.js",
+        "/common/js/jquery/plugins/select2/css/select2-4.0.6.css",
+        "<@jsLangFilesMap>select2</@jsLangFilesMap>"];
+    importLibrary(importLibraryFiles, function(){
 
-            multiple = jQuery("#${asm_multipleSelect!}");
+        multiple = jQuery("#${asm_multipleSelect!}");
 
         <#if asm_title??>
-            // set the dropdown "title" if??
-            multiple.attr('title', '${asm_title}');
+        // set the dropdown "title" if??
+        multiple.attr('title', '${asm_title}');
         </#if>
 
-            multiple.select2({
-                tags: true,
-                multiple: true,
-                lang: <#if userLogin??>'${userLogin.lastLocale!"en"}'<#else>"en"</#if>,
-                width: "50%"
-            });
+        multiple.select2({
+            tags: true,
+            multiple: true,
+            lang: <#if userLogin??>'${userLogin.lastLocale!"en"}'<#else>"en"</#if>,
+            width: "50%"
+        });
 
         <#if asm_relatedField??> <#-- can be used without related field -->
-            // track possible relatedField changes
-            // on initial focus (focus-field-name must be asm_relatedField) or if the field value changes, select related multi values.
-            typeValue = jQuery('#${asm_typeField}').val();
-            jQuery("#${asm_relatedField}").one('focus', function () {
-                selectMultipleRelatedValues('${asm_requestName}', '${asm_paramKey}', '${asm_relatedField}', '${asm_multipleSelect}', '${asm_type}', typeValue, '${asm_responseName}');
-            });
-            jQuery("#${asm_relatedField}").change(function () {
-                selectMultipleRelatedValues('${asm_requestName}', '${asm_paramKey}', '${asm_relatedField}', '${asm_multipleSelect}', '${asm_type}', typeValue, '${asm_responseName}');
-            });
+        // track possible relatedField changes
+        // on initial focus (focus-field-name must be asm_relatedField) or if the field value changes, select related multi values.
+        typeValue = jQuery('#${asm_typeField}').val();
+        jQuery("#${asm_relatedField}").one('focus', function () {
             selectMultipleRelatedValues('${asm_requestName}', '${asm_paramKey}', '${asm_relatedField}', '${asm_multipleSelect}', '${asm_type}', typeValue, '${asm_responseName}');
+        });
+        jQuery("#${asm_relatedField}").change(function () {
+            selectMultipleRelatedValues('${asm_requestName}', '${asm_paramKey}', '${asm_relatedField}', '${asm_multipleSelect}', '${asm_type}', typeValue, '${asm_responseName}');
+        });
+        selectMultipleRelatedValues('${asm_requestName}', '${asm_paramKey}', '${asm_relatedField}', '${asm_multipleSelect}', '${asm_type}', typeValue, '${asm_responseName}');
         </#if>
     });
 });
diff --git a/themes/common-theme/template/includes/SetMultipleSelectJsList.ftl b/themes/common-theme/template/includes/SetMultipleSelectJsList.ftl
index 32c784d..3aebffd 100644
--- a/themes/common-theme/template/includes/SetMultipleSelectJsList.ftl
+++ b/themes/common-theme/template/includes/SetMultipleSelectJsList.ftl
@@ -21,36 +21,36 @@ under the License.
     <#if row.asm_multipleSelect??>
       <script type="application/javascript">
           jQuery(document).ready(function () {
-              importLibrary(["/common/js/jquery/plugins/select2/js/select2-4.0.6.js",
-                      "/common/js/jquery/plugins/select2/css/select2-4.0.6.css",
-                      "<@jsLangFilesMap>select2</@jsLangFilesMap>"],
-                  function() {
-                      multiple = jQuery("#${row.asm_multipleSelect!}");
+              var importLibraryFiles = ["/common/js/jquery/plugins/select2/js/select2-4.0.6.js",
+                  "/common/js/jquery/plugins/select2/css/select2-4.0.6.css",
+                  "<@jsLangFilesMap>select2</@jsLangFilesMap>"];
+              importLibrary(importLibraryFiles, function() {
+                  multiple = jQuery("#${row.asm_multipleSelect!}");
 
-                      <#if row.asm_title??>
-                      // set the dropdown "title" if??
-                      multiple.attr('title', '${row.asm_title}');
-                      </#if>
+                  <#if row.asm_title??>
+                  // set the dropdown "title" if??
+                  multiple.attr('title', '${row.asm_title}');
+                  </#if>
 
-                      multiple.select2({
-                          tags: true,
-                          multiple: true,
-                          lang: <#if userLogin??>'${userLogin.lastLocale!"en"}'<#else>"en"</#if>,
-                          width: "50%"
-                      });
+                  multiple.select2({
+                      tags: true,
+                      multiple: true,
+                      lang: <#if userLogin??>'${userLogin.lastLocale!"en"}'<#else>"en"</#if>,
+                      width: "50%"
+                  });
 
-                      <#if row.asm_relatedField??> <#-- can be used without related field -->
-                      // track possible relatedField changes
-                      // on initial focus (focus-field-name must be asm_relatedField) or if the field value changes, select related multi values.
-                      typeValue = jQuery('#${row.asm_typeField}').val();
-                      jQuery("#${row.asm_relatedField}").one('focus', function () {
-                          selectMultipleRelatedValues('${row.asm_requestName}', '${row.asm_paramKey}', '${row.asm_relatedField}', '${row.asm_multipleSelect}', '${row.asm_type}', typeValue, '${row.asm_responseName}');
-                      });
-                      jQuery("#${row.asm_relatedField}").change(function () {
-                          selectMultipleRelatedValues('${row.asm_requestName}', '${row.asm_paramKey}', '${row.asm_relatedField}', '${row.asm_multipleSelect}', '${row.asm_type}', typeValue, '${row.asm_responseName}');
-                      });
+                  <#if row.asm_relatedField??> <#-- can be used without related field -->
+                  // track possible relatedField changes
+                  // on initial focus (focus-field-name must be asm_relatedField) or if the field value changes, select related multi values.
+                  typeValue = jQuery('#${row.asm_typeField}').val();
+                  jQuery("#${row.asm_relatedField}").one('focus', function () {
                       selectMultipleRelatedValues('${row.asm_requestName}', '${row.asm_paramKey}', '${row.asm_relatedField}', '${row.asm_multipleSelect}', '${row.asm_type}', typeValue, '${row.asm_responseName}');
-                      </#if>
+                  });
+                  jQuery("#${row.asm_relatedField}").change(function () {
+                      selectMultipleRelatedValues('${row.asm_requestName}', '${row.asm_paramKey}', '${row.asm_relatedField}', '${row.asm_multipleSelect}', '${row.asm_type}', typeValue, '${row.asm_responseName}');
+                  });
+                  selectMultipleRelatedValues('${row.asm_requestName}', '${row.asm_paramKey}', '${row.asm_relatedField}', '${row.asm_multipleSelect}', '${row.asm_type}', typeValue, '${row.asm_responseName}');
+                  </#if>
               });
           });
       </script>
diff --git a/themes/common-theme/webapp/common/js/util/OfbizUtil.js b/themes/common-theme/webapp/common/js/util/OfbizUtil.js
index 3f8ef81..ff7dbc1 100644
--- a/themes/common-theme/webapp/common/js/util/OfbizUtil.js
+++ b/themes/common-theme/webapp/common/js/util/OfbizUtil.js
@@ -101,9 +101,9 @@ function bindObservers(bind_element) {
     });
     jQuery(bind_element).find(".visual-editor").each(function(){
         var self = this;
-        importLibrary(["https://localhost:8443/common/js/jquery/plugins/elrte-1.3/js/elrte.min.js",
-                "https://localhost:8443/common/js/jquery/plugins/elrte-1.3/css/elrte.min.css"],
-        function() {
+        var importLibraryFiles = ["https://localhost:8443/common/js/jquery/plugins/elrte-1.3/js/elrte.min.js",
+            "https://localhost:8443/common/js/jquery/plugins/elrte-1.3/css/elrte.min.css"];
+        importLibrary(importLibraryFiles, function() {
             var element = jQuery(self);
             var toolbar = element.data('toolbar');
             var language = element.data('language');
@@ -1428,8 +1428,9 @@ var importLibrary = function() {
     var importLibraryFiles = new Map();
     return function (urls, onSuccessFn, onErrorFn) {
         function cachedScript(url, options) {
-            // Allow user to set any option except for dataType, cache, and url
+            // Allow user to set any option except for following
             options = $.extend(options || {}, {
+                crossDomain: true, // set to true to allow the file to be shown under browser's sources folder
                 dataType: "script",
                 cache: true,
                 url: url