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.
11 lines
29 KiB
11 lines
29 KiB
/*!
|
|
* # Semantic UI 2.0.0 - Dropdown
|
|
* http://github.com/semantic-org/semantic-ui/
|
|
*
|
|
*
|
|
* Copyright 2014 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,l=e(this),r=e(n),s=l.selector||"",c="ontouchstart"in n.documentElement,d=(new Date).getTime(),u=[],v=arguments[0],f="string"==typeof v,h=[].slice.call(arguments,1);return l.each(function(){var m,g,p,b,w,x=e.isPlainObject(o)?e.extend(!0,{},e.fn.dropdown.settings,o):e.extend({},e.fn.dropdown.settings),C=x.className,y=x.metadata,S=x.namespace,T=x.selector,k=x.error,A=x.templates,D="."+S,E="module-"+S,I=e(this),O=I.find(T.text),F=I.find(T.search),q=I.find(T.input),V=I.find(T.icon),L=I.prev().find(T.text).length>0?I.prev().find(T.text):I.prev(),M=I.children(T.menu),R=M.find(T.item),P=!1,z=!1,j=this,H=I.data(E);w={initialize:function(){w.debug("Initializing dropdown",x),w.is.alreadySetup()?w.setup.reference():(w.setup.layout(),w.save.defaults(),w.set.selected(),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),H=w,I.data(E,w)},destroy:function(){w.verbose("Destroying previous dropdown for",I),w.remove.tabbable(),I.off(D).removeData(E),M.off(D),r.off(m),p&&p.disconnect(),b&&b.disconnect()},observeChanges:function(){"MutationObserver"in t&&(p=new MutationObserver(function(){w.debug("<select> modified, recreating menu"),w.setup.select()}),b=new MutationObserver(function(){w.debug("Menu modified, updating selector cache"),w.refresh()}),w.has.input()&&p.observe(q[0],{childList:!0,subtree:!0}),w.has.menu()&&b.observe(M[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),m="."+g,w.verbose("Creating unique id for element",g)}},search:function(){var e;e=F.val(),w.verbose("Searching for query",e),w.filter(e),w.is.searchSelection()&&w.can.show()&&w.show()},select:{firstUnfiltered:function(){w.remove.selectedItem(),R.not("."+C.filtered).eq(0).addClass(C.selected)},nextAvailable:function(e){e=e.eq(0);var t=e.nextAll(T.item).not("."+C.filtered).eq(0),n=e.prevAll(T.item).not("."+C.filtered).eq(0),i=t.length>0;i?(w.verbose("Moving selection to",t),t.addClass(C.selected)):(w.verbose("Moving selection to",n),n.addClass(C.selected))}},setup:{layout:function(){I.is("select")&&w.setup.select(),w.is.search()&&!w.has.search()&&(F=e("<input />").addClass(C.search).insertBefore(O)),x.allowTab&&w.set.tabbable()},select:function(){var t=w.get.selectValues();w.debug("Dropdown initialized on a select",t),I.is("select")&&(q=I),q.parent(T.dropdown).length>0?(w.debug("UI dropdown already exists. Creating dropdown menu only"),I=q.closest(T.dropdown),M=I.children(T.menu),0===M.length&&(M=e("<div />").addClass(C.menu).appendTo(I)),M.html(A.menu(t))):(w.debug("Creating entire dropdown from select"),I=e("<div />").attr("class",q.attr("class")).addClass(C.selection).addClass(C.dropdown).html(A.dropdown(t)).insertBefore(q),q.removeAttr("class").detach().prependTo(I)),q.is("[multiple]")&&w.set.multiple(),w.refresh()},reference:function(){var e,t,n=l.index(I);w.debug("Dropdown behavior was called on select, replacing with closest dropdown"),I=I.parent(T.dropdown),w.refresh(),e=l.slice(0,n),t=l.slice(n+1),l=e.add(I).add(t),f&&(H=w,w.invoke(v))}},refresh:function(){w.verbose("Refreshing selector cache"),O=I.find(T.text),F=I.find(T.search),q=I.find(T.input),V=I.find(T.icon),L=I.prev().find(T.text).length>0?I.prev().find(T.text):I.prev(),M=I.children(T.menu),R=M.find(T.item)},toggle:function(){w.verbose("Toggling menu visibility"),w.is.active()?w.hide():w.show()},show:function(t){t=e.isFunction(t)?t:function(){},w.is.searchSelection()&&w.is.allFiltered()||w.can.show()&&!w.is.active()&&(w.debug("Showing dropdown"),w.is.multiple()&&w.is.searchSelection()&&w.filterActive(),w.animate.show(function(){w.can.click()&&w.bind.intent(),w.set.visible(),t.call(j)}),x.onShow.call(j))},hide:function(t){t=e.isFunction(t)?t:function(){},w.is.active()&&(w.debug("Hiding dropdown"),w.animate.hide(function(){w.remove.visible(),t.call(j)}),x.onHide.call(j))},hideOthers:function(){w.verbose("Finding other dropdowns to hide"),l.not(I).has(T.menu+":visible:not(."+C.animating+")").dropdown("hide")},hideMenu:function(){w.verbose("Hiding menu instantaneously"),w.remove.active(),w.remove.visible(),M.transition("hide")},hideSubMenus:function(){var e=M.children(T.item).find(T.menu);w.verbose("Hiding sub menus",e),e.transition("hide")},bind:{keyboardEvents:function(){w.debug("Binding keyboard events"),I.on("keydown"+D,w.event.keydown),w.has.search()&&I.on(w.get.inputEvent()+D,T.search,w.event.input),w.is.multiple()&&r.on("keydown"+m,w.event.document.keydown)},touchEvents:function(){w.debug("Touch device detected binding additional touch events"),w.is.searchSelection()||I.on("touchstart"+D,w.event.test.toggle),M.on("touchstart"+D,T.item,w.event.item.mouseenter)},mouseEvents:function(){w.verbose("Mouse detected binding mouse events"),w.is.multiple()&&I.on("click"+D,T.label,w.event.label.click).on("click"+D,T.remove,w.event.remove.click),w.is.searchSelection()?(I.on("mousedown"+D,T.menu,w.event.menu.mousedown).on("mouseup"+D,T.menu,w.event.menu.mouseup).on("click"+D,T.search,w.show).on("focus"+D,T.search,w.event.search.focus).on("blur"+D,T.search,w.event.search.blur).on("click"+D,T.text,w.event.text.focus),w.is.multiple()&&I.on("click"+D,w.event.click)):("click"==x.on?I.on("click"+D,w.event.test.toggle):"hover"==x.on?I.on("mouseenter"+D,w.delay.show).on("mouseleave"+D,w.delay.hide):I.on(x.on+D,w.toggle),I.on("mousedown"+D,w.event.mousedown).on("mouseup"+D,w.event.mouseup).on("focus"+D,w.event.focus).on("blur"+D,w.event.blur)),M.on("mouseenter"+D,T.item,w.event.item.mouseenter).on("mouseleave"+D,T.item,w.event.item.mouseleave).on("click"+D,T.item,w.event.item.click)},intent:function(){w.verbose("Binding hide intent event to document"),c&&r.on("touchstart"+m,w.event.test.touch).on("touchmove"+m,w.event.test.touch),r.on("click"+m,w.event.test.hide)}},unbind:{intent:function(){w.verbose("Removing hide intent event from document"),c&&r.off("touchstart"+m).off("touchmove"+m),r.off("click"+m)}},filter:function(t){var n=e(),i=w.escape.regExp(t),o=new RegExp("^"+i,"igm"),a=new RegExp(i,"ig");w.verbose("Searching for matching values"),R.each(function(){var t,i,l=e(this);if("both"==x.match||"text"==x.match){if(t=String(w.get.choiceText(l,!1)),t.match(o))return n=n.add(l),!0;if(x.fullTextSearch&&t.match(a))return n=n.add(l),!0}if("both"==x.match||"value"==x.match){if(i=String(w.get.choiceValue(l,t)),i.match(o))return n=n.add(l),!0;if(x.fullTextSearch&&i.match(a))return n=n.add(l),!0}}),w.debug("Setting filter",t),w.remove.filteredItem(),R.not(n).addClass(C.filtered),w.is.multiple()&&w.filterActive(),w.verbose("Selecting first non-filtered element"),w.select.firstUnfiltered(),w.is.allFiltered()&&(w.debug("All items filtered, hiding dropdown",t),w.is.searchSelection()&&w.hideMenu(),x.onNoResults.call(j,t))},filterActive:function(){x.hideSelections&&R.filter("."+C.active).addClass(C.filtered)},focusSearch:function(){w.is.search()&&!w.is.focusedOnSearch()&&F[0].focus()},forceSelection:function(){var e=R.not(C.filtered).filter("."+C.selected).eq(0),t=R.not(C.filtered).filter("."+C.active).eq(0),n=e.length>0?e:t,i=n.size()>0;i?(w.debug("Forcing partial selection to selected item",n),w.event.item.click.call(n),w.remove.filteredItem()):w.hide()},event:{focus:function(){x.showOnFocus&&!P&&w.is.hidden()&&w.show()},click:function(t){var n=e(t.target);!n.is(I)&&!n.is(V)||w.is.focusedOnSearch()||F.focus()},blur:function(){var e=n.activeElement===this;P||e||(w.remove.activeLabel(),w.hide())},mousedown:function(){P=!0},mouseup:function(){P=!1},search:{focus:function(){P=!0,w.is.multiple()&&w.remove.activeLabel(),x.showOnFocus&&w.show()},blur:function(){var e=n.activeElement===this;z||e||(w.is.multiple()?w.remove.activeLabel():x.forceSelection?w.forceSelection():w.hide())}},text:{focus:function(){P=!0,F.focus()}},input:function(){(w.is.multiple()||w.is.searchSelection())&&w.set.filtered(),clearTimeout(w.timer),w.timer=setTimeout(w.search,x.delay.search)},label:{click:function(t){var n=e(this),i=I.find(T.label),o=i.filter("."+C.active),a=n.nextAll("."+C.active),l=n.prevAll("."+C.active),r=a.length>0?n.nextUntil(a).add(o).add(n):n.prevUntil(l).add(o).add(n);t.shiftKey?(o.removeClass(C.active),r.addClass(C.active)):t.ctrlKey?n.toggleClass(C.active):(o.removeClass(C.active),n.addClass(C.active)),x.onLabelSelect.apply(this,i.filter("."+C.active))}},remove:{click:function(){var t=e(this).parent();t.hasClass(C.active)?w.remove.labels():w.remove.labels(t)}},test:{toggle:function(e){var t=w.is.multiple()?w.show:w.toggle;w.determine.eventOnElement(e,t)&&e.preventDefault()},touch:function(e){w.determine.eventOnElement(e,function(){"touchstart"==e.type?w.timer=setTimeout(w.hide,x.delay.touch):"touchmove"==e.type&&clearTimeout(w.timer)}),e.stopPropagation()},hide:function(e){w.determine.eventInModule(e,w.hide)}},menu:{mousedown:function(){z=!0},mouseup:function(){z=!1}},item:{mouseenter:function(t){var n=e(this).children(T.menu),i=e(this).siblings(T.item).children(T.menu);n.length>0&&(clearTimeout(w.itemTimer),w.itemTimer=setTimeout(function(){w.verbose("Showing sub-menu",n),e.each(i,function(){w.animate.hide(!1,e(this))}),w.animate.show(!1,n)},x.delay.show),t.preventDefault())},mouseleave:function(){var t=e(this).children(T.menu);t.length>0&&(clearTimeout(w.itemTimer),w.itemTimer=setTimeout(function(){w.verbose("Hiding sub-menu",t),w.animate.hide(!1,t)},x.delay.hide))},click:function(t){var n=e(this),i=e(t?t.target:""),o=n.find(T.menu),a=w.get.choiceText(n),l=w.get.choiceValue(n,a),r=o.length>0,s=o.find(i).length>0;s||r&&!x.allowCategorySelection||w.determine.selectAction.call(this,a,l)}},document:{keydown:function(e){var t=e.which,n=w.get.shortcutKeys(),i=w.is.inObject(t,n);if(i){var o=I.find(T.label),a=o.filter("."+C.active),l=a.data("value"),r=o.index(a),s=o.length,c=a.length>0,d=a.length>1,u=0==r,v=r+1==s,f=w.is.searchSelection(),h=w.is.focusedOnSearch(),m=w.is.focused(),g=h&&0==w.get.caretPosition();h&&t==n.delimiter?w.is.visible()&&(w.verbose("Delimiter key pressed. Tokenizing"),e.preventDefault()):t==n.leftArrow?!m&&!g||c?c&&(e.shiftKey?w.verbose("Adding previous label to selection"):(w.verbose("Selecting previous label"),o.removeClass(C.active)),u&&!d?a.addClass(C.active):a.prev(T.siblingLabel).addClass(C.active).end(),e.preventDefault()):(w.verbose("Selecting previous label"),o.last().addClass(C.active)):t==n.rightArrow?(m&&!c&&o.first().addClass(C.active),c&&(e.shiftKey?w.verbose("Adding next label to selection"):(w.verbose("Selecting next label"),o.removeClass(C.active)),v?f&&!h?w.focusSearch():d?a.next(T.siblingLabel).addClass(C.active):a.addClass(C.active):a.next(T.siblingLabel).addClass(C.active),e.preventDefault())):t==n.deleteKey||t==n.backspace?c?(w.verbose("Removing active labels"),v&&f&&!h&&w.focusSearch(),a.last().next(T.siblingLabel).addClass(C.active),w.remove.labels(a),e.preventDefault()):g&&!c&&t==n.backspace&&(w.verbose("Removing last label on input backspace"),a=o.last().addClass(C.active),l=a.data("value"),w.remove.selected(l),e.preventDefault()):a.removeClass(C.active)}}},keydown:function(e){var t=e.which,n=w.get.shortcutKeys(),i=w.is.inObject(t,n);if(i){var o,a,l=R.not("."+C.filtered).filter("."+C.selected).eq(0),r=M.children("."+C.active).eq(0),s=l.length>0?l:r,c=s.length>0?s.siblings(":not(."+C.filtered+")").andSelf():M.children(":not(."+C.filtered+")"),d=s.children(T.menu),u=s.closest(T.menu),v=u.hasClass(C.visible)||u.hasClass(C.animating),f=d.length>0,h=s.length>0,m=s.not("."+T.filtered).length>0;if(w.is.visible()){if(t==n.enter&&h&&(f&&!x.allowCategorySelection?(w.verbose("Pressed enter on unselectable category, opening sub menu"),t=n.rightArrow):m&&(w.verbose("Enter key pressed, choosing selected item"),w.event.item.click.call(s,e),e.stopImmediatePropagation()),e.preventDefault()),t==n.leftArrow&&(a=u[0]!==M[0],a&&(w.verbose("Left key pressed, closing sub-menu"),w.animate.hide(!1,u),s.removeClass(C.selected),u.closest(T.item).addClass(C.selected),e.preventDefault())),t==n.rightArrow&&f&&(w.verbose("Right key pressed, opening sub-menu"),w.animate.show(!1,d),s.removeClass(C.selected),d.find(T.item).eq(0).addClass(C.selected),e.preventDefault()),t==n.upArrow){if(o=h&&v?s.prevAll(T.item+":not(."+C.filtered+")").eq(0):R.eq(0),c.index(o)<0)return w.verbose("Up key pressed but reached top of current menu"),void e.preventDefault();w.verbose("Up key pressed, changing active item"),s.removeClass(C.selected),o.addClass(C.selected),w.set.scrollPosition(o),e.preventDefault()}if(t==n.downArrow){if(o=h&&v?o=s.nextAll(T.item+":not(."+C.filtered+")").eq(0):R.eq(0),0===o.length)return w.verbose("Down key pressed but reached bottom of current menu"),void e.preventDefault();w.verbose("Down key pressed, changing active item"),R.removeClass(C.selected),o.addClass(C.selected),w.set.scrollPosition(o),e.preventDefault()}t==n.escape&&(w.verbose("Escape key pressed, closing dropdown"),w.hide())}else t==n.enter&&(w.verbose("Enter key pressed, showing dropdown"),w.show(),e.preventDefault()),t==n.downArrow&&(w.verbose("Down key pressed, showing dropdown"),w.show(),e.preventDefault())}}},determine:{selectAction:function(t,n){w.verbose("Determining action",x.action),e.isFunction(w.action[x.action])?(w.verbose("Triggering preset action",x.action,t,n),w.action[x.action].call(this,t,n)):e.isFunction(x.action)?(w.verbose("Triggering user action",x.action,t,n),x.action.call(this,t,n)):w.error(k.action,x.action)},eventInModule:function(t,n){return n=e.isFunction(n)?n:function(){},0===e(t.target).closest(I).length?(w.verbose("Triggering event",n),n(),!0):(w.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(M).length?(w.verbose("Triggering event",n),n(),!0):(w.verbose("Event occurred in dropdown menu, canceling callback"),!1)}},action:{nothing:function(){},activate:function(t,n){n=n!==i?n:t,w.set.selected(n,e(this)),(!w.is.multiple()||w.is.allFiltered())&&w.hideAndClear()},select:function(){w.action.activate.call(this)},combo:function(t,n){n=n!==i?n:t,w.set.selected(n,e(this)),w.hideAndClear()},hide:function(){w.hideAndClear()}},get:{id:function(){return g},text:function(){return O.text()},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,leftArrow:37,upArrow:38,rightArrow:39,downArrow:40}},value:function(){return q.length>0?q.val():I.data(y.value)},values:function(){var e=w.get.value();return""==e?"":!q.is("select")&&w.is.multiple()?e.split(x.delimiter):e},choiceText:function(e,t){return t=t!==i?t:x.preserveHTML,e?(e.find(T.menu).length>0&&(w.verbose("Retreiving text of element with sub-menu"),e=e.clone(),e.find(T.menu).remove(),e.find(T.menuIcon).remove()),e.data(y.text)!==i?e.data(y.text):t?e.html().trim():e.text().trim()):void 0},choiceValue:function(e,t){return t=t||w.get.choiceText(e),e?e.data(y.value)!==i?e.data(y.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=x.sortSelect?{}:[],I.find("option").each(function(){var n=e(this).html(),o=e(this).attr("value")!==i?e(this).attr("value"):n;"auto"===x.placeholder&&""===o?t.placeholder=n:x.sortSelect?t.values[o]={name:n,value:o}:t.values.push({name:n,value:o})}),x.placeholder&&"auto"!==x.placeholder&&(w.debug("Setting placeholder value to",x.placeholder),t.placeholder=x.placeholder),x.sortSelect?w.debug("Retrieved and sorted values from select",t):w.debug("Retreived values from select",t),t},activeItem:function(){return R.filter("."+C.active)},item:function(t,n){var o,a=!1;return t=t!==i?t:w.get.values()!==i?w.get.values():w.get.text(),o=w.is.multiple()&&e.isArray(t),n=""===t||0===t?!0:n||!1,t!==i&&R.each(function(){var i=e(this),l=w.get.choiceText(i),r=w.get.choiceValue(i,l);if(o)(-1!==e.inArray(r.toString(),t)||-1!==e.inArray(l,t))&&(a=a?a.add(i):i);else if(n){if(w.verbose("Ambiguous dropdown value using strict type check",i,t),r===t||l===t)return a=i,!0}else if(r==t||l==t)return w.verbose("Found select item by value",r,t),a=i,!0}),a}},restore:{defaults:function(){w.restore.defaultText(),w.restore.defaultValue()},defaultText:function(){var e=I.data(y.defaultText);w.debug("Restoring default text",e),w.set.text(e),O.addClass(C.placeholder)},defaultValue:function(){var e=I.data(y.defaultValue);e!==i&&(w.debug("Restoring default value",e),e.length?w.set.selected(e):(w.remove.activeItem(),w.remove.selectedItem()))}},save:{defaults:function(){w.save.defaultText(),w.save.placeholderText(),w.save.defaultValue()},defaultValue:function(){I.data(y.defaultValue,w.get.value())},defaultText:function(){I.data(y.defaultText,O.text())},placeholderText:function(){O.hasClass(C.placeholder)&&I.data(y.placeholderText,O.text())}},clear:function(){w.set.placeholderText(),w.clearValue(),w.remove.activeItem(),w.remove.selectedItem()},clearValue:function(){w.set.value("")},set:{filtered:function(){var e=w.is.multiple(),t=w.is.searchSelection(),n=e&&t,i=t?F.val():"",o="string"==typeof i&&i.length>0,a=i.length*x.glyphWidth+"em",l=""!=q.val();e&&o&&(w.verbose("Adjusting input width",a,x.glyphWidth),F.css("width",a)),o||n&&l?(w.verbose("Hiding placeholder text"),O.addClass(C.filtered)):(!e||n&&!l)&&(w.verbose("Showing placeholder text"),O.removeClass(C.filtered))},placeholderText:function(e){w.debug("Restoring placeholder text"),e=e||I.data(y.placeholderText),w.set.text(e),O.addClass(C.placeholder)},tabbable:function(){w.has.search()?(w.debug("Searchable dropdown initialized"),F.val("").attr("tabindex",0),M.attr("tabindex","-1")):(w.debug("Simple selection dropdown initialized"),I.attr("tabindex")||(I.attr("tabindex",0),M.attr("tabindex","-1")))},scrollPosition:function(e,t){var n,o,a,l,r,s,c,d,u,v=5;e=e||w.get.activeItem(),n=e&&e.length>0,t=t!==i?t:!1,e&&n&&(M.hasClass(C.visible)||M.addClass(C.loading),c=M.height(),a=e.height(),s=M.scrollTop(),r=M.offset().top,l=e.offset().top,o=s-r+l,u=o+v>s+c,d=s>o-v,w.debug("Scrolling to active item",o),(d||u||t)&&M.scrollTop(o).removeClass(C.loading))},text:function(e){"select"!==x.action?(w.debug("Changing text",e,O),O.removeClass(C.filtered).removeClass(C.placeholder),x.preserveHTML?O.html(e):O.text(e)):"combo"==x.action&&(w.debug("Changing combo button text",e,L),x.preserveHTML?L.html(e):L.text(e))},value:function(t,n,i){var o=(q.length>0,w.get.values());if(q.length>0){if(w.is.multiple()&&(t=[t],e.isArray(o)&&(t=o.concat(t),t=w.get.uniqueArray(t)),q.is("select")?w.debug("Setting multiple <select> values",t,q):(t=t.join(x.delimiter),w.debug("Setting hidden input to delimited values",t,q))),t==o)return void w.verbose("Skipping value update already same value",t,o);w.debug("Updating input value",t,o),q.val(t).trigger("change"),x.onChange.call(j,t,n,i)}else w.verbose("Storing value in metadata",t,q),t!==o&&(I.data(y.value,t),x.onChange.call(j,t,n,i))},active:function(){I.addClass(C.active)},multiple:function(){I.addClass(C.multiple)},visible:function(){I.addClass(C.visible)},selected:function(t,n){var i,o,a=w.is.multiple();n=n||w.get.item(t),n&&(w.debug("Setting selected menu item to",n),w.is.single()?(w.remove.activeItem(),w.remove.selectedItem()):x.hideSelections&&w.remove.selectedItem(),n.each(function(){var t=e(this),l=!t.hasClass(C.active),r=!t.is("."+C.filtered),s=a&&1==n.length;i=w.get.choiceText(t),o=w.get.choiceValue(t,i),a?l?(w.add.label(o,i,s),w.set.value(o,i,t),t.addClass(C.active),w.filterActive(),w.select.nextAvailable(n)):r&&w.remove.selected(o):(w.set.value(o,i,t),w.set.text(i),t.addClass(C.active).addClass(C.selected))}))}},add:{label:function(t,n,i){var o=e("<a />").addClass(C.label).attr("data-value",t).html(A.label(t,n)),a=w.is.searchSelection()?F:O;x.label.variation&&o.addClass(x.label.variation),1==i?(w.debug("Animating in label",o),o.addClass(C.hidden).insertBefore(a).transition(x.label.transition,x.label.duration)):(w.debug("Adding selection label",o),o.insertBefore(a))}},remove:{active:function(){I.removeClass(C.active)},activeLabel:function(){I.find(T.label).removeClass(C.active)},visible:function(){I.removeClass(C.visible)},activeItem:function(){R.removeClass(C.active)},filteredItem:function(){x.hideSelections?R.not("."+C.active).removeClass(C.filtered):R.removeClass(C.filtered)},searchTerm:function(){w.verbose("Cleared search term"),F.val("")},selected:function(e){var t=w.get.item(e),n=q.val(),i=w.get.choiceValue(t);t&&(q.is("select")?(w.verbose("Input is <select> removing selected"),q.find('option[value="'+i+'"]').prop("selected",!1)):(w.verbose("Input is csv removing value"),n=w.remove.delimitedValue(i,n),q.val(n).trigger("change")),w.is.multiple()&&w.remove.label(i),t.removeClass(C.filtered).removeClass(C.active),x.hideSelections&&t.removeClass(C.selected))},selectedItem:function(){R.removeClass(C.selected)},delimitedValue:function(t,n){return"string"!=typeof n?!1:(n=n.split(x.delimiter),n=e.grep(n,function(e){return t!=e}),n=n.join(x.delimiter),w.verbose("Removed value from delimited string",t,n),n)},label:function(e){var t=I.find(T.label),n=t.filter('[data-value="'+e+'"]'),i=t.length,o=t.index(n)+1==i,a=1==i,l=a||o;l?(w.verbose("Animating and removing label",n),n.transition(x.label.transition,x.label.duration,function(){n.remove()})):(w.verbose("Removing label",n),n.remove())},labels:function(t){t=t||I.find(T.label).filter("."+C.active),w.verbose("Removing active labels",t),t.each(function(){w.remove.selected(e(this).data("value"))})},tabbable:function(){w.has.search()?(w.debug("Searchable dropdown initialized"),F.attr("tabindex","-1"),M.attr("tabindex","-1")):(w.debug("Simple selection dropdown initialized"),I.attr("tabindex","-1"),M.attr("tabindex","-1"))}},has:{search:function(){return F.length>0},input:function(){return q.length>0},menu:function(){return M.length>0}},is:{active:function(){return I.hasClass(C.active)},alreadySetup:function(){return I.is("select")&&I.parent(T.dropdown).length>0},animating:function(e){return e?e.transition&&e.transition("is animating"):M.transition&&M.transition("is animating")},focused:function(){return n.activeElement===I[0]},focusedOnSearch:function(){return n.activeElement===F[0]},allFiltered:function(){return R.filter("."+C.filtered).length===R.length},hidden:function(e){return e?e.is(":hidden"):M.is(":hidden")},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 I.hasClass(C.multiple)},single:function(){return!w.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 I.hasClass(C.search)},searchSelection:function(){return w.has.search()&&0==F.closest(T.menu).length},selection:function(){return I.hasClass(C.selection)},upward:function(){return I.hasClass(C.upward)},visible:function(e){return e?e.is(":visible"):M.is(":visible")}},can:{click:function(){return c||"click"==x.on},show:function(){return!I.hasClass(C.disabled)}},animate:{show:function(t,n){var o=n||M,a=n?function(){}:function(){w.hideSubMenus(),w.hideOthers(),w.set.active()};t=e.isFunction(t)?t:function(){},w.is.single()&&w.set.scrollPosition(w.get.activeItem(),!0),w.verbose("Doing menu show animation",o),(w.is.hidden(o)||w.is.animating(o))&&("auto"==x.transition&&(x.transition=w.is.upward()?"slide up":"slide down",w.verbose("Automatically determining animation based on animation direction",x.transition)),"none"==x.transition?(a(),o.transition("show"),t.call(j)):e.fn.transition!==i&&I.transition("is supported")?o.transition({animation:x.transition+" in",debug:x.debug,verbose:x.verbose,duration:x.duration,queue:!0,onStart:a,onComplete:function(){t.call(j)}}):w.error(k.noTransition,x.transition))},hide:function(t,n){var o=n||M,a=(n?.9*x.duration:x.duration,n?function(){}:function(){w.can.click()&&w.unbind.intent(),w.focusSearch(),w.remove.active()});t=e.isFunction(t)?t:function(){},(w.is.visible(o)||w.is.animating(o))&&(w.verbose("Doing menu hide animation",o),"auto"==x.transition&&(x.transition=w.is.upward()?"slide up":"slide down"),"none"==x.transition?(a(),o.transition("hide"),t.call(j)):e.fn.transition!==i&&I.transition("is supported")?o.transition({animation:x.transition+" out",duration:x.duration,debug:x.debug,verbose:x.verbose,queue:!0,onStart:a,onComplete:function(){t.call(j)}}):w.error(k.transition))}},hideAndClear:function(){w.is.searchSelection()?(w.remove.searchTerm(),w.hide(function(){w.remove.filteredItem()})):w.hide()},delay:{show:function(){w.verbose("Delaying show event to ensure user intent"),clearTimeout(w.timer),w.timer=setTimeout(w.show,x.delay.show)},hide:function(){w.verbose("Delaying hide event to ensure user intent"),clearTimeout(w.timer),w.timer=setTimeout(w.hide,x.delay.hide)}},escape:{regExp:function(e){return e=String(e),e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}},setting:function(t,n){if(w.debug("Changing setting",t,n),e.isPlainObject(t))e.extend(!0,x,t);else{if(n===i)return x[t];x[t]=n}},internal:function(t,n){if(e.isPlainObject(t))e.extend(!0,w,t);else{if(n===i)return w[t];w[t]=n}},debug:function(){x.debug&&(x.performance?w.performance.log(arguments):(w.debug=Function.prototype.bind.call(console.info,console,x.name+":"),w.debug.apply(console,arguments)))},verbose:function(){x.verbose&&x.debug&&(x.performance?w.performance.log(arguments):(w.verbose=Function.prototype.bind.call(console.info,console,x.name+":"),w.verbose.apply(console,arguments)))},error:function(){w.error=Function.prototype.bind.call(console.error,console,x.name+":"),w.error.apply(console,arguments)},performance:{log:function(e){var t,n,i;x.performance&&(t=(new Date).getTime(),i=d||t,n=t-i,d=t,u.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:j,"Execution Time":n})),clearTimeout(w.performance.timer),w.performance.timer=setTimeout(w.performance.display,500)},display:function(){var t=x.name+":",n=0;d=!1,clearTimeout(w.performance.timer),e.each(u,function(e,t){n+=t["Execution Time"]}),t+=" "+n+"ms",s&&(t+=" '"+s+"'"),(console.group!==i||console.table!==i)&&u.length>0&&(console.groupCollapsed(t),console.table?console.table(u):e.each(u,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),u=[]}},invoke:function(t,n,o){var l,r,s,c=H;return n=n||h,o=j||o,"string"==typeof t&&c!==i&&(t=t.split(/[\. ]/),l=t.length-1,e.each(t,function(n,o){var a=n!=l?o+t[n+1].charAt(0).toUpperCase()+t[n+1].slice(1):t;if(e.isPlainObject(c[a])&&n!=l)c=c[a];else{if(c[a]!==i)return r=c[a],!1;if(!e.isPlainObject(c[o])||n==l)return c[o]!==i?(r=c[o],!1):(w.error(k.method,t),!1);c=c[o]}})),e.isFunction(r)?s=r.apply(o,n):r!==i&&(s=r),e.isArray(a)?a.push(s):a!==i?a=[a,s]:s!==i&&(a=s),r}},f?(H===i&&w.initialize(),w.invoke(v)):(H!==i&&H.invoke("destroy"),w.initialize())}),a!==i?a:l},e.fn.dropdown.settings={debug:!1,verbose:!1,performance:!0,on:"click",action:"activate",allowTab:!0,showOnFocus:!0,fullTextSearch:!1,placeholder:"auto",preserveHTML:!0,sortSelect:!1,match:"both",allowCategorySelection:!1,forceSelection:!0,transition:"auto",duration:250,delay:{hide:300,show:200,search:50,touch:50},glyphWidth:1.0714,allowAdditions:!0,delimiter:",",label:{transition:"horizontal flip",duration:150,variation:!1},hideSelections:!0,onLabelSelect:function(){},onNoResults:function(){},onChange:function(){},onShow:function(){},onHide:function(){},name:"Dropdown",namespace:"dropdown",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",method:"The method you called is not defined.",noTransition:"This module requires ui transitions <https://github.com/Semantic-Org/UI-Transition>"},metadata:{defaultText:"defaultText",defaultValue:"defaultValue",placeholderText:"placeholderText",text:"text",value:"value"},selector:{dropdown:".ui.dropdown",icon:"> .dropdown.icon",input:'> input[type="hidden"], > select',item:".item",label:"> .label",remove:"> .label > .delete.icon",siblingLabel:".label",menu:".menu",menuIcon:".dropdown.icon",search:"input.search, .menu > .search > input",text:"> .text:not(.icon)"},className:{active:"active",animating:"animating",disabled:"disabled",dropdown:"ui dropdown",filtered:"filtered",hidden:"hidden transition",label:"ui label",loading:"loading",menu:"menu",multiple:"multiple",placeholder:"default",search:"search",selected:"selected",selection:"selection",upward:"upward",visible:"visible"}},e.fn.dropdown.settings.templates={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>'},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>"}},e.extend(e.easing,{easeOutQuad:function(e,t,n,i,o){return-i*(t/=o)*(t-2)+n}})}(jQuery,window,document);
|