瀏覽代碼

Merge pull request #1155 from jloguercio/8233

Fix Load ckeditor js plugin only when user is logged on - Refs #8233
José Loguercio 8 年之前
父節點
當前提交
4f72d84f23
共有 2 個文件被更改,包括 67 次插入64 次删除
  1. 3 1
      main/inc/lib/template.lib.php
  2. 64 63
      main/template/default/layout/header.js.tpl

+ 3 - 1
main/inc/lib/template.lib.php

@@ -713,7 +713,9 @@ class Template
         }
 
         foreach ($bowerJsFiles as $file) {
-            $js_file_to_string .= '<script type="text/javascript" src="'.api_get_path(WEB_PATH).'web/assets/'.$file.'"></script>'."\n";
+            if (!empty($file)) {
+                $js_file_to_string .= '<script type="text/javascript" src="'.api_get_path(WEB_PATH).'web/assets/'.$file.'"></script>'."\n";
+            }
         }
 
         foreach ($js_files as $file) {

+ 64 - 63
main/template/default/layout/header.js.tpl

@@ -1,74 +1,75 @@
 <script>
-// External plugins not part of the default Ckeditor package.
-var plugins = [
-    'asciimath',
-    'asciisvg',
-    'audio',
-    'ckeditor_wiris',
-    'dialogui',
-    'glossary',
-    'leaflet',
-    'mapping',
-    'maximize',
-    'mathjax',
-    'oembed',
-    'toolbar',
-    'toolbarswitch',
-    'video',
-    'wikilink',
-    'wordcount',
-    'youtube'
-];
-
-plugins.forEach(function(plugin) {
-    CKEDITOR.plugins.addExternal(plugin, '{{ _p.web_main ~ 'inc/lib/javascript/ckeditor/plugins/' }}' + plugin + '/');
-});
-
-/**
- * Function use to load templates in a div
- **/
-var showTemplates = function (ckeditorName) {
-    var editorName = 'content';
-    if (ckeditorName && ckeditorName.length > 0) {
-        editorName = ckeditorName;
-    }
-    CKEDITOR.editorConfig(CKEDITOR.config);
-    CKEDITOR.loadTemplates(CKEDITOR.config.templates_files, function (a){
-        var templatesConfig = CKEDITOR.getTemplates("default");
+    {% if _u.logged %}
+        // External plugins not part of the default Ckeditor package.
+        var plugins = [
+            'asciimath',
+            'asciisvg',
+            'audio',
+            'ckeditor_wiris',
+            'dialogui',
+            'glossary',
+            'leaflet',
+            'mapping',
+            'maximize',
+            'mathjax',
+            'oembed',
+            'toolbar',
+            'toolbarswitch',
+            'video',
+            'wikilink',
+            'wordcount',
+            'youtube'
+        ];
+
+        plugins.forEach(function(plugin) {
+            CKEDITOR.plugins.addExternal(plugin, '{{ _p.web_main ~ 'inc/lib/javascript/ckeditor/plugins/' }}' + plugin + '/');
+        });
 
-        var $templatesUL = $("<ul>");
+        /**
+         * Function use to load templates in a div
+         **/
+        var showTemplates = function (ckeditorName) {
+            var editorName = 'content';
+            if (ckeditorName && ckeditorName.length > 0) {
+                editorName = ckeditorName;
+            }
+            CKEDITOR.editorConfig(CKEDITOR.config);
+            CKEDITOR.loadTemplates(CKEDITOR.config.templates_files, function (a){
+                var templatesConfig = CKEDITOR.getTemplates("default");
 
-        $.each(templatesConfig.templates, function () {
-            var template = this;
-            var $templateLi = $("<li>");
+                var $templatesUL = $("<ul>");
 
-            var templateHTML = "<img src=\"" + templatesConfig.imagesPath + template.image + "\" ><div>";
-            templateHTML += "<b>" + template.title + "</b>";
+                $.each(templatesConfig.templates, function () {
+                    var template = this;
+                    var $templateLi = $("<li>");
 
-            if (template.description) {
-                templateHTML += "<div class=description>" + template.description + "</div>";
-            }
+                    var templateHTML = "<img src=\"" + templatesConfig.imagesPath + template.image + "\" ><div>";
+                    templateHTML += "<b>" + template.title + "</b>";
 
-            templateHTML += "</div>";
-
-            $("<a>", {
-                href: "#",
-                html: templateHTML,
-                click: function (e) {
-                    e.preventDefault();
-                    if (CKEDITOR.instances[editorName]) {
-                        CKEDITOR.instances[editorName].setData(template.html, function () {
-                            this.checkDirty();
-                        });
+                    if (template.description) {
+                        templateHTML += "<div class=description>" + template.description + "</div>";
                     }
-                }
-            }).appendTo($templateLi);
-            $templatesUL.append($templateLi);
-        });
-        $templatesUL.appendTo("#frmModel");
-    });
-};
 
+                    templateHTML += "</div>";
+
+                    $("<a>", {
+                        href: "#",
+                        html: templateHTML,
+                        click: function (e) {
+                            e.preventDefault();
+                            if (CKEDITOR.instances[editorName]) {
+                                CKEDITOR.instances[editorName].setData(template.html, function () {
+                                    this.checkDirty();
+                                });
+                            }
+                        }
+                    }).appendTo($templateLi);
+                    $templatesUL.append($templateLi);
+                });
+                $templatesUL.appendTo("#frmModel");
+            });
+        };
+    {% endif %}
 $(document).ready(function(){
     $("#open-view-list").click(function(){
         $("#student-list-work").fadeIn(300);