/*! * # 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,r=e(this),l=e(n),s=r.selector||"",c="ontouchstart"in n.documentElement,u=(new Date).getTime(),d=[],v=arguments[0],f="string"==typeof v,m=[].slice.call(arguments,1);return r.each(function(){var h,g,p,b,w,x=e.isPlainObject(o)?e.extend(!0,{},e.fn.dropdown.settings,o):e.extend({},e.fn.dropdown.settings),y=x.className,C=x.metadata,T=x.namespace,S=x.selector,k=x.error,A=x.templates,D="."+T,E="module-"+T,I=e(this),O=I.find(S.text),F=I.find(S.search),V=I.find(S.input),R=I.find(S.icon),q=I.prev().find(S.text).length>0?I.prev().find(S.text):I.prev(),M=I.children(S.menu),P=M.find(S.item),z=!1,L=!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),l.off(h),p&&p.disconnect(),b&&b.disconnect()},observeChanges:function(){"MutationObserver"in t&&(p=new MutationObserver(function(){w.debug("").addClass(y.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")&&(V=I),V.parent(S.dropdown).length>0?(w.debug("UI dropdown already exists. Creating dropdown menu only"),I=V.closest(S.dropdown),M=I.children(S.menu),0===M.length&&(M=e("
").addClass(y.menu).appendTo(I)),M.html(A.menu(t))):(w.debug("Creating entire dropdown from select"),I=e("
").attr("class",V.attr("class")).addClass(y.selection).addClass(y.dropdown).html(A.dropdown(t)).insertBefore(V),V.removeAttr("class").detach().prependTo(I)),V.is("[multiple]")&&w.set.multiple(),w.refresh()},reference:function(){var e,t,n=r.index(I);w.debug("Dropdown behavior was called on select, replacing with closest dropdown"),I=I.parent(S.dropdown),w.refresh(),e=r.slice(0,n),t=r.slice(n+1),r=e.add(I).add(t),f&&(H=w,w.invoke(v))}},refresh:function(){w.verbose("Refreshing selector cache"),O=I.find(S.text),F=I.find(S.search),V=I.find(S.input),R=I.find(S.icon),q=I.prev().find(S.text).length>0?I.prev().find(S.text):I.prev(),M=I.children(S.menu),P=M.find(S.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"),r.not(I).has(S.menu+":visible:not(."+y.animating+")").dropdown("hide")},hideSubMenus:function(){var e=M.children(S.item).find(S.menu);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,S.search,w.event.input),w.is.multiple()&&l.on("keydown"+h,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,S.item,w.event.item.mouseenter)},mouseEvents:function(){w.verbose("Mouse detected binding mouse events"),w.is.multiple()&&I.on("click"+D,S.label,w.event.label.click).on("click"+D,S.remove,w.event.remove.click),w.is.searchSelection()?(I.on("mousedown"+D,S.menu,w.event.menu.mousedown).on("mouseup"+D,S.menu,w.event.menu.mouseup).on("click"+D,S.search,w.show).on("focus"+D,S.search,w.event.search.focus).on("blur"+D,S.search,w.event.search.blur).on("click"+D,S.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,S.item,w.event.item.mouseenter).on("mouseleave"+D,S.item,w.event.item.mouseleave).on("click"+D,S.item,w.event.item.click)},intent:function(){w.verbose("Binding hide intent event to document"),c&&l.on("touchstart"+h,w.event.test.touch).on("touchmove"+h,w.event.test.touch),l.on("click"+h,w.event.test.hide)}},unbind:{intent:function(){w.verbose("Removing hide intent event from document"),c&&l.off("touchstart"+h).off("touchmove"+h),l.off("click"+h)}},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"),P.each(function(){var t,i,r=e(this);if("both"==x.match||"text"==x.match){if(t=String(w.get.choiceText(r,!1)),t.match(o))return n=n.add(r),!0;if(x.fullTextSearch&&t.match(a))return n=n.add(r),!0}if("both"==x.match||"value"==x.match){if(console.log("here"),i=String(w.get.choiceValue(r,t)),i.match(o))return n=n.add(r),!0;if(x.fullTextSearch&&i.match(a))return n=n.add(r),!0}}),w.debug("Setting filter",t),w.remove.filteredItem(),P.not(n).addClass(y.filtered),w.is.multiple()&&w.filterActive(),w.verbose("Selecting first non-filtered element"),w.remove.selectedItem(),P.not("."+y.filtered).eq(0).addClass(y.selected),w.is.allFiltered()&&(w.debug("All items filtered, hiding dropdown",t),w.is.searchSelection()&&w.hide(),x.onNoResults.call(j,t))},filterActive:function(){x.filterActive&&P.filter("."+y.active).addClass(y.filtered)},focusSearch:function(){w.is.search()&&!w.is.focusedOnSearch()&&F[0].focus()},forceSelection:function(){var e=P.not(y.filtered).filter("."+y.selected).eq(0),t=P.filter("."+y.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&&!z&&w.is.hidden()&&w.show()},click:function(t){var n=e(t.target);!n.is(I)&&!n.is(R)||w.is.focusedOnSearch()||F.focus()},blur:function(){var e=n.activeElement===this;z||e||(w.remove.activeLabel(),w.hide())},mousedown:function(){z=!0},mouseup:function(){z=!1},search:{focus:function(){z=!0,x.showOnFocus&&w.show()},blur:function(){var e=n.activeElement===this;L||e||(w.is.multiple()?w.remove.activeLabel():x.forceSelection?w.forceSelection():w.hide())}},text:{focus:function(){z=!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(S.label),o=i.filter("."+y.active),a=n.nextAll("."+y.active),r=n.prevAll("."+y.active),l=a.length>0?n.nextUntil(a).add(o).add(n):n.prevUntil(r).add(o).add(n);t.shiftKey?(o.removeClass(y.active),l.addClass(y.active)):t.ctrlKey?n.toggleClass(y.active):(o.removeClass(y.active),n.addClass(y.active)),x.onLabelSelect.apply(this,i.filter("."+y.active))}},remove:{click:function(){var t=e(this).parent();t.hasClass(y.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(){L=!0},mouseup:function(){L=!1}},item:{mouseenter:function(t){var n=e(this).children(S.menu),i=e(this).siblings(S.item).children(S.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(S.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(S.menu),a=w.get.choiceText(n),r=w.get.choiceValue(n,a),l=o.length>0,s=o.find(i).length>0;s||l&&!x.allowCategorySelection||(w.remove.searchTerm(),w.determine.selectAction.call(this,a,r))}},document:{keydown:function(e){var t=e.which,n=w.get.shortcutKeys(),i=w.is.inObject(t,n);if(i){var o=I.find(S.label),a=o.filter("."+y.active),r=a.data("value"),l=o.index(a),s=(o.length,a.length>0),c=0==l,u=w.is.focusedOnSearch(),d=w.is.focused(),v=u&&0==w.get.caretPosition();u&&t==n.delimiter?w.is.visible()&&(w.verbose("Delimiter key pressed. Tokenizing"),w.event.item.click.call($selectedItem,e),e.preventDefault()):t==n.leftArrow?!d&&!v||s?s&&!c&&(e.shiftKey?w.verbose("Adding previous label to selection"):(w.verbose("Selecting previous label"),o.removeClass(y.active)),a.prev().addClass(y.active).end(),e.preventDefault()):(w.verbose("Selecting previous label"),o.last().addClass(y.active)):t==n.rightArrow?(d&&!s&&o.last().addClass(y.active),s&&(e.shiftKey?w.verbose("Adding next label to selection"):(w.verbose("Selecting next label"),o.removeClass(y.active)),a.next().addClass(y.active).end(),e.preventDefault())):t==n.deleteKey||t==n.backspace?s?(w.verbose("Removing active labels"),a.last().next().addClass(y.active),w.remove.labels(a)):v&&!s&&t==n.backspace&&(w.verbose("Removing last label on input backspace"),a=o.last().addClass(y.active),r=a.data("value"),w.remove.selected(r)):a.removeClass(y.active)}}},keydown:function(e){var t=e.which,n=w.get.shortcutKeys(),i=w.is.inObject(t,n);if(i){var o,a,r=P.not(y.filtered).filter("."+y.selected).eq(0),l=M.children("."+y.active).eq(0),s=r.length>0?r:l,c=s.length>0?s.siblings(":not(."+y.filtered+")").andSelf():M.children(":not(."+y.filtered+")"),u=s.children(S.menu),d=s.closest(S.menu),v=d.hasClass(y.visible)||d.hasClass(y.animating),f=u.length>0,m=s.length>0;if(w.is.visible()){if(t==n.enter&&m&&(f&&!x.allowCategorySelection?(w.verbose("Pressed enter on unselectable category, opening sub menu"),t=n.rightArrow):(w.verbose("Enter key pressed, choosing selected item"),w.event.item.click.call(s,e),e.stopImmediatePropagation()),e.preventDefault()),t==n.leftArrow&&(a=d[0]!==M[0],a&&(w.verbose("Left key pressed, closing sub-menu"),w.animate.hide(!1,d),s.removeClass(y.selected),d.closest(S.item).addClass(y.selected),e.preventDefault())),t==n.rightArrow&&f&&(w.verbose("Right key pressed, opening sub-menu"),w.animate.show(!1,u),s.removeClass(y.selected),u.find(S.item).eq(0).addClass(y.selected),e.preventDefault()),t==n.upArrow){if(o=m&&v?s.prevAll(S.item+":not(."+y.filtered+")").eq(0):P.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(y.selected),o.addClass(y.selected),w.set.scrollPosition(o),e.preventDefault()}if(t==n.downArrow){if(o=m&&v?o=s.nextAll(S.item+":not(."+y.filtered+")").eq(0):P.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"),P.removeClass(y.selected),o.addClass(y.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.hide(function(){w.remove.filteredItem()})},select:function(){w.action.activate.call(this)},combo:function(t,n){n=n!==i?n:t,w.set.selected(n,e(this)),w.hide(function(){w.remove.filteredItem()})},hide:function(){w.hide(function(){w.remove.filteredItem()})}},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 V.length>0?V.val():I.data(C.value)},values:function(){var e=w.get.value();return""==e?"":!V.is("select")&&w.is.multiple()?e.split(x.delimiter):e},choiceText:function(e,t){return t=t!==i?t:x.preserveHTML,e?(e.find(S.menu).length>0&&(w.verbose("Retreiving text of element with sub-menu"),e=e.clone(),e.find(S.menu).remove(),e.find(S.menuIcon).remove()),e.data(C.text)!==i?e.data(C.text):t?e.html().trim():e.text().trim()):void 0},choiceValue:function(e,t){return t=t||w.get.choiceText(e),e?e.data(C.value)!==i?e.data(C.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 P.filter("."+y.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&&P.each(function(){var i=e(this),r=w.get.choiceText(i),l=w.get.choiceValue(i,r);if(o)(-1!==e.inArray(l,t)||-1!==e.inArray(r,t))&&(a=a?a.add(i):i);else if(n){if(w.verbose("Ambiguous dropdown value using strict type check",i,t),l===t||r===t)return a=i,!0}else if(l==t||r==t)return w.verbose("Found select item by value",l,t),a=i,!0}),a}},restore:{defaults:function(){w.restore.defaultText(),w.restore.defaultValue()},defaultText:function(){var e=I.data(C.defaultText);w.debug("Restoring default text",e),w.set.text(e),O.addClass(y.placeholder)},defaultValue:function(){var e=I.data(C.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(C.defaultValue,w.get.value())},defaultText:function(){I.data(C.defaultText,O.text())},placeholderText:function(){O.hasClass(y.placeholder)&&I.data(C.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",r=""!=V.val();e&&o&&(w.verbose("Adjusting input width",a,x.glyphWidth),F.css("width",a)),o||n&&r?(w.verbose("Hiding placeholder text"),O.addClass(y.filtered)):(!e||n&&!r)&&(w.verbose("Showing placeholder text"),O.removeClass(y.filtered))},placeholderText:function(e){w.debug("Restoring placeholder text"),e=e||I.data(C.placeholderText),w.set.text(placeholderText),O.addClass(y.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,r,l,s,c,u,d,v=5;e=e||w.get.activeItem(),n=e&&e.length>0,t=t!==i?t:!1,e&&n&&(M.hasClass(y.visible)||M.addClass(y.loading),c=M.height(),a=e.height(),s=M.scrollTop(),l=M.offset().top,r=e.offset().top,o=s-l+r,d=o+v>s+c,u=s>o-v,w.debug("Scrolling to active item",o),(u||d||t)&&M.scrollTop(o).removeClass(y.loading))},text:function(e){"select"!==x.action?(w.debug("Changing text",e,O),O.removeClass(y.filtered).removeClass(y.placeholder),x.preserveHTML?O.html(e):O.text(e)):"combo"==x.action&&(w.debug("Changing combo button text",e,q),x.preserveHTML?q.html(e):q.text(e))},value:function(t,n,i){var o=(V.length>0,w.get.values());if(V.length>0){if(w.is.multiple()&&(t=[t],e.isArray(o)&&(t=o.concat(t),t=w.get.uniqueArray(t)),V.is("select")?w.debug("Setting multiple