text: define(["core/mustache","jquery","core/webapi","core/str","core/notification","core/url","core/config","core/localstorage","core/event","core/flex_icon","core/log","core/user_date","core/truncate"],function(a,b,c,d,e,f,g,h,i,j,k,l,m){a.escape=function(a){var b={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};return a=String(a).replace(/[&<>"'\/`=]/g,function(a){return b[a]}),a=a.replace(/&amp;#([0-9]+|x[0-9a-fA-F]+);/g,"&#$1")},String.prototype.startsWith||(String.prototype.startsWith=function(a,b){return b=b||0,this.substr(b,a.length)===a});var n={},o={},p=function(c,f){arguments.length>2&&k.debug("template rendering cannot accept themeName parameter");var h=b.Deferred(),i=[],j=[],n=[],o="",p=[],r=[],s=!0,u=!0,v=function(a){var b="",c=q(a);return c.done(function(a){b=a}).fail(e.exception),""===b&&(n.push(c),s=!1),b},w=function(a,b){if(a.indexOf("{{")===-1||a.indexOf("}}")===-1)return a;if(a.match(/^\{{2,3}\s*([a-zA-Z0-9_\.]+)\s*\}{2,3}$/)){var c=a.replace(/^\{{2,3}\s*([a-zA-Z0-9_\.]+)\s*\}{2,3}$/,"$1");if(this.hasOwnProperty(c))return this[c];if(c.indexOf(".")!==-1){var d=this;if(c.split(".").forEach(function(a){d.hasOwnProperty(a)&&(d=d[a])}),null===d)return"";if("function"!=typeof d||"object"!=typeof d)return d.toString()}}return k.debug("Escaped content contains unexpected mustache processing queues. It will be lost."),""},x=function(a,b){var c=a.split(","),d=function(a,b,c,d){var e="",f=0,g=0;return void 0!==c&&""!==c&&(f=p.length,p.push({key:c,component:d}),e="[[_s"+f+"]]"),g=p.length,p.push({key:a,component:b,param:e}),"[[_s"+g+"]]"},e=function(a){var b=a.shift();return void 0===b&&(b=""),b.trim()},f=function(a){return 0===a.indexOf("{{")&&(a=b("{{#esc}}"+a+"{{/esc}}",this)),a},g=function(a){var b=e(a);return b=f(b)},h=function(a){var b=a[0].trim(),c=a[a.length-1].trim();return 0===b.search("{")||"}"===c.substr(c.length-1)},i=function(a,b,c){var d=c.join(",").trim(),e={};0===d.indexOf("{")&&0!==d.indexOf("{{")?(d=f(d),e=JSON.parse(d)):(e=f(d),0===e.indexOf("{")&&0!==e.indexOf("{{")&&(e=JSON.parse(e)));var g=p.length;return p.push({key:a,component:b,param:e}),"[[_s"+g+"]]"},j=g(c),l=g(c),m="",n="";return j.match(/^[a-zA-Z][a-zA-Z0-9\.:\/_\-]*$/)?(""===l?l="core":(!l.match(/^[a-z]+(_[a-z][a-z0-9_]*)?[a-z0-9]+$/)||l.search("__")>0)&&(k.debug("invalid component:"+l),l="core"),0===c.length?d(j,l):h(c)?(k.debug('Legacy string helper API in use for "'+a+'"'),i(j,l,c)):(m=g(c),n=g(c),m.match(/^[a-zA-Z][a-zA-Z0-9\.:\/_\-]*$/)||(k.debug('Invalid string identifier in "'+a+'"'),m=""),""===n?n="":(!n.match(/^[a-z]+(_[a-z][a-z0-9_]*)?[a-z0-9]+$/)||n.search("__")>0)&&(k.debug("Invalid component:"+n),n=""),d(j,l,m,n))):(k.debug('Invalid string identifier in "'+a+'"'),"")},y=function(a,b){var c=a.split(","),d=function(a,b,c){var d=j.length;return a=f(a),j.push(t(a,b,c)),"<_p"+d+">"},e=function(a){var b=a.shift();return void 0===b&&(b=""),b.trim()},f=function(a){return 0===a.indexOf("{{")&&(a=b("{{#esc}}"+a+"{{/esc}}",this)),a},g=function(a){var b=e(a);return b=f(b)},h=f(c.shift().trim()),i=function(a){if(0===a.length)return!1;var b=a[0].trim(),c=a[a.length-1].trim();return(0===b.search("{")||"}"===c.substr(c.length-1))&&((0!==b.search("{{")||"}}"!==c.substr(c.length-2))&&("{"===b[0]&&"}"===c[c.length-1]))},l=function(a,b){var c=b.join(",").trim(),e="",g="";if(""!==c){c.match(/^\{{2}.*?\}{2}$/)&&(c=f(c));try{c=JSON.parse(c)}catch(h){k.error("Unable to parse customdata for flex icon helper. Not valid JSON."),c={}}"undefined"!=typeof c.alt&&(e=f(c.alt)),c.classes&&(g=f(c.classes))}return d(a,e,g)},m="",n="",o="",q="";if(i(c))return k.debug('Legacy flex icon helper API in use for "'+a+'"'),l(h,c);if(m=g(c),""===m||m.match(/^[a-zA-Z][a-zA-Z0-9\.:\/_\-]*$/)||k.debug('Invalid alt identifier for flex icon "'+m+'", it must be a string identifier.'),n=g(c),""!==n&&(!n.match(/^[a-z]+(_[a-z][a-z0-9_]*)?[a-z0-9]+$/)||n.search("__")>0)&&k.debug('Invalid alt identifier for flex icon "'+n+'", it must be a component identifier.'),""!==m){var r=p.length;p.push({key:m,component:n}),o="[[_s"+r+"]]"}else o="";return q=e(c),d(h,o,q)},z=function(a,b){var c=a.split(","),d=function(a,b,c,d){var e=j.length;return""===b&&(b="core"),a=f(a),j.push(t(b+"|"+a,c,d)),"<_p"+e+">"},e=function(a){var b=a.shift();return void 0===b&&(b=""),b.trim()},f=function(a){return 0===a.indexOf("{{")&&(a=b("{{#esc}}"+a+"{{/esc}}",this)),a},g=function(a,b){var c=e(a);return c=f(c,b)},h=function(a){if(0===a.length)return!1;var b=a[0].trim(),c=a[a.length-1].trim();return(0===b.search("{")||"}"===c.substr(c.length-1))&&(0!==b.search("{{")||c.search("}}")===c.length-1)},i=function(a,b,c){var d,e;try{e=JSON.parse(c)}catch(g){e={alt:c}}for(d in e)e.hasOwnProperty(d)&&(e[d]=f(e[d]));return e},l="",m="",n="",o="",q="",r="",s="",u={};if(l=g(c),m=g(c),!c.length)return d(l,m);if(r=e(c),r.match(/^[a-zA-Z][a-zA-Z0-9\.:\/_\-]*$/)){n=r.trim(),o=e(c),""!==o&&(!o.match(/^[a-z]+(_[a-z][a-z0-9_]*)?[a-z0-9]+$/)||o.search("__")>0)&&k.debug("invalid component:"+o);var v=p.length;p.push({key:n,component:o}),q="[[_s"+v+"]]",s=e(c)}else k.debug('Legacy pix API in use for string:"'+a+'" - Please use the pix icon template or new API'),c.unshift(r),h(c)?(u=i(l,m,c.join(",")),u.hasOwnProperty("alt")&&(q=u.alt),u.hasOwnProperty("classes")&&(s=u.classes)):q=f(c.join(","));return"flexicon"===m?y.apply(this,[l+","+q,b]):d(l,m,q,s)},A=function(a,b){return i.push(b(a,this)),""},B=function(a,b){var c=b(a.trim(),this);return c=c.replace('"','\\"').replace(/([\{\}]{2,3})/g,"{{=<% %>=}}$1<%={{ }}=%>"),'"'+c+'"'},C=function(a,b){var c=/(.*?),(.*)/,d=a.match(c),e=b("{{#esc}}"+d[1].trim()+"{{/esc}}",this),f=b(d[2].trim(),this),g=r.length;return r.push({timestamp:parseInt(e,10),format:f}),"[[_t_"+g+"]]"},D=function(a,b){var c=/(.*?),(.*)/,d=a.match(c),e=parseInt(d[1].trim(),10),f=d[2].trim(),g=b("{{#esc}}"+f+"{{/esc}}",this);return m.truncate(g,{length:e,words:!0,ellipsis:"..."})};f.str=function(){return x},f.pix=function(){return z},f.flex_icon=function(){return y},f.js=function(){return A},f.quote=function(){return B},f.userdate=function(){return C},f.esc=function(){return w},f.shortentext=function(){return D},f.globals={config:g};var E=b.Deferred(),F=function(){b.when.apply(b,n).done(function(){if(s&&!u)E.resolve();else{u=!1,i=[],j=[],n=[],o="",p=[],r=[],s=!0;try{o=a.render(c,f,v),F()}catch(b){h.reject(b)}}})};return F(),E.done(function(){for(var a=0;a<j.length;a++)j[a].done(function(a){return function(b,c){i.push(c),o=o.replace("<_p"+a+">",b)}}(a));b.when.apply(b,j).then(function(){var a=b.Deferred();return i=i.join(";\n"),p.length>0?d.get_strings(p).done(function(b){for(var c,d=0;(o.indexOf("[[_s")!==-1||i.indexOf("[[_s")!==-1)&&d<2;){for(c=0;c<b.length;c++){for(;o.indexOf("[[_s"+c+"]]")!==-1;)o=o.replace("[[_s"+c+"]]",b[c]);for(;i.indexOf("[[_s"+c+"]]")!==-1;)i=i.replace("[[_s"+c+"]]",b[c])}d++}r.length>0&&r.forEach(function(a){return a.format=a.format.replace(/\[\[_s\d+\]\]/,function(a){var c=parseInt(a.match(/\d+/),10);return b[c]}),a}),a.resolve()}):a.resolve(),a}).then(function(){return r.length>0?(k.debug("userdate mustache helper in use - This has a potential XSS security issue"),l.get(r).then(function(a){a.forEach(function(a,b){var c="\\[\\[_t_"+b+"\\]\\]",d=new RegExp(c,"g");o=o.replace(d,a),i=i.replace(d,a)})})):b.Deferred().resolve().promise()}).then(function(){h.resolve(o.trim(),i)},function(a){h.reject(a)})}),h.promise()},q=function(a){var d=b.Deferred(),e=a.split("/"),f=e.shift(),i=e.shift(),j=g.theme+"/"+a;if(j in n)return d.resolve(n[j]),d.promise();var k=h.get("core_template/"+j);if(k)return d.resolve(k),n[j]=k,d.promise();if(j in o)return o[j].promise();o[j]=d;var l=c.call({operationName:"core_template_nosession",variables:{component:f,name:i,theme:g.theme}});return l.then(function(a){var b=a.template;h.set("core_template/"+j,b),n[j]=b,d.resolve(b)})["catch"](function(a){d.reject(a)}),d.promise()},r=function(a){if(void 0!==a&&""!==a.trim()){M.util.js_pending("core-templates-customjs"),a+=";M.util.js_complete('core-templates-customjs');";var b=document.createElement("script");b.text=a,document.head.insertAdjacentElement("beforeend",b)}return M.util.js_pending("core-autoinitialise"),new Promise(function(a,b){require(["core/autoinitialise"],function(c){c.scan().then(function(){M.util.js_complete("core-autoinitialise"),a()})["catch"](b)},b)})},s=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),r(d),i.notifyFilterContentUpdated(g)}},t=function(a,c,d,e){var g={};g.classes=d||"",g=b.extend(g,e),Boolean(c)&&("[object Object]"===c.toString()?g=b.extend(g,c):g.alt=c);var h=b.Deferred();return j.getFlexTemplateData(a).done(function(a){"undefined"==typeof a.data&&(a.data={}),a.data.customdata=g,"undefined"==typeof a.data.customdata.title&&"undefined"!=typeof a.data.customdata.alt&&(a.data.customdata.title=a.data.customdata.alt),w.render(a.template,a.data).done(function(a){h.resolve(a)})}).fail(function(){var b=a.split("|");1===b.length&&b.unshift("core");var c=f.imageUrl(b[1],b[0]),d=[{name:"src",value:c},{name:"alt",value:g.alt},{name:"title",value:g.alt}],e=g.classes;delete g.alt,delete g.classes;for(var i in g)d.push({name:i,value:g[i]});w.render("core/pix_icon",{attributes:d,extraclasses:e}).done(h.resolve)}),h.promise()},u=function(a,c,d){var e=b(a);e.length&&(e.prepend(c),r(d),i.notifyFilterContentUpdated(e))},v=function(a,c,d){var e=b(a);e.length&&(e.append(c),r(d),i.notifyFilterContentUpdated(e))},w={render:function(a,c){arguments.length>2&&k.debug("template rendering cannot accept themeName parameter");var d=b.Deferred(),e=b.extend({},c),f=q(a);return f.done(function(a){var b=p(a,e);b.done(function(a,b){d.resolve(a,b)}).fail(function(a){d.reject(a)})}).fail(function(a){d.reject(a)}),d},runTemplateJS:r,replaceNodeContents:function(a,b,c){return s(a,b,c,!0)},replaceNode:function(a,b,c){return s(a,b,c,!1)},prependNodeContents:function(a,b,c){u(a,b,c)},appendNodeContents:function(a,b,c){v(a,b,c)},renderIcon:t,renderPix:function(a,b,c){return t(b+"|"+a,c)},renderAppend:function(a,b,c){var d,f=document.createRange(),g=this;return new Promise(function(h,i){var j=g.render(a,b);j.done(function(a){f.selectNode(c),d=f.createContextualFragment(a),c.insertBefore(d,null),h()}).fail(function(a){e.exception(a),i()})})},renderAppendByItem:function(a,b,c,d){var f,g=document.createRange(),h=this;return new Promise(function(i,j){var k=h.render(a,b);k.done(function(a){g.selectNode(c),f=g.createContextualFragment(a);for(var b=f.querySelectorAll(d),e=0;e<b.length;e++)c.appendChild(b[e]);i()}).fail(function(a){e.exception(a),j()})})},renderReplace:function(a,b,c){var d=this;return new Promise(function(f,g){var h=d.render(a,b);h.done(function(a){c.innerHTML=a,f()}).fail(function(a){e.exception(a),g()})})}};return w});