Your IP : 192.168.165.1


Current Path : C:/Users/Mahmood/Desktop/moodle/lib/amd/build/
Upload File :
Current File : C:/Users/Mahmood/Desktop/moodle/lib/amd/build/form-autocomplete.min.js

define ("core/form-autocomplete",["jquery","core/log","core/str","core/templates","core/notification","core/loadingicon"],function(a,b,c,d,f,g){var h={DOWN:40,ENTER:13,SPACE:32,ESCAPE:27,COMMA:44,UP:38},i=Date.now(),j=function(b,c){var d=a(document.getElementById(c.selectionId)),e=d.children("[aria-selected=true]").length;b=b%e;while(0>b){b+=e}var f=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);return a.Deferred().resolve()},k=function(b,c,e){var g="form-autocomplete-updateSelectionList-"+c.inputId;M.util.js_pending(g);var h=[],i=a(document.getElementById(c.selectionId)),k=i.attr("aria-activedescendant"),l=!1;if(k){l=a(document.getElementById(k)).attr("data-value")}e.children("option").each(function(b,c){if(a(c).prop("selected")){var d;if(a(c).data("html")){d=a(c).data("html")}else{d=a(c).html()}if(""!==d){h.push({label:d,value:a(c).attr("value")})}}});var m=a.extend({items:h},b,c);return d.render(b.templates.items,m).then(function(b,e){d.replaceNodeContents(i,b,e);if(!1!==l){i.children("[aria-selected=true]").each(function(b,d){if(a(d).attr("data-value")===l){j(b,c)}})}return l}).then(function(){return M.util.js_complete(g)}).catch(f.exception)},l=function(a){if("undefined"!=typeof M.core_formchangechecker){M.core_formchangechecker.set_form_changed()}a[0].dispatchEvent(new Event("change"))},m=function(b,c,d,e){var f=a(d).attr("data-value");e.children("option").each(function(b,c){if(a(c).attr("value")==f){a(c).prop("selected",!1);if(a(c).attr("data-iscustom")){a(c).remove()}}});return k(b,c,e).then(function(){l(e)})},n=function(b,c){var d=a(document.getElementById(c.inputId)),e=a(document.getElementById(c.suggestionsId)),f=e.children("[aria-hidden=false]").length;b=b%f;while(0>b){b+=f}var g=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);var j=g.offset().top-e.offset().top+e.scrollTop()-e.height()/2;return e.animate({scrollTop:j},100).promise()},o=function(b){var c=a(document.getElementById(b.suggestionsId)),d=c.children("[aria-selected=true]"),e=c.children("[aria-hidden=false]").index(d);return n(e+1,b)},p=function(b){var c=a(document.getElementById(b.selectionId)),d=c.children("[data-active-selection=true]");if(!d){return j(0,b)}var e=c.children("[aria-selected=true]").index(d);return j(e-1,b)},q=function(b){var c=a(document.getElementById(b.selectionId)),d=c.children("[data-active-selection=true]"),e=0;if(d){e=c.children("[aria-selected=true]").index(d);e=e+1}else{e=0}return j(e,b)},r=function(b){var c=a(document.getElementById(b.suggestionsId)),d=c.children("[aria-selected=true]"),e=c.children("[aria-hidden=false]").index(d);return n(e-1,b)},s=function(b){var c=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);return a.Deferred().resolve()},t=function(b,e,g,h){var i="form-autocomplete-updateSuggestions-"+e.inputId;M.util.js_pending(i);var j=a(document.getElementById(e.inputId)),k=a(document.getElementById(e.suggestionsId)),l=!1,m=[];h.children("option").each(function(b,c){if(!0!==a(c).prop("selected")){m[m.length]={label:c.innerHTML,value:a(c).attr("value")}}});var o=e.caseSensitive?g:g.toLocaleLowerCase(),p=a.extend({options:m},b,e),q=d.render("core/form_autocomplete_suggestions",p).then(function(f,g){d.replaceNode(k,f,g);k=a(document.getElementById(e.suggestionsId));k.show().attr("aria-hidden",!1);k.children().each(function(c,d){d=a(d);if(b.caseSensitive&&-1<d.text().indexOf(o)||!b.caseSensitive&&-1<d.text().toLocaleLowerCase().indexOf(o)){d.show().attr("aria-hidden",!1);l=!0}else{d.hide().attr("aria-hidden",!0)}});j.attr("aria-expanded",!0);if(h.attr("data-notice")){k.html(h.attr("data-notice"))}else if(l){if(!b.tags){n(0,e)}}else{c.get_string("nosuggestions","form").done(function(a){k.html(a)})}return k}).then(function(){return M.util.js_complete(i)}).catch(f.exception);return q},u=function(b,c,d){var e=a(document.getElementById(c.inputId)),f=e.val(),g=f.split(","),h=!1;a.each(g,function(c,e){e=e.trim();if(""!==e){if(!b.multiple){d.children("option").prop("selected",!1)}d.children("option").each(function(b,c){if(a(c).attr("value")==e){h=!0;a(c).prop("selected",!0)}});if(!h){var f=a("<option>");f.append(document.createTextNode(e));f.attr("value",e);d.append(f);f.prop("selected",!0);f.attr("data-iscustom",!0)}}});return k(b,c,d).then(function(){l(d)}).then(function(){e.val("")}).then(function(){return s(c)})},v=function(b,c,d){var e=a(document.getElementById(c.inputId)),f=a(document.getElementById(c.suggestionsId)),g=f.children("[aria-selected=true]").attr("data-value");if(!b.multiple){d.children("option").prop("selected",!1)}d.children("option").each(function(b,c){if(a(c).attr("value")==g){a(c).prop("selected",!0)}});return k(b,c,d).then(function(){l(d)}).then(function(){if(b.closeSuggestionsOnSelect){e.val("");return s(c)}else{e.focus();return t(b,c,e.val(),d)}})},w=function(b,c,d,e,f){var h=y("updateAjax"),i=a(document.getElementById(d.selectId)).parent();g.addIconToContainerRemoveOnCompletion(i,h);var j=a(b.currentTarget).val();f.transport(c.selector,j,function(b){var g=f.processResults(c.selector,b),i=[];if(!c.multiple){e.children("option").remove()}e.children("option").each(function(b,c){c=a(c);if(!c.prop("selected")){c.remove()}else{i.push(c.attr("value")+"")}});if(!c.multiple&&0===e.children("option").length){var j=a("<option>");e.append(j)}if(a.isArray(g)){a.each(g,function(b,c){if(-1===i.indexOf(c.value+"")){var d=a("<option>");d.append(c.label);d.attr("value",c.value);e.append(d)}});e.attr("data-notice","")}else{e.attr("data-notice",g)}h.resolve(t(c,d,"",e))},function(a){h.reject(a)});return h},x=function(b,c,d){var g=a(document.getElementById(c.inputId));g.on("keydown",function(f){var e=y("addNavigation-"+c.inputId+"-"+f.keyCode);switch(f.keyCode){case h.DOWN:if(!b.showSuggestions){e.resolve();return!0}else if("true"===g.attr("aria-expanded")){e.resolve(o(c))}else{if(!g.val()&&b.ajax){require([b.ajax],function(a){e.resolve(w(f,b,c,d,a))})}else{e.resolve(t(b,c,g.val(),d))}}f.preventDefault();return!1;case h.UP:e.resolve(r(c));f.preventDefault();return!1;case h.ENTER:var i=a(document.getElementById(c.suggestionsId));if("true"===g.attr("aria-expanded")&&0<i.children("[aria-selected=true]").length){e.resolve(v(b,c,d))}else if(b.tags){e.resolve(u(b,c,d))}else{e.resolve()}f.preventDefault();return!1;case h.ESCAPE:if("true"===g.attr("aria-expanded")){e.resolve(s(c))}else{e.resolve()}f.preventDefault();return!1;}e.resolve();return!0});g.on("keypress",function(a){if(a.keyCode===h.COMMA){if(b.tags){y("keypress-"+a.keyCode).resolve(u(b,c,d))}a.preventDefault();return!1}return!0});g.closest("form").on("submit",function(){if(b.tags){y("form-autocomplete-submit").resolve(u(b,c,d))}return!0});g.on("blur",function(){var e=y("form-autocomplete-blur");window.setTimeout(function(){var f=a(document.activeElement),h=a.Deferred();if(f.is(document.getElementById(c.suggestionsId))){g.focus()}else if(!f.is(g)&&a(document.getElementById(c.inputId)).length){if(b.tags){h.then(function(){return u(b,c,d)}).catch()}h.then(function(){return s(c)}).catch()}h.then(function(){return e.resolve()}).catch();h.resolve()},500)});if(b.showSuggestions){var i=a(document.getElementById(c.downArrowId));i.on("click",function(a){var e=y("form-autocomplete-show-suggestions");g.focus();if(!g.val()&&b.ajax){require([b.ajax],function(f){e.resolve(w(a,b,c,d,f))})}else{e.resolve(t(b,c,g.val(),d))}})}var j=a(document.getElementById(c.suggestionsId));j.parent().prop("onclick",null).off("click");j.parent().on("click","[role=option]",function(f){var e=y("form-autocomplete-parent"),g=a(f.currentTarget).closest("[role=option]"),h=a(document.getElementById(c.suggestionsId)),i=h.children("[aria-hidden=false]").index(g);n(i,c).then(function(){return v(b,c,d)}).then(function(){return e.resolve()}).catch()});var k=a(document.getElementById(c.selectionId));k.on("click","[role=listitem]",function(f){var e=y("form-autocomplete-clicks");e.resolve(m(b,c,a(f.currentTarget),d))});k.on("keydown",function(f){var e=y("form-autocomplete-keydown-"+f.keyCode);switch(f.keyCode){case h.DOWN:f.preventDefault();e.resolve(q(c));return!1;case h.UP:f.preventDefault();e.resolve(p(c));return!1;case h.SPACE:case h.ENTER:var g=a(document.getElementById(c.selectionId)).children("[data-active-selection=true]");if(g){f.preventDefault();e.resolve(m(b,c,g,d))}return!1;}e.resolve();return!0});if(b.showSuggestions){g.on("focus",function(b){var c=a(b.currentTarget).val();a(b.currentTarget).data("last-value",c)});if(b.ajax){require([b.ajax],function(h){var i=null,j=!1,k="autocomplete-throttledhandler",l=function(a){i=null;j=!0;w(a,b,c,d,h).then(function(){if(null===i){M.util.js_complete(k)}j=!1;return arguments[0]}).catch(f.exception)},m=function(a){window.clearTimeout(i);if(j){i=window.setTimeout(m.bind(this,a),100);return}if(null===i){M.util.js_pending(k)}i=window.setTimeout(l.bind(this,a),300)};g.on("input",function(b){var c=a(b.currentTarget).val(),d=a(b.currentTarget).data("last-value");if(d!==c){m(b)}a(b.currentTarget).data("last-value",c)})})}else{g.on("input",function(f){var e=a(f.currentTarget).val(),g=a(f.currentTarget).data("last-value");if(g!==e){t(b,c,e,d)}a(f.currentTarget).data("last-value",e)})}}},y=function(b){var c="form-autocomplete:"+b;M.util.js_pending(c);var d=a.Deferred();d.then(function(){M.util.js_complete(c);return arguments[0]}).catch(f.exception);return d};return{enhance:function enhance(e,g,h,j,l,m,n,o,p){var q={selector:e,tags:!1,ajax:!1,placeholder:j,caseSensitive:!1,showSuggestions:!0,noSelectionString:n,templates:a.extend({input:"core/form_autocomplete_input",items:"core/form_autocomplete_selection_items",layout:"core/form_autocomplete_layout",selection:"core/form_autocomplete_selection",suggestions:"core/form_autocomplete_suggestions"},p)},r="autocomplete-setup-"+e;M.util.js_pending(r);if("undefined"!=typeof g){q.tags=g}if("undefined"!=typeof h){q.ajax=h}if("undefined"!=typeof l){q.caseSensitive=l}if("undefined"!=typeof m){q.showSuggestions=m}if("undefined"==typeof n){c.get_string("noselection","form").done(function(a){q.noSelectionString=a}).fail(f.exception)}var s=a(e);if(!s){b.debug("Selector not found: "+e);M.util.js_complete(r);return!1}s.css("visibility","hidden").attr("aria-hidden",!0);var t={selectId:s.attr("id"),inputId:"form_autocomplete_input-"+i,suggestionsId:"form_autocomplete_suggestions-"+i,selectionId:"form_autocomplete_selection-"+i,downArrowId:"form_autocomplete_downarrow-"+i};i++;q.multiple=s.attr("multiple");if(!q.multiple){s.prepend("<option>")}if("undefined"!=typeof o){q.closeSuggestionsOnSelect=o}else{q.closeSuggestionsOnSelect=!q.multiple}var u=a("[for="+t.selectId+"]"),v=[];s.children("option").each(function(b,c){v[b]={label:c.innerHTML,value:a(c).attr("value")}});var w=a.extend({},q,t);w.options=v;w.items=[];var y="",z=d.render(q.templates.layout,{}).then(function(b){return a(b)}),A=d.render(q.templates.input,w).then(function(b,c){y+=c;return a(b)}),B=d.render(q.templates.suggestions,w).then(function(b,c){y+=c;return a(b)}),C=d.render(q.templates.selection,w).then(function(b,c){y+=c;return a(b)});return a.when(z,A,B,C).then(function(b,c,e,f){s.hide();var g=s.parent();g.append(b);g.find("[data-region=\"form_autocomplete-input\"]").replaceWith(c);g.find("[data-region=\"form_autocomplete-suggestions\"]").replaceWith(e);g.find("[data-region=\"form_autocomplete-selection\"]").replaceWith(f);d.runTemplateJS(y);u.attr("for",t.inputId);x(q,t,s);var h=a(document.getElementById(t.suggestionsId));h.hide().attr("aria-hidden",!0)}).then(function(){return k(q,t,s)}).then(function(){return M.util.js_complete(r)}).catch(function(a){M.util.js_complete(r);f.exception(a)})}}});
//# sourceMappingURL=form-autocomplete.min.js.map