weekly release 3.2dev
[moodle.git] / lib / amd / build / templates.min.js
1 define(["core/mustache","jquery","core/ajax","core/str","core/notification","core/url","core/config","core/localstorage","core/event","core/yui","core/log"],function(a,b,c,d,e,f,g,h,i,j,k){var l={},m=[],n=[],o=1,p="",q=function(a,d){var e=b.Deferred(),f=a.split("/"),g=f.shift(),i=f.shift(),j=p+"/"+a;if(j in l)return e.resolve(l[j]),e.promise();var k=h.get("core_template/"+j);if(k)return e.resolve(k),l[j]=k,e.promise();var m=c.call([{methodname:"core_output_load_template",args:{component:g,template:i,themename:p}}],d,!1);return m[0].done(function(a){h.set("core_template/"+j,a),l[j]=a,e.resolve(a)}).fail(function(a){e.reject(a)}),e.promise()},r=function(a){var b="";return q(a,!1).done(function(a){b=a}).fail(e.exception),b},s=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 j=f.imageUrl(g,h),k={attributes:[{name:"src",value:j},{name:"alt",value:c(i)},{name:"class",value:"smallicon"}]},m=l[p+"/core/pix_icon"];return d=a.render(m,k,r),d.trim()},t=function(a,b){return n.push(b(a,this)),""},u=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=m.length;return m.push({key:d,component:e,param:f}),"{{_s"+g+"}}"},v=function(a,b){var c=b(a.trim(),this);return c=c.replace('"','\\"').replace(/([\{\}]{2,3})/g,"{{=<% %>=}}$1<%={{ }}=%>"),'"'+c+'"'},w=function(a,b){p=b,m=[],n=[],a.uniqid=o++,a.str=function(){return u},a.pix=function(){return s},a.js=function(){return t},a.quote=function(){return v},a.globals={config:g},a.currentTheme=b},x=function(a){var b="";return n.length>0&&(b=n.join(";\n")),y(b,a)},y=function(a,b){var c,d,e,f,g,h,i=/{{_s\d+}}/;do{for(c="",d=a.search(i);d>-1;){c+=a.substring(0,d),a=a.substr(d),e="",f=4,g=a.substr(f,1);do e+=g,f++,g=a.substr(f,1);while("}"!=g);h=b[parseInt(e,10)],"undefined"==typeof h&&(k.debug("Could not find string for pattern {{_s"+e+"}}."),h=""),c+=h,a=a.substr(6+e.length),d=a.search(i)}a=c+a,d=a.search(i)}while(d>-1);return a},z=function(c,e,f){var g=b.Deferred();p=f;var h=q("core/pix_icon",!0);return h.done(function(){w(e,f);var b="";try{b=a.render(c,e,r)}catch(h){g.reject(h)}m.length>0?d.get_strings(m).then(function(a){b=y(b,a),g.resolve(b,x(a))}).fail(g.reject):g.resolve(b.trim(),x([]))}).fail(g.reject),g.promise()},A=function(a){if(""!==a.trim()){var c=b("<script>").attr("type","text/javascript").html(a);b("head").append(c)}},B=function(a,c,d,e){var f=b(a);if(f.length){var g=b(c),h=null;e?(h=new j.NodeList(f.children().get()),h.destroy(!0),f.empty(),f.append(g)):(h=new j.NodeList(f.get()),h.destroy(!0),f.replaceWith(g)),A(d),i.notifyFilterContentUpdated(g)}};return{render:function(a,c,d){var e=b.Deferred();"undefined"==typeof d&&(d=g.theme),p=d;var f=q(a,!0);return f.done(function(a){var b=z(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:A,replaceNodeContents:function(a,b,c){B(a,b,c,!0)},replaceNode:function(a,b,c){B(a,b,c,!1)}}});