|
|
/*! * # Semantic UI x.x - 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(o){var a,s=e(this),l=e(n),r=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,p,b,w,C=e.isPlainObject(o)?e.extend(!0,{},e.fn.dropdown.settings,o):e.extend({},e.fn.dropdown.settings),x=C.className,y=C.message,S=C.metadata,T=C.namespace,A=C.regExp,k=C.selector,L=C.error,D=C.templates,q="."+T,E="module-"+T,I=e(this),O=I.find(k.text),V=I.find(k.search),F=I.find(k.input),R=I.find(k.icon),M=I.prev().find(k.text).length>0?I.prev().find(k.text):I.prev(),P=I.children(k.menu),z=P.find(k.item),H=!1,j=!1,U=this,K=I.data(E);w={initialize:function(){w.debug("Initializing dropdown",C),w.is.alreadySetup()?w.setup.reference():(w.setup.layout(),w.save.defaults(),w.set.selected(),w.is.multiple()&&(C.allowAdditions&&(C.useLabels||(w.error(L.labels),C.useLabels=!0),w.create.userLabels()),w.check.maxSelections()),w.create.id(),c&&w.bind.touchEvents(),w.bind.mouseEvents(),w.bind.keyboardEvents(),w.observeChanges(),w.instantiate())},instantiate:function(){w.verbose("Storing instance of dropdown",w),K=w,I.data(E,w)},destroy:function(){w.verbose("Destroying previous dropdown for",I),w.remove.tabbable(),I.off(q).removeData(E),P.off(q),l.off(h),p&&p.disconnect(),b&&b.disconnect()},observeChanges:function(){"MutationObserver"in t&&(p=new MutationObserver(function(e){w.debug("<select> modified, recreating menu"),w.setup.select()}),b=new MutationObserver(function(e){w.debug("Menu modified, updating selector cache"),w.refresh()}),w.has.input()&&p.observe(F[0],{childList:!0,subtree:!0}),w.has.menu()&&b.observe(P[0],{childList:!0,subtree:!0}),w.debug("Setting up mutation observer",p,b))},create:{id:function(){g=(Math.random().toString(16)+"000000000").substr(2,8),h="."+g,w.verbose("Creating unique id for element",g)},userLabels:function(){var t=w.get.userValues();t&&(w.debug("Adding user labels",t),e.each(t,function(e,t){w.verbose("Adding custom user value"),w.add.label(t,t)}))}},search:function(e){e=e!==i?e:w.get.query(),w.verbose("Searching for query",e),w.filter(e),C.allowAdditions&&w.add.userChoice(e),w.is.searchSelection()&&w.can.show()&&w.show()},select:{firstUnfiltered:function(){w.verbose("Selecting first non-filtered element"),w.remove.selectedItem(),z.not("."+x.filtered).eq(0).addClass(x.selected)},nextAvailable:function(e){e=e.eq(0);var t=e.nextAll(k.item).not("."+x.filtered).eq(0),n=e.prevAll(k.item).not("."+x.filtered).eq(0),i=t.length>0;i?(w.verbose("Moving selection to",t),t.addClass(x.selected)):(w.verbose("Moving selection to",n),n.addClass(x.selected))}},setup:{layout:function(){I.is("select")&&w.setup.select(),w.is.search()&&!w.has.search()&&(w.verbose("Adding search input"),V=e("<input />").addClass(x.search).insertBefore(O)),C.allowTab&&w.set.tabbable()},select:function(){var t=w.get.selectValues();w.debug("Dropdown initialized on a select",t),I.is("select")&&(F=I),F.parent(k.dropdown).length>0?(w.debug("UI dropdown already exists. Creating dropdown menu only"),I=F.closest(k.dropdown),P=I.children(k.menu),0===P.length&&(P=e("<div />").addClass(x.menu).appendTo(I)),P.html(D.menu(t))):(w.debug("Creating entire dropdown from select"),I=e("<div />").attr("class",F.attr("class")).addClass(x.selection).addClass(x.dropdown).html(D.dropdown(t)).insertBefore(F),F.removeAttr("class").detach().prependTo(I)),F.is("[multiple]")&&w.set.multiple(),w.refresh()},reference:function(){var e,t,n=s.index(I);w.debug("Dropdown behavior was called on select, replacing with closest dropdown"),I=I.parent(k.dropdown),w.refresh(),e=s.slice(0,n),t=s.slice(n+1),s=e.add(I).add(t),m&&(K=w,w.invoke(v))}},refresh:function(){w.verbose("Refreshing selector cache"),O=I.find(k.text),V=I.find(k.search),F=I.find(k.input),R=I.find(k.icon),M=I.prev().find(k.text).length>0?I.prev().find(k.text):I.prev(),P=I.children(k.menu),z=P.find(k.item)},toggle:function(){w.verbose("Toggling menu visibility"),w.is.active()?w.hide():w.show()},show:function(t){if(t=e.isFunction(t)?t:function(){},w.can.show()&&
return n=n||f,o=U||o,"string"==typeof t&&c!==i&&(t=t.split(/[\. ]/),s=t.length-1,e.each(t,function(n,o){var a=n!=s?o+t[n+1].charAt(0).toUpperCase()+t[n+1].slice(1):t;if(e.isPlainObject(c[a])&&n!=s)c=c[a];else{if(c[a]!==i)return l=c[a],!1;if(!e.isPlainObject(c[o])||n==s)return c[o]!==i?(l=c[o],!1):(w.error(L.method,t),!1);c=c[o]}})),e.isFunction(l)?r=l.apply(o,n):l!==i&&(r=l),e.isArray(a)?a.push(r):a!==i?a=[a,r]:r!==i&&(a=r),l}},m?(K===i&&w.initialize(),w.invoke(v)):(K!==i&&K.invoke("destroy"),w.initialize())}),a!==i?a:s},e.fn.dropdown.settings={debug:!1,verbose:!1,performance:!0,on:"click",action:"activate",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,transition:"auto",duration:200,glyphWidth:1.0714,label:{transition:"scale",duration:200,variation:!1},delay:{hide:300,show:200,search:0,touch:50},onChange: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."},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.",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",icon:"> .dropdown.icon",input:'> input[type="hidden"], > select',item:".item",label:"> .label",remove:"> .label > .delete.icon",siblingLabel:".label",menu:".menu",message:".message",menuIcon:".dropdown.icon",search:"input.search, .menu > .search > input",text:"> .text:not(.icon)"},className:{active:"active",addition:"addition",animating:"animating",disabled:"disabled",dropdown:"ui dropdown",filtered:"filtered",hidden:"hidden transition",item:"item",label:"ui label",loading:"loading",menu:"menu",message:"message",multiple:"multiple",placeholder:"default",search:"search",selected:"selected",selection:"selection",upward:"upward",visible:"visible"}},e.fn.dropdown.settings.templates={dropdown:function(t){var n=t.placeholder||!1,i=(t.values||{},"");return i+='<i class="dropdown icon"></i>',i+=t.placeholder?'<div class="default text">'+n+"</div>":'<div class="text"></div>',i+='<div class="menu">',e.each(t.values,function(e,t){i+='<div class="item" data-value="'+t.value+'">'+t.name+"</div>"}),i+="</div>"},menu:function(t){var n=(t.placeholder||!1,t.values||{},"");return e.each(t.values,function(e,t){n+='<div class="item" data-value="'+t.value+'">'+t.name+"</div>"}),n},label:function(e,t){return t+'<i class="delete icon"></i>'},message:function(e){return e},addition:function(e){return e}}}(jQuery,window,document);
|