Merge branch 'MDL-54915-master' of git://github.com/andrewnicols/moodle
authorDan Poltawski <dan@moodle.com>
Mon, 18 Jul 2016 08:17:53 +0000 (09:17 +0100)
committerDan Poltawski <dan@moodle.com>
Mon, 18 Jul 2016 08:17:53 +0000 (09:17 +0100)
lib/amd/build/templates.min.js
lib/amd/src/templates.js

index 0ffe642..fd310dd 100644 (file)
Binary files a/lib/amd/build/templates.min.js and b/lib/amd/build/templates.min.js differ
index 503c351..d009703 100644 (file)
@@ -45,9 +45,6 @@ define(['core/mustache',
     /** @var {string[]} requiredStrings - Collection of strings found during the rendering of one template */
     var requiredStrings = [];
 
-    /** @var {string[]} requiredJS - Collection of js blocks found during the rendering of one template */
-    var requiredJS = [];
-
     /** @var {Number} uniqid Incrementing value that is changed for every call to render */
     var uniqid = 1;
 
@@ -182,7 +179,7 @@ define(['core/mustache',
      * @return {string}
      */
     var jsHelper = function(sectionText, helper) {
-        requiredJS.push(helper(sectionText, this));
+        this.jsBlocks.push(helper(sectionText, this));
         return '';
     };
 
@@ -258,7 +255,6 @@ define(['core/mustache',
     var addHelpers = function(context, themeName) {
         currentThemeName = themeName;
         requiredStrings = [];
-        requiredJS = [];
         context.uniqid = uniqid++;
         context.str = function() {
           return stringHelper;
@@ -273,6 +269,7 @@ define(['core/mustache',
           return quoteHelper;
         };
         context.globals = {config: config};
+        context.jsBlocks = [];
         context.currentTheme = themeName;
     };
 
@@ -286,8 +283,8 @@ define(['core/mustache',
      */
     var getJS = function(strings) {
         var js = '';
-        if (requiredJS.length > 0) {
-            js = requiredJS.join(";\n");
+        if (this.jsBlocks.length > 0) {
+            js = this.jsBlocks.join(";\n");
         }
 
         // Re-render to get the final strings.
@@ -403,11 +400,11 @@ define(['core/mustache',
                         // and cause the template to die on the second pass (unbalanced).
 
                         result = treatStringsInContent(result, strings);
-                        deferred.resolve(result, getJS(strings));
+                        deferred.resolve(result, getJS.bind(context)(strings));
                     })
                     .fail(deferred.reject);
                 } else {
-                    deferred.resolve(result.trim(), getJS([]));
+                    deferred.resolve(result.trim(), getJS.bind(context)([]));
                 }
             }
         ).fail(deferred.reject);