From 19421799cbe12cc0fe4e46abb1fc5a3f60a5a9f5 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Tue, 19 Jul 2016 09:37:36 +0100 Subject: [PATCH] Revert "Merge branch 'MDL-54915-30' of git://github.com/andrewnicols/moodle into MOODLE_30_STABLE" This reverts commit 4b6e0cbd572625cd9d3554e7066316949c7a3a14, reversing changes made to 8d6dde0805951b2b1f6d7967799a4f8d300cc249. --- lib/amd/build/templates.min.js | 2 +- lib/amd/src/templates.js | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/amd/build/templates.min.js b/lib/amd/build/templates.min.js index 7c0a30190aa..e46fb78b2ef 100644 --- a/lib/amd/build/templates.min.js +++ b/lib/amd/build/templates.min.js @@ -1 +1 @@ -define(["core/mustache","jquery","core/ajax","core/str","core/notification","core/url","core/config","core/localstorage","core/event"],function(a,b,c,d,e,f,g,h,i){var j={},k=[],l=1,m="",n=function(b,c){var d,e=b.split(","),g="",h="",i="";e.length>0&&(g=e.shift().trim()),e.length>0&&(h=e.shift().trim()),e.length>0&&(i=e.join(",").trim());var k=f.imageUrl(g,h),l={attributes:[{name:"src",value:k},{name:"alt",value:c(i)},{name:"class",value:"smallicon"}]},n=j[m+"/core/pix_icon"];return d=a.render(n,l,o),d.trim()},o=function(a){var b="";return v(a,!1).done(function(a){b=a}).fail(e.exception),b},p=function(a,b){return this.jsBlocks.push(b(a,this)),""},q=function(a,b){var c=a.split(","),d="",e="",f="";c.length>0&&(d=c.shift().trim()),c.length>0&&(e=c.shift().trim()),c.length>0&&(f=c.join(",").trim()),""!==f&&(f=b(f,this)),0===f.indexOf("{")&&0!==f.indexOf("{{")&&(f=JSON.parse(f));var g=k.length;return k.push({key:d,component:e,param:f}),"{{_s"+g+"}}"},r=function(a,b){var c=b(a.trim(),this);return c=c.replace('"','\\"').replace(/([\{\}]{2,3})/g,"{{=<% %>=}}$1<%={{ }}=%>"),'"'+c+'"'},s=function(a,b){m=b,k=[],a.uniqid=l++,a.str=function(){return q},a.pix=function(){return n},a.js=function(){return p},a.jsBlocks=[],a.quote=function(){return r},a.globals={config:g},a.currentTheme=b},t=function(a){var b="";this.jsBlocks.length>0&&(b=this.jsBlocks.join(";\n"));var c=0;for(c=0;c0?d.get_strings(k).done(function(a){var c;for(c=0;c").attr("type","text/javascript").html(a);b("head").append(c)}},x=function(a,c,d,e){var f=b(a);if(f.length){var g=b(c);e?(f.empty(),f.append(g)):f.replaceWith(g),w(d),i.notifyFilterContentUpdated(g)}};return{render:function(a,c,d){var e=b.Deferred();"undefined"==typeof d&&(d=g.theme),m=d;var f=v(a,!0);return f.done(function(a){var b=u(a,c,d);b.done(function(a,b){e.resolve(a,b)}).fail(function(a){e.reject(a)})}).fail(function(a){e.reject(a)}),e.promise()},runTemplateJS:w,replaceNodeContents:function(a,b,c){return x(a,b,c,!0)},replaceNode:function(a,b,c){return x(a,b,c,!1)}}}); \ No newline at end of file +define(["core/mustache","jquery","core/ajax","core/str","core/notification","core/url","core/config","core/localstorage","core/event"],function(a,b,c,d,e,f,g,h,i){var j={},k=[],l=[],m=1,n="",o=function(b,c){var d,e=b.split(","),g="",h="",i="";e.length>0&&(g=e.shift().trim()),e.length>0&&(h=e.shift().trim()),e.length>0&&(i=e.join(",").trim());var k=f.imageUrl(g,h),l={attributes:[{name:"src",value:k},{name:"alt",value:c(i)},{name:"class",value:"smallicon"}]},m=j[n+"/core/pix_icon"];return d=a.render(m,l,p),d.trim()},p=function(a){var b="";return w(a,!1).done(function(a){b=a}).fail(e.exception),b},q=function(a,b){return l.push(b(a,this)),""},r=function(a,b){var c=a.split(","),d="",e="",f="";c.length>0&&(d=c.shift().trim()),c.length>0&&(e=c.shift().trim()),c.length>0&&(f=c.join(",").trim()),""!==f&&(f=b(f,this)),0===f.indexOf("{")&&0!==f.indexOf("{{")&&(f=JSON.parse(f));var g=k.length;return k.push({key:d,component:e,param:f}),"{{_s"+g+"}}"},s=function(a,b){var c=b(a.trim(),this);return c=c.replace('"','\\"').replace(/([\{\}]{2,3})/g,"{{=<% %>=}}$1<%={{ }}=%>"),'"'+c+'"'},t=function(a,b){n=b,k=[],l=[],a.uniqid=m++,a.str=function(){return r},a.pix=function(){return o},a.js=function(){return q},a.quote=function(){return s},a.globals={config:g},a.currentTheme=b},u=function(a){var b="";l.length>0&&(b=l.join(";\n"));var c=0;for(c=0;c0?d.get_strings(k).done(function(a){var c;for(c=0;c").attr("type","text/javascript").html(a);b("head").append(c)}},y=function(a,c,d,e){var f=b(a);if(f.length){var g=b(c);e?(f.empty(),f.append(g)):f.replaceWith(g),x(d),i.notifyFilterContentUpdated(g)}};return{render:function(a,c,d){var e=b.Deferred();"undefined"==typeof d&&(d=g.theme),n=d;var f=w(a,!0);return f.done(function(a){var b=v(a,c,d);b.done(function(a,b){e.resolve(a,b)}).fail(function(a){e.reject(a)})}).fail(function(a){e.reject(a)}),e.promise()},runTemplateJS:x,replaceNodeContents:function(a,b,c){return y(a,b,c,!0)},replaceNode:function(a,b,c){return y(a,b,c,!1)}}}); \ No newline at end of file diff --git a/lib/amd/src/templates.js b/lib/amd/src/templates.js index d4755cf0d6f..2204dc22e92 100644 --- a/lib/amd/src/templates.js +++ b/lib/amd/src/templates.js @@ -43,6 +43,9 @@ 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; @@ -119,7 +122,7 @@ define([ 'core/mustache', * @return {string} */ var jsHelper = function(sectionText, helper) { - this.jsBlocks.push(helper(sectionText, this)); + requiredJS.push(helper(sectionText, this)); return ''; }; @@ -195,11 +198,11 @@ define([ 'core/mustache', var addHelpers = function(context, themeName) { currentThemeName = themeName; requiredStrings = []; + requiredJS = []; context.uniqid = uniqid++; context.str = function() { return stringHelper; }; context.pix = function() { return pixHelper; }; context.js = function() { return jsHelper; }; - context.jsBlocks = []; context.quote = function() { return quoteHelper; }; context.globals = { config : config }; context.currentTheme = themeName; @@ -215,8 +218,8 @@ define([ 'core/mustache', */ var getJS = function(strings) { var js = ''; - if (this.jsBlocks.length > 0) { - js = this.jsBlocks.join(";\n"); + if (requiredJS.length > 0) { + js = requiredJS.join(";\n"); } var i = 0; @@ -270,7 +273,7 @@ define([ 'core/mustache', for (i = 0; i < strings.length; i++) { result = result.replace('{{_s' + i + '}}', strings[i]); } - deferred.resolve(result.trim(), getJS.bind(context)(strings)); + deferred.resolve(result.trim(), getJS(strings)); } ).fail( function(ex) { @@ -278,7 +281,7 @@ define([ 'core/mustache', } ); } else { - deferred.resolve(result.trim(), getJS.bind(context)([])); + deferred.resolve(result.trim(), getJS([])); } } ).fail(