MDL-50782 Ajax: No require_login for all ajax webservice calls
[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"],function(a,b,c,d,e,f,g,h){var i={},j=[],k=[],l=1,m="",n=function(b,c){var d,e=b.split(","),g="",h="",j="";e.length>0&&(g=e.shift().trim()),e.length>0&&(h=e.shift().trim()),e.length>0&&(j=e.join(",").trim());var k=f.imageUrl(g,h),l={attributes:[{name:"src",value:k},{name:"alt",value:c(j)},{name:"class",value:"smallicon"}]},n=i[m+"/core/pix_icon"];return d=a.render(n,l,o),d.trim()},o=function(a){var b="";return u(a,!1).done(function(a){b=a}).fail(e.exception),b},p=function(a,b){return k.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=j.length;return j.push({key:d,component:e,param:f}),"{{_s"+g+"}}"},r=function(a,b){m=b,j=[],k=[],a.uniqid=l++,a.str=function(){return q},a.pix=function(){return n},a.js=function(){return p},a.globals={config:g},a.currentTheme=b},s=function(a){var b="";k.length>0&&(b=k.join(";\n"));var c=0;for(c=0;c<a.length;c++)b=b.replace("{{_s"+c+"}}",a[c]);return b},t=function(c,e,f){var g=b.Deferred();m=f;var h=u("core/pix_icon",!0);return h.done(function(){r(e,f);var b="";try{b=a.render(c,e,o)}catch(h){g.reject(h)}j.length>0?d.get_strings(j).done(function(a){var c;for(c=0;c<a.length;c++)b=b.replace("{{_s"+c+"}}",a[c]);g.resolve(b.trim(),s(a))}).fail(function(a){g.reject(a)}):g.resolve(b.trim(),s([]))}).fail(function(a){g.reject(a)}),g.promise()},u=function(a,d){var e=b.Deferred(),f=a.split("/"),g=f.shift(),j=f.shift(),k=m+"/"+a;if(k in i)return e.resolve(i[k]),e.promise();var l=h.get("core_template/"+k);if(l)return e.resolve(l),i[k]=l,e.promise();var n=c.call([{methodname:"core_output_load_template",args:{component:g,template:j,themename:m}}],d);return n[0].done(function(a){h.set("core_template/"+k,a),i[k]=a,e.resolve(a)}).fail(function(a){e.reject(a)}),e.promise()};return{render:function(a,c,d){var e=b.Deferred();"undefined"==typeof d&&(d=g.theme),m=d;var f=u(a,!0);return f.done(function(a){var b=t(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:function(a){var c=b("<script>").attr("type","text/javascript").html(a);b("head").append(c)}}});