define(["jquery","core/log","core/str","core/templates","core/notification"],function(a,b,c,d,e){varf={DOWN:40,ENTER:13,SPACE:32,ESCAPE:27,COMMA:188,UP:38},g=function(b,c){vard=a(document.getElementById(c.selectionId)),e=d.children("[aria-selected=true]").length;for(b%=e;0>b;)b+=e;varf=a(d.children("[aria-selected=true]").get(b)),g=c.selectionId+"-"+b;d.children().attr("data-active-selection",!1).attr("id",""),f.attr("data-active-selection",!0).attr("id",g),d.attr("aria-activedescendant",g)},h=function(b,c,f){varh=[],i=a(document.getElementById(c.selectionId)),j=i.attr("aria-activedescendant"),k=!1;j&&(k=a(document.getElementById(j)).attr("data-value")),f.children("option").each(function(b,c){a(c).prop("selected")&&h.push({label:a(c).html(),value:a(c).attr("value")})});varl=a.extend({items:h},b,c);d.render("core/form_autocomplete_selection",l).done(function(b){i.empty().append(a(b).html()),k!==!1&&i.children("[aria-selected=true]").each(function(b,d){a(d).attr("data-value")===k&&g(b,c)})}).fail(e.exception)},i=function(a){"undefined"!=typeofM.core_formchangechecker&&M.core_formchangechecker.set_form_changed(),a.change()},j=function(b,c,d,e){varf=a(d).attr("data-value");b.multiple&&e.children("option").each(function(b,c){a(c).attr("value")==f&&(a(c).prop("selected",!1),a(c).attr("data-iscustom")&&a(c).remove())}),h(b,c,e),i(e)},k=function(b,c){vard=a(document.getElementById(c.inputId)),e=a(document.getElementById(c.suggestionsId)),f=e.children("[aria-hidden=false]").length;for(b%=f;0>b;)b+=f;varg=a(e.children("[aria-hidden=false]").get(b)),h=a(e.children("[role=option]")).index(g),i=c.suggestionsId+"-"+h;e.children().attr("aria-selected",!1).attr("id",""),g.attr("aria-selected",!0).attr("id",i),d.attr("aria-activedescendant",i);varj=g.offset().top-e.offset().top+e.scrollTop()-e.height()/2;e.animate({scrollTop:j},100)},l=function(b){varc=a(document.getElementById(b.suggestionsId)),d=c.children("[aria-selected=true]"),e=c.children("[aria-hidden=false]").index(d);k(e+1,b)},m=function(b){varc=a(document.getElementById(b.selectionId)),d=c.children("[data-active-selection=true]");if(!d)returnvoidg(0,b);vare=c.children("[aria-selected=true]").index(d);g(e-1,b)},n=function(b){varc=a(document.getElementById(b.selectionId)),d=c.children("[data-active-selection=true]");if(!d)returnvoidg(0,b);vare=c.children("[aria-selected=true]").index(d);g(e+1,b)},o=function(b){varc=a(document.getElementById(b.suggestionsId)),d=c.children("[aria-selected=true]"),e=c.children("[aria-hidden=false]").index(d);k(e-1,b)},p=function(b){varc=a(document.getElementById(b.inputId)),d=a(document.getElementById(b.suggestionsId));c.attr("aria-expanded",!1).attr("aria-activedescendant",b.selectionId),d.hide().attr("aria-hidden",!0)},q=function(b,f,g,h){vari=a(document.getElementById(f.inputId)),j=a(document.getElementById(f.suggestionsId)),l=!1,m=[];h.children("option").each(function(b,c){a(c).prop("selected")!==!0&&(m[m.length]={label:c.innerHTML,value:a(c).attr("value")})});varn=f.caseSensitive?g:g.toLocaleLowerCase(),o=a.extend({options:m},b,f);d.render("core/form_autocomplete_suggestions",o).done(function(d){j.replaceWith(d),j=a(document.getElementById(f.suggestionsId)),j.show().attr("aria-hidden",!1),j.children().each(function(c,d){d=a(d),b.caseSensitive&&d.text().indexOf(n)>-1||!b.caseSensitive&&d.text().toLocaleLowerCase().indexOf(n)>-1?(d.show().attr("aria-hidden",!1),l=!0):d.hide().attr("aria-hidden",!0)}),i.attr("aria-expanded",!0),l?b.tags||k(0,f):c.get_string("nosuggestions","form").done(function(a){j.html(a)})}).fail(e.exception)},r=function(b,c,d){vare=a(document.getElementById(c.inputId)),f=e.val(),g=f.split(","),j=!1;a.each(g,function(c,e){if(e=e.trim(),""!==e&&(b.multiple||d.children("option").prop("selected",!1),d.children("option").each(function(b,c){a(c).attr("value")==e&&(j=!0,a(c).prop("selected",!0))}),!j)){varf=a("<option>");f.append(e),f.attr("value",e),d.append(f),f.prop("selected",!0),f.attr("data-iscustom",!0)}}),h(b,c,d),i(d),e.val(""),p(c)},s=function(b,c,d){vare=a(document.getElementById(c.inputId)),f=a(document.getElementById(c.suggestionsId)),g=f.children("[aria-selected=true]").attr("data-value");b.multiple||d.children("option").prop("selected",!1),d.children("option").each(function(b,c){a(c).attr("value")==g&&a(c).prop("selected",!0)}),h(b,c,d),i(d),e.val(""),p(c)},t=function(b,c,d,f,g){varh=a(b.currentTarget).val();g.transport(c.selector,h,function(b){vare=g.processResults(c.selector,b),h=[];if(f.children("option").each(function(b,c){c=a(c),c.prop("selected")?h.push(String(c.attr("value"))):c.remove()}),!c.multiple&&0===f.children("option").length){vari=a("<option>");f.append(i)}a.each(e,function(b,c){if(-1===h.indexOf(String(c.value))){vard=a("<option>");d.append(c.label),d.attr("value",c.value),f.append(d)}}),q(c,d,"",f)},e.exception)},u=function(b,c,d){vare=a(document.getElementById(c.inputId));if(e.on("keydown",function(g){switch(g.keyCode){casef.DOWN:returnb.showSuggestions?("true"===e.attr("aria-expanded")?l(c):!e.val()&&b.ajax?require([b.ajax],function(a){t(g,b,c,d,a)}):q(b,c,e.val(),d),g.preventDefault(),!1):!0;casef.COMMA:returnb.tags&&r(b,c,d),g.preventDefault(),!1;casef.UP:returno(c),g.preventDefault(),!1;casef.ENTER:varh=a(document.getElementById(c.suggestionsId));return"true"===e.attr("aria-expanded")&&h.children("[aria-selected=true]").length>0?s(b,c,d):b.tags&&r(b,c,d),g.preventDefault(),!1;casef.ESCAPE:return"true"===e.attr("aria-expanded")&&p(c),g.preventDefault(),!1}return!0}),e.on("behat:set-value",function(){varf=a(document.getElementById(c.suggestionsId));"true"===e.attr("aria-expanded")&&f.children("[aria-selected=true]").length>0?s(b,c,d):b.tags&&r(b,c,d)}),e.on("blur",function(){window.setTimeout(function(){varf=a(document.activeElement);f.attr("id")!=e.attr("id")&&(b.tags&&r(b,c,d),p(c))},500)}),b.showSuggestions){varg=a(document.getElementById(c.downArrowId));g.on("click",function(){e.focus(),q(b,c,e.val(),d)})}varh=a(document.getElementById(c.suggestionsId));h.parent().on("click","[role=option]",function(e){varf=a(e.currentTarget).closest("[role=option]"),g=a(document.getElementById(c.suggestionsId)),h=g.children("[aria-hidden=false]").index(f);k(h,c),s(b,c,d)});vari=a(document.getElementById(c.selectionId));i.on("click","[role=listitem]",function(e){varf=a(e.currentTarget);j(b,c,f,d)}),i.on("keydown",function(e){switch(e.keyCode){casef.DOWN:returnn(c),e.preventDefault(),!1;casef.UP:returnm(c),e.preventDefault(),!1;casef.SPACE:casef.ENTER:varg=a(document.getElementById(c.selectionId)).children("[data-active-selection=true]");returng&&(j(b,c,g,d),e.preventDefault()),!1}return!0}),b.showSuggestions&&e.on("input",function(e){varf=a(e.currentTarget).val(),g=a(e.currentTarget).data("last-value");g!==f&&q(b,c,f,d),a(e.currentTarget).data("last-value",f)})};return{enhance:function(f,g,i,j,k,l,m){varn={selector:f,tags:!1,ajax:!1,placeholder:j,caseSensitive:!1,showSuggestions:!0,noSelectionString:m};"undefined"!=typeofg&&(n.tags=g),"undefined"!=typeofi&&(n.ajax=i),"undefined"!=typeofk&&(n.caseSensitive=k),"undefined"!=typeofl&&(n.showSuggestions=l),"undefined"==typeofm&&c.get_string("noselection","form").done(function(a){n.noSelectionString=a}).fail(e.exception);varo=a(f);if(!o)returnb.debug("Selector not found: "+f),!1;o.hide().attr("aria-hidden",!0);varp={selectId:o.attr("id"),inputId:"form_autocomplete_input-"+a.now(),suggestionsId:"form_autocomplete_suggestions-"+a.now(),selectionId:"form_autocomplete_selection-"+a.now(),downArrowId:"form_autocomplete_downarrow-"+a.now()};n.multiple=o.attr("multiple");varq=a("[for="+p.selectId+"]"),r=[];o.children("option").each(function(b,c){r[b]={label:c.innerHTML,value:a(c).attr("value")}});vars=a.extend({},n,p);s.options=r,s.items=[];varv=d.render("core/form_autocomplete_input",s),w=d.render("core/form_autocomplete_suggestions",s),x=d.render("core/form_autocomplete_selection",s);a.when(v,w,x).done(function(b,c,d){o.after(c),o.after(b),o.after(d),q.attr("for",p.inputId),u(n,p,o);vare=a(document.getElementById(p.inputId)),f=a(document.getElementById(p.suggestionsId));f.hide().attr("aria-hidden",!0),n.ajax&&require([n.ajax],function(b){varc=null,d=function(a){t(a,n,p,o,b)},f=function(a){null!==c&&(window.clearTimeout(c),c=null),c=window.setTimeout(d.bind(this,a),300)};e.on("input",f);varg=a(document.getElementById(p.downArrowId));g.on("click",d)}),h(n,p,o)})}}});
!function(a,b){"use strict";"object"==typeofmodule&&module.exports&&"function"==typeofrequire?module.exports=b():"function"==typeofdefine&&"object"==typeofdefine.amd?define(b):a.log=b()}(this,function(){"use strict";functiona(a){returntypeofconsole===h?!1:void0!==console[a]?b(console,a):void0!==console.log?b(console,"log"):g}functionb(a,b){varc=a[b];if("function"==typeofc.bind)returnc.bind(a);try{returnFunction.prototype.bind.call(c,a)}catch(d){returnfunction(){returnFunction.prototype.apply.apply(c,[a,arguments])}}}functionc(a,b,c){returnfunction(){typeofconsole!==h&&(d.call(this,b,c),this[a].apply(this,arguments))}}functiond(a,b){for(varc=0;c<i.length;c++){vard=i[c];this[d]=a>c?g:this.methodFactory(d,a,b)}}functione(b,d,e){returna(b)||c.apply(this,arguments)}functionf(a,b,c){functionf(a){varb=(i[a]||"silent").toUpperCase();try{returnvoid(window.localStorage[l]=b)}catch(c){}try{window.document.cookie=encodeURIComponent(l)+"="+b+";"}catch(c){}}functiong(){vara;try{a=window.localStorage[l]}catch(b){}if(typeofa===h)try{varc=window.document.cookie,d=c.indexOf(encodeURIComponent(l)+"=");d&&(a=/^([^;]+)/.exec(c.slice(d))[1])}catch(b){}returnvoid0===k.levels[a]&&(a=void0),a}varj,k=this,l="loglevel";a&&(l+=":"+a),k.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},k.methodFactory=c||e,k.getLevel=function(){returnj},k.setLevel=function(b,c){if("string"==typeofb&&void0!==k.levels[b.toUpperCase()]&&(b=k.levels[b.toUpperCase()]),!("number"==typeofb&&b>=0&&b<=k.levels.SILENT))throw"log.setLevel() called with invalid level: "+b;returnj=b,c!==!1&&f(b),d.call(k,b,a),typeofconsole===h&&b<k.levels.SILENT?"No console available for logging":void0},k.setDefaultLevel=function(a){g()||k.setLevel(a,!1)},k.enableAll=function(a){k.setLevel(k.levels.TRACE,a)},k.disableAll=function(a){k.setLevel(k.levels.SILENT,a)};varm=g();null==m&&(m=null==b?"WARN":b),k.setLevel(m,!1)}varg=function(){},h="undefined",i=["trace","debug","info","warn","error"],j=newf,k={};j.getLogger=function(a){if("string"!=typeofa||""===a)thrownewTypeError("You must supply a name when creating a logger.");varb=k[a];returnb||(b=k[a]=newf(a,j.getLevel(),j.methodFactory)),b};varl=typeofwindow!==h?window.log:void0;returnj.noConflict=function(){returntypeofwindow!==h&&window.log===j&&(window.log=l),j},j});
!function(a,b){"object"==typeofexports&&exports&&"string"!=typeofexports.nodeName?b(exports):"function"==typeofdefine&&define.amd?define(["exports"],b):(a.Mustache={},b(a.Mustache))}(this,function(a){functionb(a){return"function"==typeofa}functionc(a){returnp(a)?"array":typeofa}functiond(a){returna.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}functione(a,b){returnnull!=a&&"object"==typeofa&&bina}functionf(a,b){returnq.call(a,b)}functiong(a){return!f(r,a)}functionh(a){returnString(a).replace(/[&<>"'`=\/]/g,function(a){returns[a]})}functioni(b,c){functione(){if(r&&!s)for(;q.length;)deleteo[q.pop()];elseq=[];r=!1,s=!1}functionf(a){if("string"==typeofa&&(a=a.split(u,2)),!p(a)||2!==a.length)thrownewError("Invalid tags: "+a);h=newRegExp(d(a[0])+"\\s*"),i=newRegExp("\\s*"+d(a[1])),m=newRegExp("\\s*"+d("}"+a[1]))}if(!b)return[];varh,i,m,n=[],o=[],q=[],r=!1,s=!1;f(c||a.tags);for(vary,z,A,B,C,D,E=newl(b);!E.eos();){if(y=E.pos,A=E.scanUntil(h))for(varF=0,G=A.length;G>F;++F)B=A.charAt(F),g(B)?q.push(o.length):s=!0,o.push(["text",B,y,y+1]),y+=1,"\n"===B&&e();if(!E.scan(h))break;if(r=!0,z=E.scan(x)||"name",E.scan(t),"="===z?(A=E.scanUntil(v),E.scan(v),E.scanUntil(i)):"{"===z?(A=E.scanUntil(m),E.scan(w),E.scanUntil(i),z="&"):A=E.scanUntil(i),!E.scan(i))thrownewError("Unclosed tag at "+E.pos);if(C=[z,A,y,E.pos],o.push(C),"#"===z||"^"===z||"$"===z||"<"===z)n.push(C);elseif("/"===z){if(D=n.pop(),!D)thrownewError('Unopened section "'+A+'" at '+y);if(D[1]!==A)thrownewError('Unclosed section "'+D[1]+'" at '+y)}else"name"===z||"{"===z||"&"===z?s=!0:"="===z&&f(A)}if(D=n.pop())thrownewError('Unclosed section "'+D[1]+'" at '+E.pos);returnk(j(o))}functionj(a){for(varb,c,d=[],e=0,f=a.length;f>e;++e)b=a[e],b&&("text"===b[0]&&c&&"text"===c[0]?(c[1]+=b[1],c[3]=b[3]):(d.push(b),c=b));returnd}functionk(a){for(varb,c,d=[],e=d,f=[],g=0,h=a.length;h>g;++g)switch(b=a[g],b[0]){case"$":case"<":case"#":case"^":e.push(b),f.push(b),e=b[4]=[];break;case"/":c=f.pop(),c[5]=b[2],e=f.length>0?f[f.length-1][4]:d;break;default:e.push(b)}returnd}functionl(a){this.string=a,this.tail=a,this.pos=0}functionm(a,b){this.view=a,this.blocks={},this.cache={".":this.view},this.parent=b}functionn(){this.cache={}}varo=Object.prototype.toString,p=Array.isArray||function(a){return"[object Array]"===o.call(a)},q=RegExp.prototype.test,r=/\S/,s={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="},t=/\s*/,u=/\s+/,v=/\s*=/,w=/\s*\}/,x=/#|\^|\/|>|\{|&|=|!|\$|</;l.prototype.eos=function(){return""===this.tail},l.prototype.scan=function(a){varb=this.tail.match(a);if(!b||0!==b.index)return"";varc=b[0];returnthis.tail=this.tail.substring(c.length),this.pos+=c.length,c},l.prototype.scanUntil=function(a){varb,c=this.tail.search(a);switch(c){case-1:b=this.tail,this.tail="";break;case0:b="";break;default:b=this.tail.substring(0,c),this.tail=this.tail.substring(c)}returnthis.pos+=b.length,b},m.prototype.push=function(a){returnnewm(a,this)},m.prototype.setBlockVar=function(a,b){varc=this.blocks;returnc[a]=b,b},m.prototype.clearBlockVars=function(){this.blocks={}},m.prototype.getBlockVar=function(a){varb,c=this.blocks;returnc.hasOwnProperty(a)?b=c[a]:this.parent&&(b=this.parent.getBlockVar(a)),b},m.prototype.lookup=function(a){varc,d=this.cache;if(d.hasOwnProperty(a))c=d[a];else{for(varf,g,h=this,i=!1;h;){if(a.indexOf(".")>0)for(c=h.view,f=a.split("."),g=0;null!=c&&g<f.length;)g===f.length-1&&(i=e(c,f[g])),c=c[f[g++]];elsec=h.view[a],i=e(h.view,a);if(i)break;h=h.parent}d[a]=c}returnb(c)&&(c=c.call(this.view)),c},n.prototype.clearCache=function(){this.cache={}},n.prototype.parse=function(a,b){varc=this.cache,d=c[a];returnnull==d&&(d=c[a]=i(a,b)),d},n.prototype.render=function(a,b,c){vard=this.parse(a),e=binstanceofm?b:newm(b);returnthis.renderTokens(d,e,c,a)},n.prototype.renderTokens=function(a,b,c,d){for(vare,f,g,h="",i=0,j=a.length;j>i;++i)g=void0,e=a[i],f=e[0],"#"===f?g=this.renderSection(e,b,c,d):"^"===f?g=this.renderInverted(e,b,c,d):">"===f?g=this.renderPartial(e,b,c,d):"<"===f?g=this.renderBlock(e,b,c,d):"$"===f?g=this.renderBlockVariable(e,b,c,d):"&"===f?g=this.unescapedValue(e,b):"name"===f?g=this.escapedValue(e,b):"text"===f&&(g=this.rawValue(e)),void0!==g&&(h+=g);returnh},n.prototype.renderSection=function(a,c,d,e){functionf(a){returng.render(a,c,d)}varg=this,h="",i=c.lookup(a[1]);if(i){if(p(i))for(varj=0,k=i.length;k>j;++j)h+=this.renderTokens(a[4],c.push(i[j]),d,e);elseif("object"==typeofi||"string"==typeofi||"number"==typeofi)h+=this.renderTokens(a[4],c.push(i),d,e);elseif(b(i)){if("string"!=typeofe)thrownewError("Cannot use higher-order sections without the original template");i=i.call(c.view,e.slice(a[3],a[5]),f),null!=i&&(h+=i)}elseh+=this.renderTokens(a[4],c,d,e);returnh}},n.prototype.renderInverted=function(a,b,c,d){vare=b.lookup(a[1]);return!e||p(e)&&0===e.length?this.renderTokens(a[4],b,c,d):void0},n.prototype.renderPartial=function(a,c,d){if(d){vare=b(d)?d(a[1]):d[a[1]];returnnull!=e?this.renderTokens(this.parse(e),c,d,e):void0}},n.prototype.renderBlock=function(a,c,d,e){if(d){varf=b(d)?d(a[1]):d[a[1]];null!=f&&c.clearBlockVars(),this.renderTokens(a[4],c,d,e);varg=this.renderTokens(this.parse(f),c,d,f);returnc.clearBlockVars(),g}},n.prototype.renderBlockVariable=function(a,b,c,d){vare=a[1],f=b.getBlockVar(e);returnf?this.renderTokens(this.parse(f),b,c,f):(b.setBlockVar(e,d.slice(a[3],a[5])),this.renderTokens(a[4],b,c,d))},n.prototype.unescapedValue=function(a,b){varc=b.lookup(a[1]);returnnull!=c?c:void0},n.prototype.escapedValue=function(b,c){vard=c.lookup(b[1]);returnnull!=d?a.escape(d):void0},n.prototype.rawValue=function(a){returna[1]},a.name="mustache.js",a.version="2.2.1",a.tags=["{{","}}"];vary=newn;a.clearCache=function(){returny.clearCache()},a.parse=function(a,b){returny.parse(a,b)},a.render=function(a,b,d){if("string"!=typeofa)thrownewTypeError('Invalid template! Template should be a "string" but "'+c(a)+'" was given as the first argument for mustache#render(template, view, partials)');returny.render(a,b,d)},a.to_html=function(c,d,e,f){varg=a.render(c,d,e);returnb(f)?voidf(g):g},a.escape=h,a.Scanner=l,a.Context=m,a.Writer=n});
define(["core/yui","jquery","core/log"],function(a,b,c){vard={types:{success:"core/notification_success",info:"core/notification_info",warning:"core/notification_warning",error:"core/notification_error"},fieldName:"user-notifications",fetchNotifications:function(){require(["core/ajax"],function(a){varb=a.call([{methodname:"core_fetch_notifications",args:{contextid:d.contextid}}]);b[0].done(d.addNotifications)})},addNotifications:function(a){a||(a=[]),b.each(a,function(a,b){d.renderNotification(b.template,b.variables)})},setupTargetRegion:function(){vara=b("#"+d.fieldName);if(!a.length){varc=b("<span>").attr("id",d.fieldName);returna=b("#region-main"),a.length?a.prepend(c):(a=b('[role="main"]'),a.length?a.prepend(c):(a=b("body"),a.prepend(c)))}},addNotification:function(a){varc=d.types.error;returna=b.extend({closebutton:!0,announce:!0,type:"error"},a),a.template?(c=a.template,deletea.template):a.type&&("undefined"!=typeofd.types[a.type]&&(c=d.types[a.type]),deletea.type),d.renderNotification(c,a)},renderNotification:function(a,e){return"undefined"!=typeofe.message&&e.message?voidrequire(["core/templates"],function(c){c.render(a,e).done(function(a,e){b("#"+d.fieldName).prepend(a),c.runTemplateJS(e)}).fail(d.exception)}):voidc.debug("Notification received without content. Skipping.")},alert:function(b,c,d){a.use("moodle-core-notification-alert",function(){vara=newM.core.alert({title:b,message:c,yesLabel:d});a.show()})},confirm:function(b,c,d,e,f,g){a.use("moodle-core-notification-confirm",function(){vara=newM.core.confirm({title:b,question:c,yesLabel:d,noLabel:e});a.on("complete-yes",function(){f()}),g&&a.on("complete-no",function(){g()}),a.show()})},exception:function(b){b.backtrace&&(b.lineNumber=b.backtrace[0].line,b.fileName=b.backtrace[0].file,b.fileName="..."+b.fileName.substr(b.fileName.length-20),b.stack=b.debuginfo,b.name=b.errorcode),a.use("moodle-core-notification-exception",function(){vara=newM.core.exception(b);a.show()})}};return{init:function(a,b){d.contextid=a,d.setupTargetRegion(),d.addNotifications(b),d.fetchNotifications()},fetchNotifications:d.fetchNotifications,addNotification:d.addNotification,alert:d.alert,confirm:d.confirm,exception:d.exception}});