|
|
/*! * # 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=e(t),c=s.selector||"",u="ontouchstart"in n.documentElement,d=(new Date).getTime(),v=[],m=arguments[0],f="string"==typeof m,h=[].slice.call(arguments,1);return s.each(function(){var g,b,p,w,C,x,y,S=e.isPlainObject(a)?e.extend(!0,{},e.fn.dropdown.settings,a):e.extend({},e.fn.dropdown.settings),A=S.className,T=S.message,k=S.metadata,L=S.namespace,D=S.regExp,I=S.selector,R=S.error,q=S.templates,V="."+L,E="module-"+L,O=e(this),F=O.find(I.text),P=O.find(I.search),M=O.find(I.input),z=O.find(I.icon),H=O.prev().find(I.text).length>0?O.prev().find(I.text):O.prev(),j=O.children(I.menu),U=j.find(I.item),N=!1,K=!1,W=this,B=O.data(E);y={initialize:function(){y.debug("Initializing dropdown",S),y.is.alreadySetup()?y.setup.reference():(y.setup.layout(),y.refreshData(),y.save.defaults(),y.restore.selected(),y.create.id(),u&&y.bind.touchEvents(),y.bind.mouseEvents(),y.bind.keyboardEvents(),y.observeChanges(),y.instantiate())},instantiate:function(){y.verbose("Storing instance of dropdown",y),B=y,O.data(E,y)},destroy:function(){y.verbose("Destroying previous dropdown for",O),y.remove.tabbable(),O.off(V).removeData(E),j.off(V),r.off(p),C&&C.disconnect(),x&&x.disconnect()},observeChanges:function(){"MutationObserver"in t&&(C=new MutationObserver(function(){y.debug("<select> modified, recreating menu"),y.setup.select()}),x=new MutationObserver(function(){y.debug("Menu modified, updating selector cache"),y.refresh()}),y.has.input()&&C.observe(M[0],{childList:!0,subtree:!0}),y.has.menu()&&x.observe(j[0],{childList:!0,subtree:!0}),y.debug("Setting up mutation observer",C,x))},create:{id:function(){w=(Math.random().toString(16)+"000000000").substr(2,8),p="."+w,y.verbose("Creating unique id for element",w)},userChoice:function(t){var n,a,o;return(t=t||y.get.userValues())?(t=e.isArray(t)?t:[t],e.each(t,function(t,s){y.get.item(s)===!1&&(o=S.templates.addition(s),a=e("<div />").html(o).data(k.value,s).addClass(A.addition).addClass(A.item),n=n===i?a:n.add(a),y.verbose("Creating user choices for value",s,a))}),n):!1},userLabels:function(){var t=y.get.userValues();t&&(y.debug("Adding user labels",t),e.each(t,function(e,t){y.verbose("Adding custom user value"),y.add.label(t,t)}))}},search:function(e){e=e!==i?e:y.get.query(),y.verbose("Searching for query",e),y.filter(e)},select:{firstUnfiltered:function(){y.verbose("Selecting first non-filtered element"),y.remove.selectedItem(),U.not(I.unselectable).eq(0).addClass(A.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?(y.verbose("Moving selection to",t),t.addClass(A.selected)):(y.verbose("Moving selection to",n),n.addClass(A.selected))}},setup:{api:function(){var e={debug:S.debug,on:!1};y.verbose("First request, initializing API"),O.api(e)},layout:function(){O.is("select")&&y.setup.select(),y.is.search()&&!y.has.search()&&(y.verbose("Adding search input"),P=e("<input />").addClass(A.search).insertBefore(F)),S.allowTab&&y.set.tabbable(),0===j.length&&(j=e("<div />").addClass(A.menu).appendTo(O))},select:function(){var t=y.get.selectValues();y.debug("Dropdown initialized on a select",t),O.is("select")&&(M=O),M.parent(I.dropdown).length>0?(y.debug("UI dropdown already exists. Creating dropdown menu only"),O=M.closest(I.dropdown),j=O.children(I.menu),y.setup.menu(t)):(y.debug("Creating entire dropdown from select"),O=e("<div />").attr("class",M.attr("class")).addClass(A.selection).addClass(A.dropdown).html(q.dropdown(t)).insertBefore(M),M.removeAttr("class").detach().prependTo(O)),M.is("[multiple]")&&y.set.multiple(),y.refresh()},menu:function(e){j.html(q.menu(e)),U=j.find(I.item)},reference:function(){var e,t,n=s.index(O);y.debug("Dropdown behavior was called on select, replacing with closest dropdown"),O=O.parent(I.dropdown),y.refresh(),e=s.slice(0,n),t=s.slice(n+1),s=e.add(O).add(t),f&&(B=y,y.invoke(m))}},refresh:function(){y.refreshSelectors(),y.refreshData()},refreshSelectors:function(){y.verbose("Refreshing selector },inObject:function(t,n){var i=!1;return e.each(n,function(e,n){return n==t?(i=!0,!0):void 0}),i},multiple:function(){return O.hasClass(A.multiple)},single:function(){return!y.is.multiple()},selectMutation:function(t){var n=!1;return e.each(t,function(t,i){return i.target&&e(i.target).is("select")?(n=!0,!0):void 0}),n},search:function(){return O.hasClass(A.search)},searchSelection:function(){return y.has.search()&&0===P.closest(I.menu).length},selection:function(){return O.hasClass(A.selection)},userValue:function(t){return-1!==e.inArray(t,y.get.userValues())},upward:function(e){var t=e||O;return t.hasClass(A.upward)},visible:function(e){return e?e.hasClass(A.visible):j.hasClass(A.visible)}},can:{click:function(){return u||"click"==S.on},show:function(){return!O.hasClass(A.disabled)&&U.length>0},useAPI:function(){return e.fn.api!==i}},animate:{show:function(t,n){var a,o=n||j,s=n?function(){}:function(){y.hideSubMenus(),y.hideOthers(),y.set.active()};t=e.isFunction(t)?t:function(){},y.verbose("Doing menu show animation",o),y.set.direction(n),a=y.get.transition(n),y.is.selection()&&y.set.scrollPosition(y.get.selectedItem(),!0),(y.is.hidden(o)||y.is.animating(o))&&("none"==a?(s(),o.transition("show"),t.call(W)):e.fn.transition!==i&&O.transition("is supported")?o.transition({animation:a+" in",debug:S.debug,verbose:S.verbose,duration:S.duration,queue:!0,onStart:s,onComplete:function(){t.call(W)}}):y.error(R.noTransition,a))},hide:function(t,n){var a=n||j,o=(n?.9*S.duration:S.duration,n?function(){}:function(){y.can.click()&&y.unbind.intent(),y.remove.active()}),s=y.get.transition(n);t=e.isFunction(t)?t:function(){},(y.is.visible(a)||y.is.animating(a))&&(y.verbose("Doing menu hide animation",a),"none"==s?(o(),a.transition("hide"),t.call(W)):e.fn.transition!==i&&O.transition("is supported")?a.transition({animation:s+" out",duration:S.duration,debug:S.debug,verbose:S.verbose,queue:!0,onStart:o,onComplete:function(){"auto"==S.direction&&y.remove.upward(n),t.call(W)}}):y.error(R.transition))}},hideAndClear:function(){y.has.search()?(y.remove.searchTerm(),y.hide(function(){y.remove.filteredItem()})):y.hide()},delay:{show:function(){y.verbose("Delaying show event to ensure user intent"),clearTimeout(y.timer),y.timer=setTimeout(y.show,S.delay.show)},hide:function(){y.verbose("Delaying hide event to ensure user intent"),clearTimeout(y.timer),y.timer=setTimeout(y.hide,S.delay.hide)}},escape:{regExp:function(e){return e=String(e),e.replace(D.escape,"\\$&")}},setting:function(t,n){if(y.debug("Changing setting",t,n),e.isPlainObject(t))e.extend(!0,S,t);else{if(n===i)return S[t];S[t]=n}},internal:function(t,n){if(e.isPlainObject(t))e.extend(!0,y,t);else{if(n===i)return y[t];y[t]=n}},debug:function(){S.debug&&(S.performance?y.performance.log(arguments):(y.debug=Function.prototype.bind.call(console.info,console,S.name+":"),y.debug.apply(console,arguments)))},verbose:function(){S.verbose&&S.debug&&(S.performance?y.performance.log(arguments):(y.verbose=Function.prototype.bind.call(console.info,console,S.name+":"),y.verbose.apply(console,arguments)))},error:function(){y.error=Function.prototype.bind.call(console.error,console,S.name+":"),y.error.apply(console,arguments)},performance:{log:function(e){var t,n,i;S.performance&&(t=(new Date).getTime(),i=d||t,n=t-i,d=t,v.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:W,"Execution Time":n})),clearTimeout(y.performance.timer),y.performance.timer=setTimeout(y.performance.display,500)},display:function(){var t=S.name+":",n=0;d=!1,clearTimeout(y.performance.timer),e.each(v,function(e,t){n+=t["Execution Time"]}),t+=" "+n+"ms",c&&(t+=" '"+c+"'"),(console.group!==i||console.table!==i)&&v.length>0&&(console.groupCollapsed(t),console.table?console.table(v):e.each(v,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),v=[]}},invoke:function(t,n,a){var s,r,l,c=B;return n=n||h,a=W||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{i
|