|
|
/*! * # Semantic UI 2.0.0 - Dropdown * http://github.com/semantic-org/semantic-ui/
* * * Copyright 2015 Contributors * Released under the MIT license * http://opensource.org/licenses/MIT
* */ !function(e,t,n,i){"use strict";e.fn.dropdown=function(a){var o,s=e(this),r=e(n),l=s.selector||"",c="ontouchstart"in n.documentElement,u=(new Date).getTime(),d=[],v=arguments[0],m="string"==typeof v,f=[].slice.call(arguments,1);return s.each(function(){var h,g,b,p,w,C,x,y=e.isPlainObject(a)?e.extend(!0,{},e.fn.dropdown.settings,a):e.extend({},e.fn.dropdown.settings),S=y.className,T=y.message,A=y.metadata,k=y.namespace,D=y.regExp,I=y.selector,L=y.error,q=y.templates,R="."+k,E="module-"+k,V=e(this),O=V.find(I.text),F=V.find(I.search),P=V.find(I.input),M=V.find(I.icon),z=V.prev().find(I.text).length>0?V.prev().find(I.text):V.prev(),H=V.children(I.menu),j=H.find(I.item),U=!1,K=!1,N=this,B=V.data(E);x={initialize:function(){x.debug("Initializing dropdown",y),x.is.alreadySetup()?x.setup.reference():(x.setup.layout(),x.save.defaults(),x.restore.values(),x.is.multiple()&&x.restore.labels(),x.create.id(),c&&x.bind.touchEvents(),x.bind.mouseEvents(),x.bind.keyboardEvents(),x.observeChanges(),x.instantiate())},instantiate:function(){x.verbose("Storing instance of dropdown",x),B=x,V.data(E,x)},destroy:function(){x.verbose("Destroying previous dropdown for",V),x.remove.tabbable(),V.off(R).removeData(E),H.off(R),r.off(b),w&&w.disconnect(),C&&C.disconnect()},observeChanges:function(){"MutationObserver"in t&&(w=new MutationObserver(function(e){x.debug("<select> modified, recreating menu"),x.setup.select()}),C=new MutationObserver(function(e){x.debug("Menu modified, updating selector cache"),x.refresh()}),x.has.input()&&w.observe(P[0],{childList:!0,subtree:!0}),x.has.menu()&&C.observe(H[0],{childList:!0,subtree:!0}),x.debug("Setting up mutation observer",w,C))},create:{id:function(){p=(Math.random().toString(16)+"000000000").substr(2,8),b="."+p,x.verbose("Creating unique id for element",p)},userLabels:function(){var t=x.get.userValues();t&&(x.debug("Adding user labels",t),e.each(t,function(e,t){x.verbose("Adding custom user value"),x.add.label(t,t)}))}},search:function(e){e=e!==i?e:x.get.query(),x.verbose("Searching for query",e),x.filter(e)},select:{firstUnfiltered:function(){x.verbose("Selecting first non-filtered element"),x.remove.selectedItem(),j.not(I.unselectable).eq(0).addClass(S.selected)},nextAvailable:function(e){e=e.eq(0);var t=e.nextAll(I.item).not(I.unselectable).eq(0),n=e.prevAll(I.item).not(I.unselectable).eq(0),i=t.length>0;i?(x.verbose("Moving selection to",t),t.addClass(S.selected)):(x.verbose("Moving selection to",n),n.addClass(S.selected))}},setup:{api:function(){var e={debug:y.debug,cache:"local",on:!1};x.verbose("First request, initializing API"),V.api(e)},layout:function(){V.is("select")&&x.setup.select(),x.is.search()&&!x.has.search()&&(x.verbose("Adding search input"),F=e("<input />").addClass(S.search).insertBefore(O)),y.allowTab&&x.set.tabbable(),0===H.length&&(H=e("<div />").addClass(S.menu).appendTo(V))},select:function(){var t=x.get.selectValues();x.debug("Dropdown initialized on a select",t),V.is("select")&&(P=V),P.parent(I.dropdown).length>0?(x.debug("UI dropdown already exists. Creating dropdown menu only"),V=P.closest(I.dropdown),H=V.children(I.menu),x.setup.menu(t)):(x.debug("Creating entire dropdown from select"),V=e("<div />").attr("class",P.attr("class")).addClass(S.selection).addClass(S.dropdown).html(q.dropdown(t)).insertBefore(P),P.removeAttr("class").detach().prependTo(V)),P.is("[multiple]")&&x.set.multiple(),x.refresh()},menu:function(e){H.html(q.menu(e)),j=H.find(I.item)},reference:function(){var e,t,n=s.index(V);x.debug("Dropdown behavior was called on select, replacing with closest dropdown"),V=V.parent(I.dropdown),x.refresh(),e=s.slice(0,n),t=s.slice(n+1),s=e.add(V).add(t),m&&(B=x,x.invoke(v))}},refresh:function(){x.verbose("Refreshing selector cache"),O=V.find(I.text),F=V.find(I.search),P=V.find(I.input),M=V.find(I.icon),z=V.prev().find(I.text).length>0?V.prev().find(I.text):V.prev(),H=V.children(I.menu),j=H.find(I.item)},toggle:function(){x.verbose("Toggling menu visibility"),x.is.active()?x.hide():x.show()},show:function(t){if(t=e.isFunction(t)?t:function(){},x.can.show()&&!x.is.active(
}},hideAndClear:function(){x.is.searchSelection()?(x.remove.searchTerm(),x.hide(function(){x.remove.filteredItem()})):x.hide()},delay:{show:function(){x.verbose("Delaying show event to ensure user intent"),clearTimeout(x.timer),x.timer=setTimeout(x.show,y.delay.show)},hide:function(){x.verbose("Delaying hide event to ensure user intent"),clearTimeout(x.timer),x.timer=setTimeout(x.hide,y.delay.hide)}},escape:{regExp:function(e){return e=String(e),e.replace(D.escape,"\\$&")}},setting:function(t,n){if(x.debug("Changing setting",t,n),e.isPlainObject(t))e.extend(!0,y,t);else{if(n===i)return y[t];y[t]=n}},internal:function(t,n){if(e.isPlainObject(t))e.extend(!0,x,t);else{if(n===i)return x[t];x[t]=n}},debug:function(){y.debug&&(y.performance?x.performance.log(arguments):(x.debug=Function.prototype.bind.call(console.info,console,y.name+":"),x.debug.apply(console,arguments)))},verbose:function(){y.verbose&&y.debug&&(y.performance?x.performance.log(arguments):(x.verbose=Function.prototype.bind.call(console.info,console,y.name+":"),x.verbose.apply(console,arguments)))},error:function(){x.error=Function.prototype.bind.call(console.error,console,y.name+":"),x.error.apply(console,arguments)},performance:{log:function(e){var t,n,i;y.performance&&(t=(new Date).getTime(),i=u||t,n=t-i,u=t,d.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:N,"Execution Time":n})),clearTimeout(x.performance.timer),x.performance.timer=setTimeout(x.performance.display,500)},display:function(){var t=y.name+":",n=0;u=!1,clearTimeout(x.performance.timer),e.each(d,function(e,t){n+=t["Execution Time"]}),t+=" "+n+"ms",l&&(t+=" '"+l+"'"),(console.group!==i||console.table!==i)&&d.length>0&&(console.groupCollapsed(t),console.table?console.table(d):e.each(d,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),d=[]}},invoke:function(t,n,a){var s,r,l,c=B;return n=n||f,a=N||a,"string"==typeof t&&c!==i&&(t=t.split(/[\. ]/),s=t.length-1,e.each(t,function(n,a){var o=n!=s?a+t[n+1].charAt(0).toUpperCase()+t[n+1].slice(1):t;if(e.isPlainObject(c[o])&&n!=s)c=c[o];else{if(c[o]!==i)return r=c[o],!1;if(!e.isPlainObject(c[a])||n==s)return c[a]!==i?(r=c[a],!1):(x.error(L.method,t),!1);c=c[a]}})),e.isFunction(r)?l=r.apply(a,n):r!==i&&(l=r),e.isArray(o)?o.push(l):o!==i?o=[o,l]:l!==i&&(o=l),r}},m?(B===i&&x.initialize(),x.invoke(v)):(B!==i&&B.invoke("destroy"),x.initialize())}),o!==i?o:s},e.fn.dropdown.settings={debug:!1,verbose:!1,performance:!0,on:"click",action:"activate",apiSettings:!1,saveRemoteData:!1,keepOnScreen:!0,match:"both",fullTextSearch:!1,placeholder:"auto",preserveHTML:!0,sortSelect:!1,forceSelection:!0,allowAdditions:!1,maxSelections:!1,useLabels:!0,delimiter:",",showOnFocus:!0,allowTab:!0,allowCategorySelection:!1,fireOnInit:!1,transition:"auto",duration:200,glyphWidth:1.0714,label:{transition:"scale",duration:200,variation:!1},delay:{hide:300,show:200,search:20,touch:50},onChange:function(e,t,n){},onAdd:function(e,t,n){},onRemove:function(e,t,n){},onLabelSelect:function(e){},onLabelCreate:function(t,n){return e(this)},onNoResults:function(e){return!0},onShow:function(){},onHide:function(){},name:"Dropdown",namespace:"dropdown",message:{addResult:"Add <b>{term}</b>",count:"{count} selected",maxSelections:"Max {maxCount} selections",noResults:"No results found.",serverError:"There was an error contacting the server"},error:{action:"You called a dropdown action that was not defined",alreadySetup:"Once a select has been initialized behaviors must be called on the created ui dropdown",labels:"Allowing user additions currently requires the use of labels.",method:"The method you called is not defined.",noAPI:"The API module is required to load resources remotely",noStorage:"Saving remote data requires local storage",noTransition:"This module requires ui transitions <https://github.com/Semantic-Org/UI-Transition>"},regExp:{escape:/[-[\]{}()*+?.,\\^$|#\s]/g},metadata:{defaultText:"defaultText",defaultValue:"defaultValue",placeholderText:"placeholderText",text:"text",value:"value"},selector:{addition:".addition",dropdown:".ui.dropdown",ic
|