|
|
- /*!
- * # Semantic UI 2.1.6 - 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(h){var g,p,b,w,x,C,S,y=e.isPlainObject(a)?e.extend(!0,{},e.fn.dropdown.settings,a):e.extend({},e.fn.dropdown.settings),T=y.className,A=y.message,k=y.fields,L=y.keys,D=y.metadata,I=y.namespace,R=y.regExp,q=y.selector,V=y.error,E=y.templates,O="."+I,F="module-"+I,P=e(this),M=e(y.context),H=P.find(q.text),z=P.find(q.search),j=P.find(q.input),U=P.find(q.icon),N=P.prev().find(q.text).length>0?P.prev().find(q.text):P.prev(),B=P.children(q.menu),W=B.find(q.item),K=!1,$=!1,Q=!1,Y=this,G=P.data(F);S={initialize:function(){S.debug("Initializing dropdown",y),S.is.alreadySetup()?S.setup.reference():(S.setup.layout(),S.refreshData(),S.save.defaults(),S.restore.selected(),S.create.id(),S.bind.events(),S.observeChanges(),S.instantiate())},instantiate:function(){S.verbose("Storing instance of dropdown",S),G=S,P.data(F,S)},destroy:function(){S.verbose("Destroying previous dropdown",P),S.remove.tabbable(),P.off(O).removeData(F),B.off(O),r.off(b),x&&x.disconnect(),C&&C.disconnect()},observeChanges:function(){"MutationObserver"in t&&(x=new MutationObserver(function(e){S.debug("<select> modified, recreating menu"),S.setup.select()}),C=new MutationObserver(function(e){S.debug("Menu modified, updating selector cache"),S.refresh()}),S.has.input()&&x.observe(j[0],{childList:!0,subtree:!0}),S.has.menu()&&C.observe(B[0],{childList:!0,subtree:!0}),S.debug("Setting up mutation observer",x,C))},create:{id:function(){w=(Math.random().toString(16)+"000000000").substr(2,8),b="."+w,S.verbose("Creating unique id for element",w)},userChoice:function(t){var n,a,o;return(t=t||S.get.userValues())?(t=e.isArray(t)?t:[t],e.each(t,function(t,s){S.get.item(s)===!1&&(o=y.templates.addition(S.add.variables(A.addResult,s)),a=e("<div />").html(o).attr("data-"+D.value,s).attr("data-"+D.text,s).addClass(T.addition).addClass(T.item),n=n===i?a:n.add(a),S.verbose("Creating user choices for value",s,a))}),n):!1},userLabels:function(t){var n=S.get.userValues();n&&(S.debug("Adding user labels",n),e.each(n,function(e,t){S.verbose("Adding custom user value"),S.add.label(t,t)}))},menu:function(){B=e("<div />").addClass(T.menu).appendTo(P)}},search:function(e){e=e!==i?e:S.get.query(),S.verbose("Searching for query",e),S.filter(e)},select:{firstUnfiltered:function(){S.verbose("Selecting first non-filtered element"),S.remove.selectedItem(),W.not(q.unselectable).eq(0).addClass(T.selected)},nextAvailable:function(e){e=e.eq(0);var t=e.nextAll(q.item).not(q.unselectable).eq(0),n=e.prevAll(q.item).not(q.unselectable).eq(0),i=t.length>0;i?(S.verbose("Moving selection to",t),t.addClass(T.selected)):(S.verbose("Moving selection to",n),n.addClass(T.selected))}},setup:{api:function(){var e={debug:y.debug,on:!1};S.verbose("First request, initializing API"),P.api(e)},layout:function(){P.is("select")&&(S.setup.select(),S.setup.returnedObject()),S.has.menu()||S.create.menu(),S.is.search()&&!S.has.search()&&(S.verbose("Adding search input"),z=e("<input />").addClass(T.search).prop("autocomplete","off").insertBefore(H)),y.allowTab&&S.set.tabbable()},select:function(){var t=S.get.selectValues();S.debug("Dropdown initialized on a select",t),P.is("select")&&(j=P),j.parent(q.dropdown).length>0?(S.debug("UI dropdown already exists. Creating dropdown menu only"),P=j.closest(q.dropdown),S.has.menu()||S.create.menu(),B=P.children(q.menu),S.setup.menu(t)):(S.debug("Creating entire dropdown from select"),P=e("<div />").attr("class",j.attr("class")).addClass(T.selection).addClass(T.dropdown).html(E.dropdown(t)).insertBefore(j),j.hasClass(T.multiple)&&j.prop("multiple")===!1&&(S.error(V.missingMultiple),j.prop("multiple",!0)),j.is("[multiple]")&&S.set.multiple(),j.prop("disabled")&&(S.debug("Disabling dropdown"),P.addClass(T.disabled)),j.removeAttr("class").detach().prependTo(P)),S.refresh()},menu:function(e){B.html(E.menu(e,k)),W=B.find(q.item)},reference:funct
- t.removeClass(T.filtered).removeClass(T.active),y.useLabels&&t.removeClass(T.selected)}):!1},selectedItem:function(){W.removeClass(T.selected)},value:function(e,t,n){var i,a=S.get.values();S.has.selectInput()?(S.verbose("Input is <select> removing selected option",e),i=S.remove.arrayValue(e,a),S.remove.optionValue(e)):(S.verbose("Removing from delimited values",e),i=S.remove.arrayValue(e,a),i=i.join(y.delimiter)),y.fireOnInit===!1&&S.is.initialLoad()?S.verbose("No callback on initial load",y.onRemove):y.onRemove.call(Y,e,t,n),S.set.value(i,t,n),S.check.maxSelections()},arrayValue:function(t,n){return e.isArray(n)||(n=[n]),n=e.grep(n,function(e){return t!=e}),S.verbose("Removed value from delimited string",t,n),n},label:function(e,t){var n=P.find(q.label),i=n.filter('[data-value="'+e+'"]');S.verbose("Removing label",i),i.remove()},activeLabels:function(e){e=e||P.find(q.label).filter("."+T.active),S.verbose("Removing active label selections",e),S.remove.labels(e)},labels:function(t){t=t||P.find(q.label),S.verbose("Removing labels",t),t.each(function(){var t=e(this),n=t.data(D.value),a=n!==i?String(n):n,o=S.is.userValue(a);return y.onLabelRemove.call(t,n)===!1?void S.debug("Label remove callback cancelled removal"):void(o?(S.remove.value(a),S.remove.label(a)):S.remove.selected(a))})},tabbable:function(){S.has.search()?(S.debug("Searchable dropdown initialized"),z.removeAttr("tabindex"),B.removeAttr("tabindex")):(S.debug("Simple selection dropdown initialized"),P.removeAttr("tabindex"),B.removeAttr("tabindex"))}},has:{search:function(){return z.length>0},selectInput:function(){return j.is("select")},firstLetter:function(e,t){var n,i;return e&&0!==e.length&&"string"==typeof t?(n=S.get.choiceText(e,!1),t=t.toLowerCase(),i=String(n).charAt(0).toLowerCase(),t==i):!1},input:function(){return j.length>0},items:function(){return W.length>0},menu:function(){return B.length>0},message:function(){return 0!==B.children(q.message).length},label:function(e){var t=P.find(q.label);return t.filter('[data-value="'+e+'"]').length>0},maxSelections:function(){return y.maxSelections&&S.get.selectionCount()>=y.maxSelections},allResultsFiltered:function(){return W.filter(q.unselectable).length===W.length},query:function(){return""!==S.get.query()},value:function(t){var n=S.get.values(),i=e.isArray(n)?n&&-1!==e.inArray(t,n):n==t;return i?!0:!1}},is:{active:function(){return P.hasClass(T.active)},alreadySetup:function(){return P.is("select")&&P.parent(q.dropdown).length>0&&0===P.prev().length},animating:function(e){return e?e.transition&&e.transition("is animating"):B.transition&&B.transition("is animating")},disabled:function(){return P.hasClass(T.disabled)},focused:function(){return n.activeElement===P[0]},focusedOnSearch:function(){return n.activeElement===z[0]},allFiltered:function(){return(S.is.multiple()||S.has.search())&&!S.has.message()&&S.has.allResultsFiltered()},hidden:function(e){return!S.is.visible(e)},initialLoad:function(){return g},onScreen:function(e){var t,n=e||B,i=!0,a={};return n.addClass(T.loading),t={context:{scrollTop:M.scrollTop(),height:M.outerHeight()},menu:{offset:n.offset(),height:n.outerHeight()}},a={above:t.context.scrollTop<=t.menu.offset.top-t.menu.height,below:t.context.scrollTop+t.context.height>=t.menu.offset.top+t.menu.height},a.below?(S.verbose("Dropdown can fit in context downward",a),i=!0):a.below||a.above?(S.verbose("Dropdown cannot fit below, opening upward",a),i=!1):(S.verbose("Dropdown cannot fit in either direction, favoring downward",a),i=!0),n.removeClass(T.loading),i},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 P.hasClass(T.multiple)},single:function(){return!S.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 P.hasClass(T.search)},searchSelection:function(){return S.has.search()&&1===z.parent(q.dropdown).length},selection:function(){return P.hasClass(T.selection)},userValue:function(t){return-1!==e.inArray
|