You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
37 KiB
12 lines
37 KiB
/*!
|
|
* # 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(){x.debug("<select> modified, recreating menu"),x.setup.select()}),C=new MutationObserver(function(){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()){if(x.debug("Showing dropdown"),x.is.multiple()&&!x.has.search()&&x.is.allFiltered())return!0;x.animate.show(function(){x.can.click()&&x.bind.intent(),x.set.visible(),t.call(N)}),y.onShow.call(N)}},hide:function(t){t=e.isFunction(t)?t:function(){},x.is.active()&&(x.debug("Hiding dropdown"),x.animate.hide(function(){x.remove.visible(),t.call(N)}),y.onHide.call(N))},hideOthers:function(){x.verbose("Finding other dropdowns to hide"),s.not(V).has(I.menu+"."+S.visible).dropdown("hide")},hideMenu:function(){x.verbose("Hiding menu instantaneously"),x.remove.active(),x.remove.visible(),H.transition("hide")},hideSubMenus:function(){var e=H.children(I.item).find(I.menu);x.verbose("Hiding sub menus",e),e.transition("hide")},bind:{keyboardEvents:function(){x.debug("Binding keyboard events"),V.on("keydown"+R,x.event.keydown),x.has.search()&&V.on(x.get.inputEvent()+R,I.search,x.event.input),x.is.multiple()&&r.on("keydown"+b,x.event.document.keydown)},touchEvents:function(){x.debug("Touch device detected binding additional touch events"),x.is.searchSelection()||V.on("touchstart"+R,x.event.test.toggle),H.on("touchstart"+R,I.item,x.event.item.mouseenter)},mouseEvents:function(){x.debug("Mouse detected binding mouse events"),x.is.multiple()&&V.on("click"+R,I.label,x.event.label.click).on("click"+R,I.remove,x.event.remove.click),x.is.searchSelection()?(V.on("mousedown"+R,I.menu,x.event.menu.mousedown).on("mouseup"+R,I.menu,x.event.menu.mouseup).on("click"+R,I.search,x.show).on("focus"+R,I.search,x.event.search.focus).on("blur"+R,I.search,x.event.search.blur).on("click"+R,I.text,x.event.text.focus),x.is.multiple()&&V.on("click"+R,x.event.click)):("click"==y.on?V.on("click"+R,x.event.test.toggle):"hover"==y.on?V.on("mouseenter"+R,x.delay.show).on("mouseleave"+R,x.delay.hide):V.on(y.on+R,x.toggle),V.on("mousedown"+R,x.event.mousedown).on("mouseup"+R,x.event.mouseup).on("focus"+R,x.event.focus).on("blur"+R,x.event.blur)),H.on("mouseenter"+R,I.item,x.event.item.mouseenter).on("mouseleave"+R,I.item,x.event.item.mouseleave).on("click"+R,I.item,x.event.item.click)},intent:function(){x.verbose("Binding hide intent event to document"),c&&r.on("touchstart"+b,x.event.test.touch).on("touchmove"+b,x.event.test.touch),r.on("click"+b,x.event.test.hide)}},unbind:{intent:function(){x.verbose("Removing hide intent event from document"),c&&r.off("touchstart"+b).off("touchmove"+b),r.off("click"+b)}},filter:function(e){var t=e!==i?e:x.get.query(),n=function(){x.is.multiple()&&x.filterActive(),x.select.firstUnfiltered(),x.has.allResultsFiltered()?y.onNoResults.call(N,t)?y.allowAdditions||(x.verbose("All items filtered, showing message",t),x.add.message(T.noResults)):(x.verbose("All items filtered, hiding dropdown",t),x.hideMenu()):x.remove.message(),y.allowAdditions&&x.add.userChoice(e),x.is.searchSelection()&&x.can.show()&&x.is.focusedOnSearch()&&x.show()};x.has.maxSelections()||(y.apiSettings?x.can.useAPI()?x.queryRemote(t,function(){n()}):x.error(L.noAPI):(x.filterItems(t),n()))},queryRemote:function(t,n){var i={errorDuration:!1,urlData:{query:t},onError:function(){x.add.message(T.serverError),n()},onFailure:function(){x.add.message(T.serverError),n()},onSuccess:function(e){x.remove.message(),x.setup.menu({values:e.results}),n()}};V.api("get request")||x.setup.api(),i=e.extend(!0,{},i,y.apiSettings),V.api("setting",i).api("abort").api("query")},filterItems:function(t){var n=t!==i?t:x.get.query(),a=e(),o=x.escape.regExp(n),s=new RegExp("^"+o,"igm");""===n?a=j:(x.verbose("Searching for matching values",n),j.each(function(){var t,i,o=e(this);if("both"==y.match||"text"==y.match){if(t=String(x.get.choiceText(o,!1)),-1!==t.search(s))return a=a.add(o),!0;if(y.fullTextSearch&&x.fuzzySearch(n,t))return a=a.add(o),!0}if("both"==y.match||"value"==y.match){if(i=String(x.get.choiceValue(o,t)),-1!==i.search(s))return a=a.add(o),!0;if(y.fullTextSearch&&x.fuzzySearch(n,i))return a=a.add(o),!0}})),x.debug("Showing only matched items",n),x.remove.filteredItem(),j.not(a).addClass(S.filtered)},fuzzySearch:function(e,t){var n=t.length,i=e.length;if(e=e.toLowerCase(),t=t.toLowerCase(),i>n)return!1;if(i===n)return e===t;e:for(var a=0,o=0;i>a;a++){for(var s=e.charCodeAt(a);n>o;)if(t.charCodeAt(o++)===s)continue e;return!1}return!0},filterActive:function(){y.useLabels&&j.filter("."+S.active).addClass(S.filtered)},focusSearch:function(){x.is.search()&&!x.is.focusedOnSearch()&&F[0].focus()},forceSelection:function(){var e=j.not(S.filtered).filter("."+S.selected).eq(0),t=j.not(S.filtered).filter("."+S.active).eq(0),n=e.length>0?e:t,i=n.size()>0;i?(x.debug("Forcing partial selection to selected item",n),x.event.item.click.call(n)):x.hide()},event:{focus:function(){y.showOnFocus&&!U&&x.is.hidden()&&!g&&x.show()},click:function(t){var n=e(t.target);!n.is(V)&&!n.is(M)||x.is.focusedOnSearch()||x.focusSearch()},blur:function(){g=n.activeElement===this,U||g||(x.remove.activeLabel(),x.hide())},mousedown:function(){U=!0},mouseup:function(){U=!1},search:{focus:function(){U=!0,x.is.multiple()&&x.remove.activeLabel(),y.showOnFocus&&x.show()},blur:function(){g=n.activeElement===this,K||g||(x.is.multiple()?(x.remove.activeLabel(),x.hide()):y.forceSelection?x.forceSelection():x.hide())}},text:{focus:function(){U=!0,x.focusSearch()}},input:function(){(x.is.multiple()||x.is.searchSelection())&&x.set.filtered(),clearTimeout(x.timer),x.timer=setTimeout(x.search,y.delay.search)},label:{click:function(t){var n=e(this),i=V.find(I.label),a=i.filter("."+S.active),o=n.nextAll("."+S.active),s=n.prevAll("."+S.active),r=o.length>0?n.nextUntil(o).add(a).add(n):n.prevUntil(s).add(a).add(n);t.shiftKey?(a.removeClass(S.active),r.addClass(S.active)):t.ctrlKey?n.toggleClass(S.active):(a.removeClass(S.active),n.addClass(S.active)),y.onLabelSelect.apply(this,i.filter("."+S.active))}},remove:{click:function(){var t=e(this).parent();t.hasClass(S.active)?x.remove.labels():x.remove.labels(t)}},test:{toggle:function(e){var t=x.is.multiple()?x.show:x.toggle;x.determine.eventOnElement(e,t)&&e.preventDefault()},touch:function(e){x.determine.eventOnElement(e,function(){"touchstart"==e.type?x.timer=setTimeout(x.hide,y.delay.touch):"touchmove"==e.type&&clearTimeout(x.timer)}),e.stopPropagation()},hide:function(e){x.determine.eventInModule(e,x.hide)}},menu:{mousedown:function(){K=!0},mouseup:function(){K=!1}},item:{mouseenter:function(t){var n=e(this).children(I.menu),i=e(this).siblings(I.item).children(I.menu);n.length>0&&(clearTimeout(x.itemTimer),x.itemTimer=setTimeout(function(){x.verbose("Showing sub-menu",n),e.each(i,function(){x.animate.hide(!1,e(this))}),x.animate.show(!1,n)},y.delay.show),t.preventDefault())},mouseleave:function(){var t=e(this).children(I.menu);t.length>0&&(clearTimeout(x.itemTimer),x.itemTimer=setTimeout(function(){x.verbose("Hiding sub-menu",t),x.animate.hide(!1,t)},y.delay.hide))},click:function(t){var n=e(this),i=e(t?t.target:""),a=n.find(I.menu),o=x.get.choiceText(n),s=x.get.choiceValue(n,o),r=a.length>0,l=a.find(i).length>0;l||r&&!y.allowCategorySelection||x.determine.selectAction.call(this,o,s)}},document:{keydown:function(e){var t=e.which,n=x.get.shortcutKeys(),i=x.is.inObject(t,n);if(i){var a=V.find(I.label),o=a.filter("."+S.active),s=(o.data("value"),a.index(o)),r=a.length,l=o.length>0,c=o.length>1,u=0===s,d=s+1==r,v=x.is.searchSelection(),m=x.is.focusedOnSearch(),f=x.is.focused(),h=m&&0===x.get.caretPosition();if(v&&!l&&!m)return;t==n.leftArrow?!f&&!h||l?l&&(e.shiftKey?x.verbose("Adding previous label to selection"):(x.verbose("Selecting previous label"),a.removeClass(S.active)),u&&!c?o.addClass(S.active):o.prev(I.siblingLabel).addClass(S.active).end(),e.preventDefault()):(x.verbose("Selecting previous label"),a.last().addClass(S.active)):t==n.rightArrow?(f&&!l&&a.first().addClass(S.active),l&&(e.shiftKey?x.verbose("Adding next label to selection"):(x.verbose("Selecting next label"),a.removeClass(S.active)),d?v?m?a.removeClass(S.active):x.focusSearch():c?o.next(I.siblingLabel).addClass(S.active):o.addClass(S.active):o.next(I.siblingLabel).addClass(S.active),e.preventDefault())):t==n.deleteKey||t==n.backspace?l?(x.verbose("Removing active labels"),d&&v&&!m&&x.focusSearch(),o.last().next(I.siblingLabel).addClass(S.active),x.remove.labels(o),e.preventDefault()):h&&!l&&t==n.backspace&&(x.verbose("Removing last label on input backspace"),o=a.last().addClass(S.active),x.remove.labels(o)):o.removeClass(S.active)}}},keydown:function(e){var t=e.which,n=x.get.shortcutKeys(),i=x.is.inObject(t,n);if(i){var a,o,s=j.not(I.unselectable).filter("."+S.selected).eq(0),r=H.children("."+S.active).eq(0),l=s.length>0?s:r,c=l.length>0?l.siblings(":not(."+S.filtered+")").andSelf():H.children(":not(."+S.filtered+")"),u=l.children(I.menu),d=l.closest(I.menu),v=d.hasClass(S.visible)||d.hasClass(S.animating)||d.parent(I.menu).length>0,m=u.length>0,f=l.length>0,h=l.not(I.unselectable).length>0;if(x.is.visible()){if((t==n.enter||t==n.delimiter)&&(t==n.enter&&f&&m&&!y.allowCategorySelection?(x.verbose("Pressed enter on unselectable category, opening sub menu"),t=n.rightArrow):h&&(x.verbose("Selecting item from keyboard shortcut",l),x.event.item.click.call(l,e),y.useLabels&&x.is.searchSelection()?x.hideAndClear():x.remove.searchTerm()),e.preventDefault()),t==n.leftArrow&&(o=d[0]!==H[0],o&&(x.verbose("Left key pressed, closing sub-menu"),x.animate.hide(!1,d),l.removeClass(S.selected),d.closest(I.item).addClass(S.selected),e.preventDefault())),t==n.rightArrow&&m&&(x.verbose("Right key pressed, opening sub-menu"),x.animate.show(!1,u),l.removeClass(S.selected),u.find(I.item).eq(0).addClass(S.selected),e.preventDefault()),t==n.upArrow){if(a=f&&v?l.prevAll(I.item+":not("+I.unselectable+")").eq(0):j.eq(0),c.index(a)<0)return x.verbose("Up key pressed but reached top of current menu"),void e.preventDefault();x.verbose("Up key pressed, changing active item"),l.removeClass(S.selected),a.addClass(S.selected),x.set.scrollPosition(a),e.preventDefault()}if(t==n.downArrow){if(a=f&&v?a=l.nextAll(I.item+":not("+I.unselectable+")").eq(0):j.eq(0),0===a.length)return x.verbose("Down key pressed but reached bottom of current menu"),void e.preventDefault();x.verbose("Down key pressed, changing active item"),j.removeClass(S.selected),a.addClass(S.selected),x.set.scrollPosition(a),e.preventDefault()}t==n.pageUp&&(x.scrollPage("up"),e.preventDefault()),t==n.pageDown&&(x.scrollPage("down"),e.preventDefault()),t==n.escape&&(x.verbose("Escape key pressed, closing dropdown"),x.hide())}else t==n.delimiter&&e.preventDefault(),t==n.downArrow&&(x.verbose("Down key pressed, showing dropdown"),x.show(),e.preventDefault())}else x.is.selection()&&!x.is.search()&&x.set.selectedLetter(String.fromCharCode(t))}},determine:{selectAction:function(t,n){x.verbose("Determining action",y.action),e.isFunction(x.action[y.action])?(x.verbose("Triggering preset action",y.action,t,n),x.action[y.action].call(this,t,n)):e.isFunction(y.action)?(x.verbose("Triggering user action",y.action,t,n),y.action.call(this,t,n)):x.error(L.action,y.action)},eventInModule:function(t,n){return n=e.isFunction(n)?n:function(){},0===e(t.target).closest(V).length?(x.verbose("Triggering event",n),n(),!0):(x.verbose("Event occurred in dropdown, canceling callback"),!1)},eventOnElement:function(t,n){var i=e(t.target);return n=e.isFunction(n)?n:function(){},0===i.closest(H).length?(x.verbose("Triggering event",n),n(),!0):(x.verbose("Event occurred in dropdown menu, canceling callback"),!1)}},action:{nothing:function(){},activate:function(t,n){n=n!==i?n:t,x.set.selected(n,e(this)),(!x.is.multiple()||x.is.allFiltered())&&x.hideAndClear()},select:function(){x.action.activate.call(this)},combo:function(t,n){n=n!==i?n:t,x.set.selected(n,e(this)),x.hideAndClear()},hide:function(){x.hideAndClear()}},get:{id:function(){return p},text:function(){return O.text()},query:function(){return e.trim(F.val())},searchWidth:function(e){return e*y.glyphWidth+"em"},selectionCount:function(){var t=x.get.values();return x.is.multiple()?e.isArray(t)?t.length:0:""!==x.get.value()?1:0},transition:function(e){return"auto"==y.transition?x.is.upward(e)?"slide up":"slide down":y.transition},userValues:function(){var t=x.get.values();return t?e.grep(t,function(e){return x.get.item(e)===!1}):!1},uniqueArray:function(t){return e.grep(t,function(n,i){return e.inArray(n,t)===i})},caretPosition:function(){var e,t,i=F.get(0);return"selectionStart"in i?i.selectionStart:n.selection?(i.focus(),e=n.selection.createRange(),t=e.text.length,e.moveStart("character",-i.value.length),e.text.length-t):void 0},shortcutKeys:function(){return{backspace:8,delimiter:188,deleteKey:46,enter:13,escape:27,pageUp:33,pageDown:34,leftArrow:37,upArrow:38,rightArrow:39,downArrow:40}},value:function(){return P.length>0?P.val():V.data(A.value)},values:function(){var e=x.get.value();return""===e?"":!P.is("select")&&x.is.multiple()?"string"==typeof e?e.split(y.delimiter):"":e},remoteValues:function(){var t=x.get.values(),n=!1;return t&&("string"==typeof t&&(t=[t]),n={},e.each(t,function(e,t){var i=x.read.remoteData(t);n[t]=i?i:t})),n},choiceText:function(e,t){return t=t!==i?t:y.preserveHTML,e?(e.find(I.menu).length>0&&(x.verbose("Retreiving text of element with sub-menu"),e=e.clone(),e.find(I.menu).remove(),e.find(I.menuIcon).remove()),e.data(A.text)!==i?e.data(A.text):t?e.html().trim():e.text().trim()):void 0},choiceValue:function(e,t){return t=t||x.get.choiceText(e),e?e.data(A.value)!==i?e.data(A.value):"string"==typeof t?t.toLowerCase().trim():t:!1},inputEvent:function(){var e=F[0];return e?e.oninput!==i?"input":e.onpropertychange!==i?"propertychange":"keyup":!1},selectValues:function(){var t={};return t.values=[],V.find("option").each(function(){var n=e(this).html(),a=e(this).attr("value")!==i?e(this).attr("value"):n;"auto"===y.placeholder&&""===a?t.placeholder=n:t.values.push({name:n,value:a})}),y.placeholder&&"auto"!==y.placeholder&&(x.debug("Setting placeholder value to",y.placeholder),t.placeholder=y.placeholder),y.sortSelect?(t.values.sort(function(e,t){return e.name>t.name?1:-1}),x.debug("Retrieved and sorted values from select",t)):x.debug("Retreived values from select",t),t},activeItem:function(){return j.filter("."+S.active)},selectedItem:function(){var e=j.not(I.unselectable).filter("."+S.selected);return e.length>0?e:j.eq(0)},item:function(t,n){var a,o=!1;return t=t!==i?t:x.get.values()!==i?x.get.values():x.get.text(),a=x.is.multiple()&&e.isArray(t),n=""===t||0===t?!0:n||!1,t!==i&&j.each(function(){var i=e(this),s=x.get.choiceText(i),r=x.get.choiceValue(i,s);if(a)(-1!==e.inArray(r.toString(),t)||-1!==e.inArray(s,t))&&(o=o?o.add(i):i);else if(n){if(x.verbose("Ambiguous dropdown value using strict type check",i,t),r===t||s===t)return o=i,!0}else if(r==t||s==t)return x.verbose("Found select item by value",r,t),o=i,!0}),o}},check:{maxSelections:function(e){return y.maxSelections?(e=e!==i?e:x.get.selectionCount(),e>=y.maxSelections?(x.debug("Maximum selection count reached"),j.addClass(S.filtered),x.add.message(T.maxSelections),!0):(x.verbose("No longer at maximum selection count"),x.remove.message(),x.remove.filteredItem(),x.is.searchSelection()&&x.filterItems(),!1)):!0}},restore:{defaults:function(){x.restore.defaultText(),x.restore.defaultValue()},defaultText:function(){var e=V.data(A.defaultText);x.debug("Restoring default text",e),x.set.text(e),O.addClass(S.placeholder)},defaultValue:function(){var e=V.data(A.defaultValue);e!==i&&(x.debug("Restoring default value",e),e.length?x.set.selected(e):(x.remove.activeItem(),x.remove.selectedItem()))},labels:function(){y.allowAdditions&&(y.useLabels||(x.error(L.labels),y.useLabels=!0),x.debug("Restoring selected values"),x.create.userLabels()),x.check.maxSelections()},values:function(){x.debug("Restoring selected values"),y.fireOnInit===!1&&(h=!0),y.apiSettings?y.saveRemoteData?x.restore.remoteValues():x.clearValue():x.set.selected(),y.fireOnInit===!1&&(h=!1)},remoteValues:function(){var t=x.get.remoteValues();x.debug("Recreating selected from session data",t),t&&(x.is.single()?e.each(t,function(e,t){x.set.text(t)}):e.each(t,function(e,t){x.add.label(e,t)}))}},read:{remoteData:function(e){var n;return t.Storage===i?void x.error(L.noStorage):(n=sessionStorage.getItem(e),n!==i?n:!1)}},save:{defaults:function(){x.save.defaultText(),x.save.placeholderText(),x.save.defaultValue()},defaultValue:function(){V.data(A.defaultValue,x.get.value())},defaultText:function(){V.data(A.defaultText,O.text())},placeholderText:function(){O.hasClass(S.placeholder)&&V.data(A.placeholderText,O.text())},remoteData:function(e,n){return t.Storage===i?void x.error(L.noStorage):void sessionStorage.setItem(n,e)}},clear:function(){x.set.placeholderText(),x.clearValue(),x.remove.activeItem(),x.remove.selectedItem()},clearValue:function(){x.set.value("")},scrollPage:function(e,t){var n,i,a,t=t||x.get.selectedItem(),o=t.closest(I.menu),s=o.outerHeight(),r=o.scrollTop(),l=j.eq(0).outerHeight(),c=Math.floor(s/l),u=(o.prop("scrollHeight"),"up"==e?r-l*c:r+l*c),d=j.not(I.unselectable);a="up"==e?d.index(t)-c:d.index(t)+c,n="up"==e?a>=0:a<d.length,i=n?d.eq(a):"up"==e?d.first():d.last(),i.length>0&&(x.debug("Scrolling page",e,i),t.removeClass(S.selected),i.addClass(S.selected),o.scrollTop(u))},set:{filtered:function(){var e=x.is.multiple(),t=x.is.searchSelection(),n=e&&t,i=t?x.get.query():"",a="string"==typeof i&&i.length>0,o=x.get.searchWidth(i.length),s=""!==i;e&&a&&(x.verbose("Adjusting input width",o,y.glyphWidth),F.css("width",o)),a||n&&s?(x.verbose("Hiding placeholder text"),O.addClass(S.filtered)):(!e||n&&!s)&&(x.verbose("Showing placeholder text"),O.removeClass(S.filtered))},loading:function(){V.addClass(S.loading)},placeholderText:function(e){x.debug("Restoring placeholder text"),e=e||V.data(A.placeholderText),x.set.text(e),O.addClass(S.placeholder)},input:function(){},tabbable:function(){x.has.search()?(x.debug("Added tabindex to searchable dropdown"),F.val("").attr("tabindex",0),H.attr("tabindex",-1)):(x.debug("Added tabindex to dropdown"),V.attr("tabindex")||(V.attr("tabindex",0),H.attr("tabindex",-1)))},scrollPosition:function(e,t){var n,a,o,s,r,l,c,u,d,v=5;e=e||x.get.selectedItem(),n=e.closest(I.menu),a=e&&e.length>0,t=t!==i?t:!1,e&&n.length>0&&a&&(s=e.position().top,n.addClass(S.loading),l=n.scrollTop(),r=n.offset().top,s=e.offset().top,o=l-r+s,t||(c=n.height(),d=o+v>l+c,u=l>o-v),x.debug("Scrolling to active item",o),(t||u||d)&&n.scrollTop(o),n.removeClass(S.loading))},text:function(e){"select"!==y.action&&("combo"==y.action?(x.debug("Changing combo button text",e,z),y.preserveHTML?z.html(e):z.text(e)):(x.debug("Changing text",e,O),O.removeClass(S.filtered).removeClass(S.placeholder),y.preserveHTML?O.html(e):O.text(e)))},selectedLetter:function(t){var n=j.filter("."+S.selected),i=!1;j.each(function(){var n=e(this),a=x.get.choiceText(n,!1),o=String(a).charAt(0).toLowerCase(),s=t.toLowerCase();return o==s?(i=n,!1):void 0}),i&&(x.verbose("Scrolling to next value with letter",t),x.set.scrollPosition(i),n.removeClass(S.selected),i.addClass(S.selected))},upward:function(e){var t=e||V;t.addClass(S.upward)},value:function(e,t,n){var i=P.length>0,a=(!x.has.value(e),x.get.values());if(i){if(e==a)return void x.verbose("Skipping value update already same value",e,a);x.debug("Updating input value",e,a),P.val(e).trigger("change")}else x.verbose("Storing value in metadata",e,P),e!==a&&V.data(A.value,e);h||y.onChange.call(N,e,t,n)},active:function(){V.addClass(S.active)},multiple:function(){V.addClass(S.multiple)},visible:function(){V.addClass(S.visible)},selected:function(t,n){var i=x.is.multiple();return(n=n||x.get.item(t))?(x.debug("Setting selected menu item to",n),x.is.single()?(x.remove.activeItem(),x.remove.selectedItem()):y.useLabels&&x.remove.selectedItem(),void n.each(function(){var t=e(this),a=x.get.choiceText(t),o=x.get.choiceValue(t,a),s=t.hasClass(S.filtered),r=t.hasClass(S.active),l=t.hasClass(S.addition),c=i&&1==n.length;i?!r||l?(y.apiSettings&&y.saveRemoteData&&x.save.remoteData(a,o),y.useLabels?(x.add.value(o,a,t),x.add.label(o,a,c),t.addClass(S.active),x.filterActive(),x.select.nextAvailable(n)):(x.add.value(o,a,t),x.set.text(x.add.variables(T.count)),t.addClass(S.active))):s||(x.debug("Selected active value, removing label"),x.remove.selected(o)):(x.set.value(o,a,t),x.set.text(a),t.addClass(S.active).addClass(S.selected))})):!1}},add:{label:function(t,n,i){var a,o=x.is.searchSelection()?F:O;return a=e("<a />").addClass(S.label).attr("data-value",t).html(q.label(t,n)),a=y.onLabelCreate.call(a,t,n),x.has.label(t)?void x.debug("Label already exists, skipping",t):(y.label.variation&&a.addClass(y.label.variation),void(i===!0?(x.debug("Animating in label",a),a.addClass(S.hidden).insertBefore(o).transition(y.label.transition,y.label.duration)):(x.debug("Adding selection label",a),a.insertBefore(o))))},message:function(t){var n=H.children(I.message),i=y.templates.message(x.add.variables(t));n.length>0?n.html(i):n=e("<div/>").html(i).addClass(S.message).appendTo(H)},optionValue:function(t){var n=P.find('option[value="'+t+'"]'),i=n.length>0;i||(w&&(w.disconnect(),x.verbose("Temporarily disconnecting mutation observer",t)),e("<option/>").prop("value",t).html(t).appendTo(P),x.verbose("Adding user addition as an <option>",t),w&&w.observe(P[0],{childList:!0,subtree:!0}))},userChoice:function(t){var n,i=x.get.item(t),a=H.children(I.addition);if(!x.has.maxSelections()){if(""===t||i)return void a.remove();n=y.templates.addition(t),j.removeClass(S.selected),a.length>0?a.html(n).data(A.value,t).removeClass(S.filtered).addClass(S.selected):a=e("<div/>").html(n).data(A.value,t).addClass(S.addition).addClass(S.item).prependTo(H).addClass(S.selected)}},variables:function(e){var t,n,i=-1!==e.search("{count}"),a=-1!==e.search("{maxCount}"),o=-1!==e.search("{term}");return i&&(t=x.get.selectionCount(),e=e.replace("{count}",t)),a&&(t=x.get.selectionCount(),e=e.replace("{maxCount}",y.maxSelections)),o&&(n=x.get.query(),e=e.replace("{term}",n)),e},value:function(t,n,i){var a,o=x.get.values();return""===t?void x.debug("Cannot select blank values from multiselect"):(e.isArray(o)?(a=o.concat([t]),a=x.get.uniqueArray(a)):a=[t],P.is("select")?y.allowAdditions&&(x.add.optionValue(t),x.debug("Adding value to select",t,a,P)):(a=a.join(y.delimiter),x.debug("Setting hidden input to delimited value",a,P)),h||y.onAdd.call(N,t,n,i),x.set.value(a,t,n,i),void x.check.maxSelections())}},remove:{active:function(){V.removeClass(S.active)},activeLabel:function(){V.find(I.label).removeClass(S.active)},loading:function(){V.removeClass(S.loading)},upward:function(e){var t=e||V;t.removeClass(S.upward)},visible:function(){V.removeClass(S.visible)},activeItem:function(){j.removeClass(S.active)},filteredItem:function(){x.has.maxSelections()||(y.useLabels?j.not("."+S.active).removeClass(S.filtered):j.removeClass(S.filtered))},message:function(){H.children(I.message).remove()},searchTerm:function(){x.verbose("Cleared search term"),F.val(""),x.set.filtered()},selected:function(e){var t=x.get.item(e),n=x.get.choiceText(t),i=x.get.choiceValue(t,n);return t?(x.is.multiple()?y.useLabels?(x.remove.value(i,n,t),x.remove.label(i)):(x.remove.value(i,n,t),x.set.text(x.add.variables(T.count))):x.remove.value(i,n,t),t.removeClass(S.filtered).removeClass(S.active),void(y.useLabels&&t.removeClass(S.selected))):!1},selectedItem:function(){j.removeClass(S.selected)},value:function(e,t,n){var i,a=P.val();P.is("select")?(x.verbose("Input is <select> removing selected option",e),i=x.remove.arrayValue(e,a)):(x.verbose("Removing from delimited values",e),a=a.split(y.delimiter),i=x.remove.arrayValue(e,a),i=i.join(y.delimiter)),h||y.onRemove.call(N,e,t,n),x.set.value(i,t,n)},arrayValue:function(t,n){return n=e.grep(n,function(e){return t!=e}),x.verbose("Removed value from delimited string",t,n),n},label:function(e){var t=V.find(I.label),n=t.filter('[data-value="'+e+'"]'),i=t.length,a=t.index(n)+1==i,o=(!x.is.searchSelection()||!x.is.focusedOnSearch())&&a;o?(x.verbose("Animating and removing label",n),n.transition(y.label.transition,y.label.duration,function(){n.remove()})):(x.verbose("Removing label",n),n.remove())},labels:function(t){t=t||V.find(I.label).filter("."+S.active),x.verbose("Removing active label selections",t),t.each(function(){var t=e(this).data("value"),n=x.is.userValue(t);n?(x.remove.value(t),x.remove.label(t)):x.remove.selected(t)})},tabbable:function(){x.has.search()?(x.debug("Searchable dropdown initialized"),F.attr("tabindex","-1"),H.attr("tabindex","-1")):(x.debug("Simple selection dropdown initialized"),V.attr("tabindex","-1"),H.attr("tabindex","-1"))}},has:{search:function(){return F.length>0},input:function(){return P.length>0},menu:function(){return H.length>0},message:function(){return 0!==H.children(I.message).length},label:function(e){var t=V.find(I.label);return t.filter('[data-value="'+e+'"]').length>0},maxSelections:function(){return y.maxSelections&&x.get.selectionCount()>=y.maxSelections},allResultsFiltered:function(){return j.filter(I.unselectable).length===j.length},value:function(t){var n=x.get.values(),i=e.isArray(n)?n&&-1!==e.inArray(t,n):n==t;return i?!0:!1}},is:{active:function(){return V.hasClass(S.active)},alreadySetup:function(){return V.is("select")&&V.parent(I.dropdown).length>0&&0===V.prev().length},animating:function(e){return e?e.transition&&e.transition("is animating"):H.transition&&H.transition("is animating")},focused:function(){return n.activeElement===V[0]},focusedOnSearch:function(){return n.activeElement===F[0]},allFiltered:function(){return(x.is.multiple()||x.has.search())&&!x.has.message()&&x.has.allResultsFiltered()},hidden:function(e){return!x.is.visible(e)},onScreen:function(n){var a,o=n||H;return o.addClass(S.loading),a=e.fn.visibility!==i?o.visibility("bottom visible"):e(t).scrollTop()+e(t).height()>=o.offset().top+o.height(),x.debug("Checking if menu can fit on screen",a,H),o.removeClass(S.loading),a},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 V.hasClass(S.multiple)},single:function(){return!x.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 V.hasClass(S.search)},searchSelection:function(){return x.has.search()&&0===F.closest(I.menu).length},selection:function(){return V.hasClass(S.selection)},userValue:function(t){return-1!==e.inArray(t,x.get.userValues())},upward:function(e){var t=e||V;return t.hasClass(S.upward)},visible:function(e){return e?e.hasClass(S.visible):H.hasClass(S.visible)}},can:{click:function(){return c||"click"==y.on},show:function(){return!V.hasClass(S.disabled)&&j.length>0},useAPI:function(){return e.fn.api!==i}},animate:{show:function(t,n){var a,o=n||H,s=n?function(){}:function(){x.hideSubMenus(),x.hideOthers(),x.set.active()};t=e.isFunction(t)?t:function(){},x.verbose("Doing menu show animation",o),y.keepOnScreen&&(x.is.onScreen(n)?x.remove.upward(n):x.set.upward(n)),a=x.get.transition(n),x.is.selection()&&x.set.scrollPosition(x.get.selectedItem(),!0),(x.is.hidden(o)||x.is.animating(o))&&("none"==a?(s(),o.transition("show"),t.call(N)):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(N)}}):x.error(L.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(N)):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(){x.remove.upward(n),t.call(N)}}):x.error(L.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(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(){},onAdd:function(){},onRemove:function(){},onLabelSelect:function(){},onLabelCreate:function(){return e(this)},onNoResults:function(){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:"placeholder",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)",unselectable:".disabled, .filtered"},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.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);
|