|
|
/*! * # 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,L=y.regExp,D=y.selector,I=y.error,R=y.templates,q="."+k,E="module-"+k,V=e(this),O=V.find(D.text),F=V.find(D.search),P=V.find(D.input),M=V.find(D.icon),z=V.prev().find(D.text).length>0?V.prev().find(D.text):V.prev(),H=V.children(D.menu),j=H.find(D.item),U=!1,N=!1,K=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.selected(),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(q).removeData(E),H.off(q),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(D.unselectable).eq(0).addClass(S.selected)},nextAvailable:function(e){e=e.eq(0);var t=e.nextAll(D.item).not(D.unselectable).eq(0),n=e.prevAll(D.item).not(D.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,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(D.dropdown).length>0?(x.debug("UI dropdown already exists. Creating dropdown menu only"),V=P.closest(D.dropdown),H=V.children(D.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(R.dropdown(t)).insertBefore(P),P.removeAttr("class").detach().prependTo(V)),P.is("[multiple]")&&x.set.multiple(),x.refresh()},menu:function(e){H.html(R.menu(e)),j=H.find(D.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(D.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(D.text),F=V.find(D.search),P=V.find(D.input),M=V.find(D.icon),z=V.prev().find(D.text).length>0?V.prev().find(D.text):V.prev(),H=V.children(D.menu),j=H.find(D.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()){if(x.debug("Showing dropdown"),x.is.multiple( (x.is.hidden(o)||x.is.animating(o))&&("none"==a?(s(),o.transition("show"),t.call(K)):e.fn.transition!==i&&V.transition("is supported")?o.transition({animation:a+" in",debug:y.debug,verbose:y.verbose,duration:y.duration,queue:!0,onStart:s,onComplete:function(){t.call(K)}}):x.error(I.noTransition,a))},hide:function(t,n){var a=n||H,o=(n?.9*y.duration:y.duration,n?function(){}:function(){x.can.click()&&x.unbind.intent(),x.remove.active()}),s=x.get.transition(n);t=e.isFunction(t)?t:function(){},(x.is.visible(a)||x.is.animating(a))&&(x.verbose("Doing menu hide animation",a),"none"==s?(o(),a.transition("hide"),t.call(K)):e.fn.transition!==i&&V.transition("is supported")?a.transition({animation:s+" out",duration:y.duration,debug:y.debug,verbose:y.verbose,queue:!0,onStart:o,onComplete:function(){"auto"==y.direction&&x.remove.upward(n),t.call(K)}}):x.error(I.transition))}},hideAndClear:function(){x.has.search()?(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(L.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:K,"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=K||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(I.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:!0,throttle:100,direction:"auto",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
|