diff --git a/config-dist.php b/config-dist.php index 6196a57..b073e3b 100644 --- a/config-dist.php +++ b/config-dist.php @@ -781,6 +781,18 @@ $CFG->admin = 'admin'; //========================================================================= // 13. SYSTEM PATHS (You need to set following, depending on your system) //========================================================================= +// jQuery configuration for RequireJS +// Moodle uses RequireJS for including external JavaScript modules. While +// Moodle includes jQuery, it is not exposed in the global object as usual. +// All internal JavaScript modules should adhere to using RequireJS, so +// the default should be fine. +// Some installations include JavaScript from a remote CDN that expects +// jQuery configured within the global scope. In order to avoid duplicate +// loading of jQuery and/or if you struggle with race conditions that are +// stating "$ is not a function" comment the following configuration. + +$CFG->jQueryLocalOnly = true; + // Ghostscript path. // On most Linux installs, this can be left as '/usr/bin/gs'. // On Windows it will be something like 'c:\gs\bin\gswin32c.exe' (make sure diff --git a/lib/classes/minify.php b/lib/classes/minify.php index 6ebb067..f3a8582 100644 --- a/lib/classes/minify.php +++ b/lib/classes/minify.php @@ -79,7 +79,18 @@ EOD; $compressed = array(); foreach ($files as $file) { - $content = file_get_contents($file); + // Patch to be able to include minor php fixes (#51153) + // min_get_slash_argument() forbids to have *.php.js files + // so check for PHP indicator into the filename without a dot. + if (preg_match('/php\.js$/', $file)) { + ob_start(); + include($file); + $content = ob_get_contents(); + ob_end_clean(); + } + else { + $content = file_get_contents($file); + } if ($content === false) { $compressed[] = "\n\n// Cannot read JS file ".basename(dirname(dirname($file))).'/'.basename(dirname($file)).'/'.basename($file)."\n\n"; continue; diff --git a/lib/requirejs/jquery-privatephp.js b/lib/requirejs/jquery-privatephp.js new file mode 100644 index 0000000..1bd19e2 --- /dev/null +++ b/lib/requirejs/jquery-privatephp.js @@ -0,0 +1,28 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * This module depends on the real jquery - and returns the non-global version of it. + * + * @module jquery-private + * @package core + * @copyright 2015 Christian Glahn + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +define(['jquery'], function ($) { + // This noConflict call tells JQuery to remove the variable from the global scope - so + // the only remaining instance will be the sandboxed one. + return $jQueryLocalOnly) echo '.noConflict( true )'; ?>; +}); diff --git a/lib/requirejs/moodle-config.js b/lib/requirejs/moodle-config.js index 2c0324d..a34c474 100644 --- a/lib/requirejs/moodle-config.js +++ b/lib/requirejs/moodle-config.js @@ -7,7 +7,7 @@ var require = { paths: { jquery: '[JSURL]lib/jquery/jquery-1.11.2.min[JSEXT]', jqueryui: '[JSURL]lib/jquery/ui-1.11.4/jquery-ui.min[JSEXT]', - jqueryprivate: '[JSURL]lib/requirejs/jquery-private[JSEXT]' + jqueryprivate: '[JSURL]lib/requirejs/jquery-privatephp[JSEXT]' }, // Custom jquery config map.