Parcourir la source

Move js code into a file web/build/main.js #2584

Julio Montoya il y a 6 ans
Parent
commit
0af3ddabe6

+ 5 - 0
main/admin/archive_cleanup.php

@@ -36,6 +36,11 @@ if ($form->validate()) {
         opcache_reset();
     }
 
+    $file = api_get_path(SYS_PUBLIC_PATH).'build/main.js';
+    if (file_exists($file)) {
+        rmdirr($file);
+    }
+
     $archive_path = api_get_path(SYS_ARCHIVE_PATH);
     $htaccess = @file_get_contents($archive_path.'.htaccess');
     $result = rmdirr($archive_path, true, true);

+ 17 - 0
main/inc/global.inc.php

@@ -632,6 +632,23 @@ $default_quota = api_get_setting('default_document_quotum');
 if (empty($default_quota)) {
     $default_quota = 100000000;
 }
+
 define('DEFAULT_DOCUMENT_QUOTA', $default_quota);
 // Forcing PclZip library to use a custom temporary folder.
 define('PCLZIP_TEMPORARY_DIR', api_get_path(SYS_ARCHIVE_PATH));
+
+// Create web/build/main.js
+if (!is_dir(api_get_path(SYS_PUBLIC_PATH).'build')) {
+    mkdir(api_get_path(SYS_PUBLIC_PATH).'build');
+}
+
+// Load template layout/header.js.tpl and save it into web/build/main.js
+$file = api_get_path(SYS_PUBLIC_PATH).'build/main.js';
+// if portal is in test mode always generate the file
+if (!file_exists($file) || api_get_setting('server_type') === 'test') {
+    $template = new Template();
+    // Force use of default to avoid problems
+    $tpl = 'default/layout/header.js.tpl';
+    $contents = $template->fetch($tpl);
+    file_put_contents($file, $contents);
+}

+ 0 - 1
main/inc/lib/display.lib.php

@@ -160,7 +160,6 @@ class Display
      */
     public static function display_reduced_footer()
     {
-        echo self::$global_template->show_footer_js_template();
         echo '</body></html>';
     }
 

+ 2 - 19
main/inc/lib/template.lib.php

@@ -770,7 +770,7 @@ class Template
             }
         }
 
-        if (CHAMILO_LOAD_WYSIWYG == true) {
+        if (CHAMILO_LOAD_WYSIWYG === true) {
             $bowerJsFiles[] = 'ckeditor/ckeditor.js';
         }
 
@@ -859,15 +859,6 @@ class Template
         $this->display($tpl);
     }
 
-    /**
-     * Show footer js template.
-     */
-    public function show_footer_js_template()
-    {
-        $tpl = $this->get_template('layout/footer.js.tpl');
-        $this->display($tpl);
-    }
-
     /**
      * Sets the plugin content in a template variable.
      *
@@ -1377,6 +1368,7 @@ class Template
             'web_query_vars' => api_htmlentities($_SERVER['QUERY_STRING']),
             'web_self_query_vars' => api_htmlentities($_SERVER['REQUEST_URI']),
             'web_cid_query' => api_get_cidreq(),
+            'web_rel_code' => api_get_path(REL_CODE_PATH),
         ];
     }
 
@@ -1401,15 +1393,6 @@ class Template
             }
         }
 
-        $this->assign(
-            'online_button',
-            Display::return_icon('statusonline.png', null, [], ICON_SIZE_ATOM)
-        );
-        $this->assign(
-            'offline_button',
-            Display::return_icon('statusoffline.png', null, [], ICON_SIZE_ATOM)
-        );
-
         // Get language iso-code for this page - ignore errors
         $this->assign('document_language', api_get_language_isocode());
 

+ 0 - 134
main/template/default/layout/footer.js.tpl

@@ -1,134 +0,0 @@
-<script>
-    /* Makes row highlighting possible */
-    $(document).ready( function() {
-        $("[data-toggle=popover]").each(function(i, obj) {
-            $(this).popover({
-                html: true,
-                content: function() {
-                    var id = $(this).attr('id')
-                    return $('#popover-content-' + id).html();
-                }
-            });
-        });
-
-        $('.scrollbar-inner').scrollbar();
-
-        // Date time settings.
-        moment.locale('{{ locale }}');
-        $.datepicker.setDefaults($.datepicker.regional["{{ locale }}"]);
-        $.datepicker.regional["local"] = $.datepicker.regional["{{ locale }}"];
-
-        // Fix old calls of "inc/lib/mediaplayer/player.swf" and convert to <audio> tag, then rendered by media element js
-        // see BT#13405
-        $('embed').each( function () {
-            var flashVars = $(this).attr('flashvars');
-            if (flashVars && flashVars.indexOf("file") == -1) {
-                var audioId = Math.floor( Math.random()*99999 );
-                flashVars = flashVars.replace('&autostart=false', '');
-                flashVars = flashVars.replace('&autostart=true', '');
-                var audioDiv = '<audio id="'+audioId+'" controls="controls" style="width:400px;" width:"400px;" src="'+flashVars+'" ><source src="'+flashVars+'" type="audio/mp3"  ></source></audio>';
-                $(this).hide();
-                $(this).after(audioDiv);
-            }
-        });
-
-        // Chosen select
-        $(".chzn-select").chosen({
-            disable_search_threshold: 10,
-            no_results_text: '{{ 'SearchNoResultsFound' | get_lang | escape('js') }}',
-            placeholder_text_multiple: '{{ 'SelectSomeOptions' | get_lang | escape('js') }}',
-            placeholder_text_single: '{{ 'SelectAnOption' | get_lang | escape('js') }}',
-            width: "100%"
-        });
-
-        // Bootstrap tabs.
-        $('.tab-wrapper a').click(function (e) {
-            e.preventDefault();
-            $(this).tab('show');
-
-            //$('#tabs a:first').tab('show') // Select first tab
-        });
-
-        // Fixes bug when loading links inside a tab.
-        $('.tab-wrapper .tab-pane a').unbind();
-
-        /**
-         * Advanced options
-         * Usage
-         * <a id="link" href="url">Advanced</a>
-         * <div id="link_options">
-         *     hidden content :)
-         * </div>
-         * */
-        $(".advanced_options").on("click", function (event) {
-            event.preventDefault();
-            var id = $(this).attr('id') + '_options';
-            var button = $(this);
-            $("#" + id).toggle();
-        });
-
-        /**
-         * <a class="advanced_options_open" href="http://" rel="div_id">Open</a>
-         * <a class="advanced_options_close" href="http://" rel="div_id">Close</a>
-         * <div id="div_id">Div content</div>
-         * */
-        $(".advanced_options_open").on("click", function (event) {
-            event.preventDefault();
-            var id = $(this).attr('rel');
-            $("#" + id).show();
-        });
-
-        $(".advanced_options_close").on("click", function (event) {
-            event.preventDefault();
-            var id = $(this).attr('rel');
-            $("#" + id).hide();
-        });
-
-        // Adv multi-select search input.
-        $('.select_class_filter').each( function () {
-            var inputId = $(this).attr('id');
-            inputId = inputId.replace('-filter', '');
-            $("#" + inputId).filterByText($("#" + inputId + "-filter"));
-        });
-
-        // Mediaelement
-        if ( {{ show_media_element }} == 1) {
-            $('video:not(.skip), audio:not(.skip)').mediaelementplayer({
-                pluginPath: '{{ _p.web }}web/assets/mediaelement/build/',
-                renderers: ['html5', 'flash_video', 'native_flv'],
-                features: ['{{ video_features }}'],
-                success: function(mediaElement, originalNode, instance) {
-                }
-            });
-        }
-
-        // Table highlight.
-        $("form .data_table input:checkbox").click(function () {
-            if ($(this).is(":checked")) {
-                $(this).parentsUntil("tr").parent().addClass("row_selected");
-            } else {
-                $(this).parentsUntil("tr").parent().removeClass("row_selected");
-            }
-        });
-
-        /* For non HTML5 browsers */
-        if ($("#formLogin".length > 1)) {
-            $("input[name=login]").focus();
-        }
-
-        // Tool tip (in exercises)
-        var tip_options = {
-            placement: 'right'
-        };
-        $('.boot-tooltip').tooltip(tip_options);
-        var more = '{{ 'SeeMore' | get_lang | escape('js') }}';
-        var close = '{{ 'Close' | get_lang | escape('js') }}';
-        $('.list-teachers').readmore({
-            speed: 75,
-            moreLink: '<a href="#">' + more + '</a>',
-            lessLink: '<a href="#">' + close + '</a>',
-            collapsedHeight: 35,
-            blockCSS: 'display: block; width: 100%;'
-        });
-    });
-</script>

+ 1 - 35
main/template/default/layout/head.tpl

@@ -19,42 +19,8 @@
 {{ css_static_file_to_string }}
 {{ js_file_to_string }}
 {{ extra_headers }}
-<script>
-/* Global chat variables */
-var ajax_url = '{{ _p.web_ajax }}chat.ajax.php';
-var online_button = '{{ online_button }}';
-var offline_button = '{{ offline_button }}';
-var connect_lang = '{{ "ChatConnected"|get_lang }}';
-var disconnect_lang = '{{ "ChatDisconnected"|get_lang }}';
-var logOutUrl = '{{ _p.web_ajax }}course.ajax.php?a=course_logout&{{ _p.web_cid_query }}';
 
-function addMainEvent(elm, evType, fn, useCapture) {
-    if (elm.addEventListener) {
-        elm.addEventListener(evType, fn, useCapture);
-        return true;
-    } else if (elm.attachEvent) {
-        elm.attachEvent('on' + evType, fn);
-    } else{
-        elm['on'+evType] = fn;
-    }
-}
-
-function courseLogout() {
-    $.ajax({
-        url: logOutUrl,
-        success: function (data) {
-            return 1;
-        }
-    });
-}
-
-$(function() {
-    addMainEvent(window, 'unload', courseLogout ,false);
-});
-
-</script>
-
-{% include 'layout/header.js.tpl'|get_template %}
+<script type="text/javascript" src="{{ _p.web }}web/build/main.js"></script>
 
 {{ css_custom_file_to_string }}
 {{ css_style_print }}

+ 170 - 6
main/template/default/layout/header.js.tpl

@@ -1,5 +1,37 @@
-<script>
-{% if constant('CHAMILO_LOAD_WYSIWYG') %}
+/* Global chat variables */
+
+var ajax_url = '{{ _p.web_rel_code }}inc/ajax/chat.ajax.php';
+var online_button = '{{ 'statusonline.png' |icon(8) }}';
+var offline_button = '{{ 'statusoffline.png' |icon(8) }}';
+var connect_lang = '{{ "ChatConnected"|get_lang }}';
+var disconnect_lang = '{{ "ChatDisconnected"|get_lang }}';
+var logOutUrl = '{{ _p.web_rel_code }}inc/ajax/course.ajax.php?a=course_logout&{{ _p.web_cid_query }}';
+
+function addMainEvent(elm, evType, fn, useCapture) {
+    if (elm.addEventListener) {
+        elm.addEventListener(evType, fn, useCapture);
+        return true;
+    } else if (elm.attachEvent) {
+        elm.attachEvent('on' + evType, fn);
+    } else {
+        elm['on'+evType] = fn;
+    }
+}
+
+function courseLogout() {
+    $.ajax({
+        url: logOutUrl,
+        success: function (data) {
+            return 1;
+        }
+    });
+}
+
+$(function() {
+    addMainEvent(window, 'unload', courseLogout ,false);
+});
+
+if (typeof CKEDITOR !== 'undefined') {
     // External plugins not part of the default Ckeditor package.
     var plugins = [
         'asciimath',
@@ -24,8 +56,11 @@
         'image2_chamilo'
     ];
 
-    plugins.forEach(function(plugin) {
-        CKEDITOR.plugins.addExternal(plugin, '{{ _p.web_main ~ 'inc/lib/javascript/ckeditor/plugins/' }}' + plugin + '/');
+    plugins.forEach(function (plugin) {
+        CKEDITOR.plugins.addExternal(
+            plugin,
+            '{{ _p.web_rel_code ~ 'inc/lib/javascript/ckeditor/plugins/' }}' + plugin + '/'
+        );
     });
 
     /**
@@ -70,7 +105,7 @@
             $templatesUL.appendTo("#frmModel");
         });
     };
-{% endif %}
+}
 
 function doneResizing() {
     var widthWindow = $(window).width();
@@ -233,6 +268,136 @@ $(document).ready(function() {
     }).mouseleave(function() {
          $(this).removeClass('hovered-course');
     });
+
+    $("[data-toggle=popover]").each(function(i, obj) {
+        $(this).popover({
+            html: true,
+            content: function() {
+                var id = $(this).attr('id')
+                return $('#popover-content-' + id).html();
+            }
+        });
+    });
+
+    $('.scrollbar-inner').scrollbar();
+
+    // Date time settings.
+    moment.locale('{{ locale }}');
+    $.datepicker.setDefaults($.datepicker.regional["{{ locale }}"]);
+    $.datepicker.regional["local"] = $.datepicker.regional["{{ locale }}"];
+
+    // Fix old calls of "inc/lib/mediaplayer/player.swf" and convert to <audio> tag, then rendered by media element js
+    // see BT#13405
+    $('embed').each( function () {
+        var flashVars = $(this).attr('flashvars');
+        if (flashVars && flashVars.indexOf("file") == -1) {
+            var audioId = Math.floor( Math.random()*99999 );
+            flashVars = flashVars.replace('&autostart=false', '');
+            flashVars = flashVars.replace('&autostart=true', '');
+            var audioDiv = '<audio id="'+audioId+'" controls="controls" style="width:400px;" width:"400px;" src="'+flashVars+'" ><source src="'+flashVars+'" type="audio/mp3"  ></source></audio>';
+            $(this).hide();
+            $(this).after(audioDiv);
+        }
+    });
+
+    // Chosen select
+    $(".chzn-select").chosen({
+        disable_search_threshold: 10,
+        no_results_text: '{{ 'SearchNoResultsFound' | get_lang | escape('js') }}',
+        placeholder_text_multiple: '{{ 'SelectSomeOptions' | get_lang | escape('js') }}',
+        placeholder_text_single: '{{ 'SelectAnOption' | get_lang | escape('js') }}',
+        width: "100%"
+    });
+
+    // Bootstrap tabs.
+    $('.tab-wrapper a').click(function (e) {
+        e.preventDefault();
+        $(this).tab('show');
+
+        //$('#tabs a:first').tab('show') // Select first tab
+    });
+
+    // Fixes bug when loading links inside a tab.
+    $('.tab-wrapper .tab-pane a').unbind();
+
+    /**
+     * Advanced options
+     * Usage
+     * <a id="link" href="url">Advanced</a>
+     * <div id="link_options">
+     *     hidden content :)
+     * </div>
+     * */
+    $(".advanced_options").on("click", function (event) {
+        event.preventDefault();
+        var id = $(this).attr('id') + '_options';
+        var button = $(this);
+        $("#" + id).toggle();
+    });
+
+    /**
+     * <a class="advanced_options_open" href="http://" rel="div_id">Open</a>
+     * <a class="advanced_options_close" href="http://" rel="div_id">Close</a>
+     * <div id="div_id">Div content</div>
+     * */
+    $(".advanced_options_open").on("click", function (event) {
+        event.preventDefault();
+        var id = $(this).attr('rel');
+        $("#" + id).show();
+    });
+
+    $(".advanced_options_close").on("click", function (event) {
+        event.preventDefault();
+        var id = $(this).attr('rel');
+        $("#" + id).hide();
+    });
+
+    // Adv multi-select search input.
+    $('.select_class_filter').each( function () {
+        var inputId = $(this).attr('id');
+        inputId = inputId.replace('-filter', '');
+        $("#" + inputId).filterByText($("#" + inputId + "-filter"));
+    });
+
+    // Mediaelement
+    if ( {{ show_media_element }} == 1) {
+        $('video:not(.skip), audio:not(.skip)').mediaelementplayer({
+            pluginPath: '{{ _p.web }}web/assets/mediaelement/build/',
+            renderers: ['html5', 'flash_video', 'native_flv'],
+            features: ['{{ video_features }}'],
+            success: function(mediaElement, originalNode, instance) {
+            }
+        });
+    }
+
+    // Table highlight.
+    $("form .data_table input:checkbox").click(function () {
+        if ($(this).is(":checked")) {
+            $(this).parentsUntil("tr").parent().addClass("row_selected");
+        } else {
+            $(this).parentsUntil("tr").parent().removeClass("row_selected");
+        }
+    });
+
+    /* For non HTML5 browsers */
+    if ($("#formLogin".length > 1)) {
+        $("input[name=login]").focus();
+    }
+
+    // Tool tip (in exercises)
+    var tip_options = {
+        placement: 'right'
+    };
+    $('.boot-tooltip').tooltip(tip_options);
+    var more = '{{ 'SeeMore' | get_lang | escape('js') }}';
+    var close = '{{ 'Close' | get_lang | escape('js') }}';
+    $('.list-teachers').readmore({
+        speed: 75,
+        moreLink: '<a href="#">' + more + '</a>',
+        lessLink: '<a href="#">' + close + '</a>',
+        collapsedHeight: 35,
+        blockCSS: 'display: block; width: 100%;'
+    });
 });
 
 $(window).resize(function() {
@@ -464,4 +629,3 @@ function expandColumnToogle(buttonSelector, col1Info, col2Info)
         col1.removeClass('hide').addClass('col-md-' + col1Info.width);
     });
 }
-</script>

+ 0 - 2
main/template/default/layout/page.tpl

@@ -58,8 +58,6 @@
     {% if show_footer == true %}
 	    {% include 'layout/page_footer.tpl'|get_template %}
     {% endif %}
-
-    {% include 'layout/footer.js.tpl'|get_template %}
     </div>
   </body>
 </html>

+ 0 - 1
main/template/default/layout/show_footer.tpl

@@ -4,6 +4,5 @@
         {% include 'layout/page_footer.tpl'|get_template %}
     {% endif %}
     </div>
-    {% include 'layout/footer.js.tpl'|get_template %}
 </body>
 </html>