[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 55df1c7  Improved: Move page-specific script links to html template (OFBIZ-11799)
55df1c7 is described below

commit 55df1c7db06103ed0006cf741019f5ad2291fe0f
Author: James Yong <[hidden email]>
AuthorDate: Sun Aug 16 14:35:35 2020 +0800

    Improved: Move page-specific script links to html template (OFBIZ-11799)
   
    Use importLibrary js function to load elrte js and css
    Tested on
    https://localhost:8443/content/control/findForumMessages?forumGroupId=WebStoreFORUM&forumId=10000
    https://localhost:8443/content/control/WebSiteCms?webSiteId=CmsSite
---
 .../content/template/website/WebSiteCMSNav.ftl     | 20 +++++++------
 .../webapp/common/js/util/OfbizUtil.js             | 33 ++++++++++++++--------
 themes/common-theme/widget/Theme.xml               |  2 --
 3 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/applications/content/template/website/WebSiteCMSNav.ftl b/applications/content/template/website/WebSiteCMSNav.ftl
index f759898..f155685 100644
--- a/applications/content/template/website/WebSiteCMSNav.ftl
+++ b/applications/content/template/website/WebSiteCMSNav.ftl
@@ -18,12 +18,6 @@
   -->
 <script type="application/javascript" src="<@ofbizContentUrl>/common/js/jquery/ui/js/jquery.cookie-1.4.0.js</@ofbizContentUrl>"></script>
 <script type="application/javascript" src="<@ofbizContentUrl>/common/js/jquery/plugins/jsTree/jquery.jstree.js</@ofbizContentUrl>"></script>
-<script type="application/javascript" src="<@ofbizContentUrl>/common/js/jquery/plugins/elrte-1.3/js/elrte.min.js</@ofbizContentUrl>"></script>
-<#if language?has_content && language != "en">
-<script src="<@ofbizContentUrl>/common/js/jquery/plugins/elrte-1.3/js/i18n/elrte.${language!"en"}.js</@ofbizContentUrl>" type="application/javascript"></script><#rt/>
-</#if>
-<link href="/common/js/jquery/plugins/elrte-1.3/css/elrte.min.css" rel="stylesheet" type="text/css">
-
 <script type="application/javascript">
     function modifyJstreeCookieToSelectNewPage() {
         // core.initally_load and ui.initially_select don't work with the cookies plugin,
@@ -444,8 +438,15 @@ var contextmenu = { 'items': {
      }
 
 <#-------------------------------------------------------------------------------------createEditor function-->
-    function createEditor() {
-        if($('#cmseditor').length) {
+function createEditor() {
+    if($('#cmseditor').length) {
+        var libraryFiles = ["/common/js/jquery/plugins/elrte-1.3/js/elrte.min.js",
+                "/common/js/jquery/plugins/elrte-1.3/css/elrte.min.css"];
+        <#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() {
             var opts = {
                 cssClass : 'el-rte',
                 lang     : '${language!"en"}',
@@ -455,8 +456,9 @@ var contextmenu = { 'items': {
                 cssfiles : ['/common/js/jquery/plugins/elrte-1.3/css/elrte-inner.css']
             }
             jQuery('#cmseditor').elrte(opts);
-        }
+        });
     }
+}
 <#-------------------------------------------------------------------------------------callMetaInfo function-->
 function callMetaInfo(contentId) {
         var ctx = {"contentId" : contentId, "webSiteId" : webSiteId};
diff --git a/themes/common-theme/webapp/common/js/util/OfbizUtil.js b/themes/common-theme/webapp/common/js/util/OfbizUtil.js
index cedceb6..3f8ef81 100644
--- a/themes/common-theme/webapp/common/js/util/OfbizUtil.js
+++ b/themes/common-theme/webapp/common/js/util/OfbizUtil.js
@@ -100,17 +100,22 @@ function bindObservers(bind_element) {
         })
     });
     jQuery(bind_element).find(".visual-editor").each(function(){
-        var element = jQuery(this);
-        var toolbar = element.data('toolbar');
-        var language = element.data('language');
-        var opts = {
-            cssClass : 'el-rte',
-            lang     : language,
-            toolbar  : toolbar,
-            doctype  : '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">', //'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">',
-            cssfiles : ['/images/jquery/plugins/elrte-1.3/css/elrte-inner.css']
-        }
-        element.elrte(opts);
+        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 element = jQuery(self);
+            var toolbar = element.data('toolbar');
+            var language = element.data('language');
+            var opts = {
+                cssClass : 'el-rte',
+                lang     : language,
+                toolbar  : toolbar,
+                doctype  : '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">', //'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">',
+                cssfiles : ['/common/js/jquery/plugins/elrte-1.3/css/elrte-inner.css']
+            }
+            element.elrte(opts);
+        });
     });
     jQuery(bind_element).find(".ajaxAutoCompleter").each(function(){
         var element = jQuery(this);
@@ -1438,9 +1443,13 @@ var importLibrary = function() {
         jQuery.when.apply(jQuery,
             jQuery.map(urls, function (url) {
                 if (!importLibraryFiles.has(url)) {
+                    var folder = url.substring(0,url.lastIndexOf("/"))
+                    var parentFolder = folder.substring(0,folder.lastIndexOf("/"))
                     var deferObj = (url.endsWith(".css") ?
                         jQuery.get(url, function (css) {
-                                jQuery("<style>" + css + "</style>").appendTo("head");
+                                // convert any relative path
+                                var updatedCss = css.replace(/\.\.\/(images|css|js)+/g, parentFolder+"/$1");
+                                jQuery("<style>" + updatedCss + "</style>").appendTo("head");
                             }
                         ) :
                         cachedScript(url));
diff --git a/themes/common-theme/widget/Theme.xml b/themes/common-theme/widget/Theme.xml
index 36ae42b..2f5e793 100644
--- a/themes/common-theme/widget/Theme.xml
+++ b/themes/common-theme/widget/Theme.xml
@@ -66,7 +66,6 @@ under the License.
         <property name="VT_HDR_JAVASCRIPT['add']" value="/common/js/jquery/plugins/mask/jquery.mask-1.14.13.min.js"/>
         <property name="VT_HDR_JAVASCRIPT['add']" value="/common/js/jquery/plugins/jeditable/jquery.jeditable-1.7.3.js"/>
         <property name="VT_HDR_JAVASCRIPT['add']" value="/common/js/jquery/plugins/validate/jquery.validate.min.js"/>
-        <property name="VT_HDR_JAVASCRIPT['add']" value="/common/js/jquery/plugins/elrte-1.3/js/elrte.min.js"/>
         <property name="VT_HDR_JAVASCRIPT['add']" value="/common/js/util/OfbizUtil.js"/>
         <property name="VT_HDR_JAVASCRIPT['add']" value="/common/js/util/fieldlookup.js"/>
         <property name="VT_HDR_JAVASCRIPT['add']" value="/common/js/plugins/date/date.format-1.2.3-min.js"/>
@@ -78,7 +77,6 @@ under the License.
         <property name="VT_HDR_JAVASCRIPT['add']" value="/common/js/plugins/date/FromThruDateCheck.js"/>
         <property name="VT_HDR_JAVASCRIPT['add']" value="/common/js/util/application.js"/>
         <!--Css styles: don't load them since they differ depending on theme -->
-        <property name="VT_STYLESHEET['add']" value="/common/js/jquery/plugins/elrte-1.3/css/elrte.min.css"/>
         <property name="VT_STYLESHEET['add']" value="/common/js/jquery/ui/jquery-ui-1.12.1.min.css"/>
         <property name="VT_STYLESHEET['add']" value="/common/js/jquery/plugins/datetimepicker/jquery-ui-timepicker-addon-1.6.3.min.css"/>
     </theme-properties>