Current Path : C:/Users/Mahmood/Desktop/moodle/lib/amd/build/ |
Current File : C:/Users/Mahmood/Desktop/moodle/lib/amd/build/templates.min.js |
define ("core/templates",["core/mustache","jquery","core/ajax","core/str","core/notification","core/url","core/config","core/localstorage","core/icon_system","core/event","core/yui","core/log","core/truncate","core/user_date","core/pending"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){var p=0,q={},r={},s={},t={},u=[],v=!1,w=["js"],x=function(a){if(a in r){return r[a]}if(a in q){r[a]=b.Deferred().resolve(q[a]).promise();return r[a]}if(0>=M.cfg.templaterev){return null}var c=h.get("core_template/"+M.cfg.templaterev+":"+a);if(c){q[a]=c;r[a]=b.Deferred().resolve(c).promise();return r[a]}return null},y=function(){if(!u.length){return}if(v){return}v=!0;var a=u.slice(),e=b.Deferred(),f=[],g=a.map(function(a){var c=a.component,i=a.name,j=a.searchKey,k=a.theme,l=a.deferred,m=null,n=x(j);if(n){m=n}else{f.push({methodname:"core_output_load_template_with_dependencies",args:{component:c,template:i,themename:k,lang:b("html").attr("lang").replace(/-/g,"_")}});var o=f.length-1;m=e.promise().then(function(a){g[j]=a[o].then(function(a){var b=null;a.templates.forEach(function(a){var d=[k,a.component,a.name].join("/");q[d]=a.value;if(0<M.cfg.templaterev){h.set("core_template/"+M.cfg.templaterev+":"+d,a.value)}if(a.component==c&&a.name==i){b=a.value}});if(a.strings.length){d.cache_strings(a.strings.map(function(a){return{component:a.component,key:a.name,value:a.value}}))}return b});return g[j]})}return m.then(function(a){return l.resolve(a)}).catch(function(a){l.reject(a);throw a})});if(f.length){e.resolve(c.call(f,!0,!1,!1,0,M.cfg.templaterev))}else{e.resolve()}b.when.apply(null,g).then(function(){u.splice(0,a.length);v=!1;y()}).catch(function(){u.splice(0,a.length);v=!1;y()})},z=function(){this.requiredStrings=[];this.requiredJS=[];this.requiredDates=[];this.currentThemeName=""};z.prototype.requiredStrings=null;z.prototype.requiredDates=[];z.prototype.requiredJS=null;z.prototype.currentThemeName="";z.prototype.getTemplate=function(a){var c=this.currentThemeName,d=c+"/"+a,e=x(d);if(e){return e}var f=u.filter(function(a){return a.searchKey==d});if(f.length){return f[0].deferred.promise()}var g=a.split("/"),h=g.shift(),i=g.join("/"),j=b.Deferred();u.push({component:h,name:i,theme:c,searchKey:d,deferred:j});y();return j.promise()};z.prototype.prefetchTemplates=function(a,c){a.forEach(function(a){var d=c+"/"+a;if(x(d)){return}var e=u.filter(function(a){return a.searchKey==d});if(e.length){return}var f=a.split("/"),g=f.shift(),h=f.join("/");u.push({component:g,name:h,theme:c,searchKey:d,deferred:b.Deferred()})});y()};z.prototype.partialHelper=function(a){var b=this.currentThemeName+"/"+a;if(!(b in q)){e.exception(new Error("Failed to pre-fetch the template: "+a))}return q[b]};z.prototype.renderIcon=function(a,c,d){var f=g.iconsystemmodule,h=b.Deferred();require([f],function(a){var b=new a;if(!(b instanceof i)){h.reject("Invalid icon system specified"+g.iconsystemmodule)}else{t=b;b.init().then(h.resolve).catch(e.exception)}});return h.then(function(a){return this.getTemplate(a.getTemplateName())}.bind(this)).then(function(b){return t.renderIcon(a,c,d,b)})};z.prototype.pixHelper=function(a,b,c){var d=b.split(","),e="",f="",g="";if(0<d.length){e=c(d.shift().trim(),a)}if(0<d.length){f=c(d.shift().trim(),a)}if(0<d.length){g=c(d.join(",").trim(),a)}var h=t.getTemplateName(),i=this.currentThemeName+"/"+h,j=q[i];e=e.replace(///gi,"/");return t.renderIcon(e,f,g,j)};z.prototype.jsHelper=function(a,b,c){this.requiredJS.push(c(b,a));return""};z.prototype.stringHelper=function(a,b,c){var d=b.split(","),e="",f="",g="";if(0<d.length){e=d.shift().trim()}if(0<d.length){f=d.shift().trim()}if(0<d.length){g=d.join(",").trim()}if(!f||"moodle"===f){f="core"}if(""!==g){g=c(g,a)}if(0===g.indexOf("{")&&0!==g.indexOf("{{")){g=JSON.parse(g)}var h=this.requiredStrings.length;this.requiredStrings.push({key:e,component:f,param:g});return"[[_s"+h+"]]"};z.prototype.quoteHelper=function(a,b,c){var d=c(b.trim(),a);d=d.replace(/"/g,"\\\"").replace(/([\{\}]{2,3})/g,"{{=<% %>=}}$1<%={{ }}=%>").replace(/(\r\n|\r|\n)/g,"
");return"\""+d+"\""};z.prototype.shortenTextHelper=function(a,b,c){var d=b.match(/(.*?),(.*)/),e=d[1].trim(),f=d[2].trim(),g=c(f,a);return m.truncate(g,{length:e,words:!0,ellipsis:"..."})};z.prototype.userDateHelper=function(a,b,c){var d=b.match(/(.*?),(.*)/),e=c(d[1].trim(),a),f=c(d[2].trim(),a),g=this.requiredDates.length;this.requiredDates.push({timestamp:e,format:f});return"[[_t_"+g+"]]"};z.prototype.addHelperFunction=function(a,b){return function(){return function(c,d){var e=w.reduce(function(a,c){if(b.hasOwnProperty(c)){a[c]=b[c]}return a},{});w.forEach(function(a){b[a]=function(){return""}});var f=a.apply(this,[b,c,d]);for(var g in e){b[g]=e[g]}return f}.bind(this)}.bind(this)};z.prototype.addHelpers=function(a,b){this.currentThemeName=b;this.requiredStrings=[];this.requiredJS=[];a.uniqid=p++;a.str=this.addHelperFunction(this.stringHelper,a);a.pix=this.addHelperFunction(this.pixHelper,a);a.js=this.addHelperFunction(this.jsHelper,a);a.quote=this.addHelperFunction(this.quoteHelper,a);a.shortentext=this.addHelperFunction(this.shortenTextHelper,a);a.userdate=this.addHelperFunction(this.userDateHelper,a);a.globals={config:g};a.currentTheme=b};z.prototype.getJS=function(){var a="";if(0<this.requiredJS.length){a=this.requiredJS.join(";\n")}return a};z.prototype.treatStringsInContent=function(a,b){var c=/\[\[_s\d+\]\]/,d,e,f,g,h,i;do{d="";e=a.search(c);while(-1<e){d+=a.substring(0,e);a=a.substr(e);f="";g=4;h=a.substr(g,1);do{f+=h;g++;h=a.substr(g,1)}while("]"!=h);i=b[parseInt(f,10)];if("undefined"==typeof i){l.debug("Could not find string for pattern [[_s"+f+"]].");i=""}d+=i;a=a.substr(6+f.length);e=a.search(c)}a=d+a;e=a.search(c)}while(-1<e);return a};z.prototype.treatDatesInContent=function(a,b){b.forEach(function(b,c){var d=new RegExp("\\[\\[_t_"+c+"\\]\\]","g");a=a.replace(d,b)});return a};z.prototype.doRender=function(c,e,f){this.currentThemeName=f;var g=t.getTemplateName(),h=new o("core/templates:doRender");return this.getTemplate(g).then(function(){this.addHelpers(e,f);var d=a.render(c,e,this.partialHelper.bind(this));return b.Deferred().resolve(d.trim(),this.getJS()).promise()}.bind(this)).then(function(a,c){if(0<this.requiredStrings.length){return d.get_strings(this.requiredStrings).then(function(d){this.requiredDates=this.requiredDates.map(function(a){return{timestamp:this.treatStringsInContent(a.timestamp,d),format:this.treatStringsInContent(a.format,d)}}.bind(this));a=this.treatStringsInContent(a,d);c=this.treatStringsInContent(c,d);return b.Deferred().resolve(a,c).promise()}.bind(this))}return b.Deferred().resolve(a,c).promise()}.bind(this)).then(function(a,c){if(0<this.requiredDates.length){return n.get(this.requiredDates).then(function(d){a=this.treatDatesInContent(a,d);c=this.treatDatesInContent(c,d);return b.Deferred().resolve(a,c).promise()}.bind(this))}return b.Deferred().resolve(a,c).promise()}.bind(this)).then(function(a,c){h.resolve();return b.Deferred().resolve(a,c).promise()})};var 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;if(e){h=new k.NodeList(f.children().get());h.destroy(!0);f.empty();f.append(g)}else{h=new k.NodeList(f.get());h.destroy(!0);f.replaceWith(g)}A(d);j.notifyFilterContentUpdated(g);return g.get()}return[]};z.prototype.scanForPartials=function(b){var c=a.parse(b),d=[],e=function(a,b){var c,d;for(c=0;c<a.length;c++){d=a[c];if(">"==d[0]||"<"==d[0]){b.push(d[1])}if(4<d.length){e(d[4],b)}}};e(c,d);return d};z.prototype.cachePartials=function(a,c){var d=this.currentThemeName+"/"+a;if(d in s){return s[d]}c=c||[d];s[d]=b.Deferred();this.getTemplate(a).then(function(e){var f=this.scanForPartials(e),g=f.filter(function(b){if(0<=c.indexOf(this.currentThemeName+"/"+b)){return!1}return b!=a}.bind(this)),h=g.map(function(a){c.push(this.currentThemeName+"/"+a);return this.cachePartials(a,c)}.bind(this));return b.when.apply(b,h).then(function(){return s[d].resolve(e)})}.bind(this)).catch(s[d].reject);return s[d]};z.prototype.render=function(a,c,d){if("undefined"==typeof d){d=g.theme}this.currentThemeName=d;var f=g.iconsystemmodule,h=b.Deferred();require([f],function(a){var b=new a;if(!(b instanceof i)){h.reject("Invalid icon system specified"+g.iconsystem)}else{t=b;b.init().then(h.resolve).catch(e.exception)}});return h.then(function(){return this.cachePartials(a)}.bind(this)).then(function(a){return this.doRender(a,c,d)}.bind(this))};var C=function(a,c,d){var e=b(a);if(e.length){var f=b(c);e.prepend(f);A(d);j.notifyFilterContentUpdated(e);return f.get()}return[]},D=function(a,c,d){var e=b(a);if(e.length){var f=b(c);e.append(f);A(d);j.notifyFilterContentUpdated(e);return f.get()}return[]};return{render:function render(a,b,c){var d=new z;return d.render(a,b,c)},prefetchTemplates:function prefetchTemplates(a,b){var c=new z;if("undefined"==typeof b){b=g.theme}return c.prefetchTemplates(a,b)},renderForPromise:function renderForPromise(a,b,c){var d=new z;return d.render(a,b,c).then(function(a,b){return{html:a,js:b}})},renderPix:function renderPix(a,b,c){var d=new z;return d.renderIcon(a,b,c)},runTemplateJS:A,replaceNodeContents:function replaceNodeContents(a,b,c){return B(a,b,c,!0)},replaceNode:function replaceNode(a,b,c){return B(a,b,c,!1)},prependNodeContents:function prependNodeContents(a,b,c){return C(a,b,c)},appendNodeContents:function appendNodeContents(a,b,c){return D(a,b,c)}}}); //# sourceMappingURL=templates.min.js.map