agenda-libre-ruby/public/webshims/1.15.9/shims/form-datalist-lazy.js

1 line
10 KiB
JavaScript
Raw Normal View History

webshims.register("form-datalist-lazy",function(a,b,c,d,e,f){var g=0,h=a.webshims.cfg.forms,i={},j=function(a){if(!a)return[];if(i[a])return i[a];var b;try{b=JSON.parse(localStorage.getItem("storedDatalistOptions"+a))}catch(c){}return i[a]=b||[],b||[]},k=function(a,b){if(a){b=b||[];try{localStorage.setItem("storedDatalistOptions"+a,JSON.stringify(b))}catch(c){}}},l=/</g,m=/>/g,n=/\s*,\s*/g;b.getDataListVal=function(b){var c=a.data(b,"datalistWidget");return c?c.getPartialValue():a.prop(b,"value")},a.extend(f.shadowListProto,{_lazyCreate:function(d){var e=this;this.hideList=a.proxy(e,"hideList"),this.index=-1,this.input=d.input,this.arrayOptions=[],this._updateOptions(),this.popover=b.objectCreate(b.wsPopover,{},this.options.popover),this.shadowList=this.popover.element.addClass("datalist-polyfill"),this.shadowList.on("mouseenter.datalistWidget mousedown.datalistWidget click.datalistWidget","li",function(b){if(!e._stopMouseOver||!b||"mouseenter"!=b.type){var c=a("li:not(.hidden-item)",e.shadowList),f="mousedown"==b.type||"click"==b.type;return f&&a(d.input).getNativeElement().triggerHandler("beforeselect",[a(b.currentTarget).find(".option-value").text()])===!1?"mousedown"!=b.type:(e.markItem(c.index(b.currentTarget),f,c),"click"==b.type&&(e.hideList(),h.customDatalist&&a(d.input).getNativeElement().trigger("datalistselect")),"mousedown"!=b.type)}}),d.input.setAttribute("autocomplete","off"),this.lastCompletedValue="",a(d.input).attr({"aria-haspopup":"true","aria-autocomplete":"both"}).on({"input.datalistWidget":function(){e.triggeredByDatalist||(e.changedValue=!1,e.showHideOptions())},"keydown.datalistWidget":function(b){var c,f,g=b.keyCode,i=!!e.options.inlineValue||"onlyScroll";if(40==g&&!e.showList())return e.markItem(e.index+1,i),!1;if(e.popover.isVisible){if(38==g)return e.markItem(e.index-1,i),!1;if(!b.shiftKey&&(33==g||36==g))return e.markItem(0,i),!1;if(!b.shiftKey&&(34==g||35==g))return f=a("li:not(.hidden-item)",e.shadowList),e.markItem(f.length-1,!0,f),!1;if(13==g||27==g){if(13==g){if(c=a("li.active-item:not(.hidden-item)",e.shadowList),e.isCompleted&&(a.prop(d.input,"selectionStart",a.prop(d.input,"value").length),e.lastCompletedValue&&!c[0]&&(e.lastCompletedValue="",e.isCompleted=!1)),a(d.input).getNativeElement().triggerHandler("beforeselect",[c.find(".option-value").text()])===!1)return;e.changeValue(c)}if(e.hideList(),h.customDatalist&&c&&c[0]&&a(d.input).getNativeElement().trigger("datalistselect"),13!=b.keyCode||c&&c[0])return!1}}},"focus.datalistWidget":function(){e.lastCompletedValue="",e.options.focus&&e.showList()},"mousedown.datalistWidget":function(){a(this).is(":focus")&&e.showList()}}),a(this.datalist).off("updateDatalist.datalistWidget").on("updateDatalist.datalistWidget",a.proxy(this,"_resetListCached")).on("remove",function(a){a.originalEvent||e.destroy()}),this._resetListCached(),d.input.form&&(d.input.name||d.input.id)&&a(d.input.form).on("submit.datalistWidget"+d.input.id,function(){if(!a(d.input).hasClass("no-datalist-cache")&&"off"!=e._autocomplete){var b=a.prop(d.input,"value"),c=(d.input.name||d.input.id)+a.prop(d.input,"type");e.storedOptions||(e.storedOptions=j(c)),b&&-1==e.storedOptions.indexOf(b)&&(e.storedOptions.push(b),k(c,e.storedOptions))}}),a(c).on("unload.datalist"+this.id+" beforeunload.datalist"+this.id,function(a){e.destroy(a)})},_resetListCached:function(){var b,d=this;this.needsUpdate=!0,this.lastUpdatedValue=!1,this.lastUnfoundValue="",this.updateTimer||(c.QUnit||(b=a(d.input).is(":focus")&&(d.options.focus||a.prop(d.input,"value")))?d.updateListOptions(b):d.updateTimer=setTimeout(function(){d.updateListOptions(),d=null},200))},_updateOptions:function(){this.options=b.getOptions(this.input,"list",f.list),a(this.input).prop("multiple")&&("email"!=a(this.input).prop("type")?b.warn("multiple only used on email and file type. Use data-list-multiple instead."):this.options.multiple=!0),this.options.inlineValue||this.options.valueCompletion||(a.attr(this.input,"aria-autocomplete","list"),a.attr(this.input,"aria-expanded","false")),this.options.getOptionContent&&!a.isFunction