/* * # Semantic UI * https://github.com/Semantic-Org/Semantic-UI * http://beta.semantic-ui.com/ * * Copyright 2014 Contributors * Released under the MIT license * http://opensource.org/licenses/MIT * */ !function(e,t,n,i){"use strict";e.fn.dropdown=function(t){var o,s=e(this),a=e(n),r=s.selector||"",u="ontouchstart"in n.documentElement,c=(new Date).getTime(),d=[],l=arguments[0],v="string"==typeof l,f=[].slice.call(arguments,1);return s.each(function(){var n,m,h=e.isPlainObject(t)?e.extend(!0,{},e.fn.dropdown.settings,t):e.extend({},e.fn.dropdown.settings),p=h.className,g=h.metadata,b=h.namespace,w=h.selector,y=h.error,x="."+b,T="module-"+b,C=e(this),k=C.find(w.text),S=C.find(w.search),z=C.find(w.input),E=C.prev().find(w.text).size()>0?C.prev().find(w.text):C.prev(),D=C.children(w.menu),M=D.find(w.item),A=!1,O=!1,I=this,Q=C.data(T);m={initialize:function(){m.debug("Initializing dropdown",h),m.setup.layout(),m.save.defaults(),m.set.selected(),u&&m.bind.touchEvents(),m.bind.mouseEvents(),m.bind.keyboardEvents(),m.observeChanges(),m.instantiate()},instantiate:function(){m.verbose("Storing instance of dropdown",m),Q=m,C.data(T,m)},destroy:function(){m.verbose("Destroying previous dropdown for",C),C.off(x).removeData(T)},observeChanges:function(){MutationObserver!==i&&(n=new MutationObserver(function(){m.debug("DOM tree modified, updating selector cache"),m.refresh()}),n.observe(I,{childList:!0,subtree:!0}),m.debug("Setting up mutation observer",n))},setup:{layout:function(){C.is("select")&&m.setup.select(),m.is.search()&&!m.is.searchable()&&(S=e("").addClass(p.search).insertBefore(k)),h.allowTab&&(m.is.searchable()?(m.debug("Searchable dropdown initialized"),S.val("").attr("tabindex",0),D.attr("tabindex","-1")):(m.debug("Simple selection dropdown initialized"),C.attr("tabindex")||(C.attr("tabindex",0),D.attr("tabindex","-1"))))},select:function(){var t=m.get.selectValues();m.debug("Dropdown initialized on a select",t),z=C,z.parents(w.dropdown).size()>0?(m.debug("Creating dropdown menu only from template"),C=z.closest(w.dropdown),0===C.find("."+p.dropdown).size()&&e("
").addClass(p.menu).html(h.templates.menu(t)).appendTo(C)):(m.debug("Creating entire dropdown from template"),C=e("
").attr("class",z.attr("class")).addClass(p.selection).addClass(p.dropdown).html(h.templates.dropdown(t)).insertBefore(z),z.removeAttr("class").prependTo(C)),m.refresh()}},refresh:function(){k=C.find(w.text),S=C.find(w.search),z=C.find(w.input),D=C.children(w.menu),M=D.find(w.item)},toggle:function(){m.verbose("Toggling menu visibility"),m.is.active()?m.hide():m.show()},show:function(){m.debug("Checking if dropdown can show"),m.is.active()||(m.animate.show(function(){m.can.click()&&m.bind.intent(),m.set.visible()}),e.proxy(h.onShow,I)())},hide:function(){m.is.active()&&(m.debug("Hiding dropdown"),m.animate.hide(function(){m.remove.filteredItem(),m.remove.visible()}),e.proxy(h.onHide,I)())},hideOthers:function(){m.verbose("Finding other dropdowns to hide"),s.not(C).has(w.menu+":visible:not(."+p.animating+")").dropdown("hide")},hideSubMenus:function(){var e=D.find(w.menu),t=e.has(w.item+"."+p.active);e.not(t).removeClass(p.visible).removeAttr("style")},bind:{keyboardEvents:function(){m.debug("Binding keyboard events"),C.on("keydown"+x,m.event.keydown),m.is.searchable()&&C.on(m.get.inputEvent(),w.search,m.event.input)},touchEvents:function(){m.debug("Touch device detected binding touch events"),m.is.searchSelection()||C.on("touchstart"+x,m.event.test.toggle),C.on("touchstart"+x,w.item,m.event.item.mouseenter).on("touchstart"+x,w.item,m.event.item.click)},mouseEvents:function(){m.verbose("Mouse detected binding mouse events"),m.is.searchSelection()?C.on("focus"+x,w.search,m.event.searchFocus).on("blur"+x,w.search,m.event.searchBlur):("click"==h.on?C.on("click"+x,m.event.test.toggle):"hover"==h.on?C.on("mouseenter"+x,m.delay.show).on("mouseleave"+x,m.delay.hide):C.on(h.on+x,m.toggle),C.on("mousedown",m.event.mousedown).on("mouseup",m.event.mouseup).on("focus"+x,m.event.focus).on("blur"+x,m.event.blur)),C.on("mousedown"+x,w.item,m.event.item.mousedown).on("mouseup"+x,w.item,m.event.item.mouseup).on("mouseenter"+x,w.item,m.event.item.mouseenter).on("mouseleave"+x,w.item,m.event.item.mouseleave).on("click"+x,w.item,m.event.item.click)},intent:function(){m.verbose("Binding hide intent event to document"),u&&a.on("touchstart"+x,m.event.test.touch).on("touchmove"+x,m.event.test.touch),a.on("click"+x,m.event.test.hide)}},unbind:{intent:function(){m.verbose("Removing hide intent event from document"),u&&a.off("touchstart"+x).off("touchmove"+x),a.off("click"+x)}},filter:function(t){var n,o=e(),s=new RegExp("(?:s|^)"+t,"i"),a=new RegExp(t,"i");M.each(function(){var t=e(this),n=t.data(g.text)!==i?t.data(g.text):h.preserveHTML?t.html():t.text(),r=t.data(g.value)!==i?t.data(g.value):"string"==typeof n?n.toLowerCase():n;s.test(n)||s.test(r)?o=o.add(t):h.fullTextSearch&&(a.test(n)||a.test(r))&&(o=o.add(t))}),n=M.not(o),m.remove.filteredItem(),m.remove.selectedItem(),n.addClass(p.filtered),M.not("."+p.filtered).eq(0).addClass(p.selected)},event:{mousedown:function(){A=!0},mouseup:function(){A=!1},focus:function(){A||m.show()},blur:function(){A||m.hide()},searchFocus:function(){A=!0,m.show()},searchBlur:function(){O||m.hide()},input:function(){var e=S.val();m.is.searchSelection()&&k.addClass(p.filtered),m.filter(e)},keydown:function(t){var n,i=M.not(p.filtered).filter("."+p.selected).eq(0),o=M.not("."+p.filtered),s=t.which,a={enter:13,escape:27,upArrow:38,downArrow:40},r=p.selected,u=o.index(i),c=i.size()>0;if(c||(i=M.filter("."+p.active).eq(0),c=i.size()>0),s==a.escape&&(m.verbose("Escape key pressed, closing dropdown"),S.blur(),m.hide()),m.is.visible()){if(s==a.enter&&c)return m.verbose("Enter key pressed, choosing selected item"),m.is.searchable()&&(m.verbose("Removing focus from search input"),S.blur()),e.proxy(m.event.item.click,i)(t),t.preventDefault(),!1;s==a.upArrow?(n=c?i.prevAll(w.item+":not(."+p.filtered+")").eq(0):o.eq(0),0!==u&&(m.verbose("Up key pressed, changing active item"),M.removeClass(r),n.addClass(r),m.set.scrollPosition(n)),t.preventDefault()):s==a.downArrow&&(n=c?i.nextAll(w.item+":not(."+p.filtered+")").eq(0):o.eq(0),u+10&&(clearTimeout(m.itemTimer),m.itemTimer=setTimeout(function(){m.animate.hide(!1,i),m.verbose("Showing sub-menu",n),m.animate.show(!1,n)},2*h.delay.show),t.preventDefault())},mouseleave:function(){var t=e(this).find(w.menu);t.size()>0&&(clearTimeout(m.itemTimer),m.itemTimer=setTimeout(function(){m.verbose("Hiding sub-menu",t),m.animate.hide(!1,t)},h.delay.hide))},click:function(){var t=e(this),n=t.data(g.text)!==i?t.data(g.text):h.preserveHTML?t.html():t.text(),o=t.data(g.value)!==i?t.data(g.value):"string"==typeof n?n.toLowerCase():n,s=function(){S.val(""),m.determine.selectAction(n,o),e.proxy(h.onChange,I)(o,n,t)},a=t.find(w.menu).size()>0;a||s()}},resetStyle:function(){e(this).removeAttr("style")}},determine:{selectAction:function(t,n){m.verbose("Determining action",h.action),e.isFunction(m.action[h.action])?(m.verbose("Triggering preset action",h.action,t,n),m.action[h.action](t,n)):e.isFunction(h.action)?(m.verbose("Triggering user action",h.action,t,n),h.action(t,n)):m.error(y.action,h.action)},eventInModule:function(t,n){return n=n||function(){},0===e(t.target).closest(C).size()?(m.verbose("Triggering event",n),n(),!0):(m.verbose("Event occurred in dropdown, canceling callback"),!1)},eventInMenu:function(t,n){return n=n||function(){},0===e(t.target).closest(D).size()?(m.verbose("Triggering event",n),n(),!0):(m.verbose("Event occurred in dropdown menu, canceling callback"),!1)}},action:{nothing:function(){},hide:function(){m.hide()},select:function(e,t){t=t!==i?t:e,m.set.selected(t),m.set.value(t),m.hide()},activate:function(e,t){t=t!==i?t:e,m.set.selected(t),m.set.value(t),m.hide()},combo:function(e,t){t=t!==i?t:e,m.set.selected(t),m.set.value(t),m.hide()}},get:{text:function(){return k.text()},value:function(){return z.size()>0?z.val():C.data(g.value)},inputEvent:function(){var e=S[0];return e?e.oninput!==i?"input":e.onpropertychange!==i?"propertychange":"keyup":!1},selectValues:function(){var t={values:{}};return C.find("option").each(function(){var n=e(this).html(),o=e(this).attr("value")!==i?e(this).attr("value"):n;""===o?t.placeholder=n:t.values[o]=n}),m.debug("Retrieved values from select",t),t},item:function(t,n){var o=!1;return t=t!==i?t:m.get.value()!==i?m.get.value():m.get.text(),n=""===t||0===t?!0:n||!1,t!==i?M.each(function(){var s=e(this),a=s.data(g.text)!==i?s.data(g.text):h.preserveHTML?s.html():s.text(),r=s.data(g.value)!==i?s.data(g.value):"string"==typeof a?a.toLowerCase():a;n?(m.debug("Ambiguous dropdown value using strict type check",t),r===t?o=e(this):o||a!==t||(o=e(this))):r==t?(m.verbose("Found select item by value",r,t),o=e(this)):o||a!=t||(m.verbose("Found select item by text",a,t),o=e(this))}):t=m.get.text(),o||!1}},restore:{defaults:function(){m.restore.defaultText(),m.restore.defaultValue()},defaultText:function(){var e=C.data(g.defaultText);m.debug("Restoring default text",e),m.set.text(e)},defaultValue:function(){var e=C.data(g.defaultValue);e!==i&&(m.debug("Restoring default value",e),m.set.selected(e),m.set.value(e))}},save:{defaults:function(){m.save.defaultText(),m.save.defaultValue()},defaultValue:function(){C.data(g.defaultValue,m.get.value())},defaultText:function(){C.data(g.defaultText,k.text())}},set:{scrollPosition:function(e){var t,n,i,o,s,a,r,u,e=e||m.get.item(),c=e&&e.size()>0,d=5;e&&c&&(a=D.height(),n=e.height(),s=D.scrollTop(),o=D.offset().top,i=e.offset().top,t=s-o+i,u=t+d>s+a,r=s>t-d,(r||u)&&(m.debug("Scrolling to active item"),D.scrollTop(t)))},text:function(e){"combo"==h.action?(m.debug("Changing combo button text",e,E),h.preserveHTML?E.html(e):E.text(e)):"select"!==h.action&&(m.debug("Changing text",e,k),k.removeClass(p.filtered).removeClass(p.placeholder),h.preserveHTML?k.html(e):k.text(e))},value:function(e){m.debug("Adding selected value to hidden input",e,z),z.size()>0?z.val(e).trigger("change"):C.data(g.value,e)},active:function(){C.addClass(p.active)},visible:function(){C.addClass(p.visible)},selected:function(e){var t,n=m.get.item(e);n&&(m.debug("Setting selected menu item to",n),t=n.data(g.text)!==i?n.data(g.text):h.preserveHTML?n.html():n.text(),m.remove.activeItem(),m.remove.selectedItem(),n.addClass(p.active).addClass(p.selected),m.set.text(t))}},remove:{active:function(){C.removeClass(p.active)},visible:function(){C.removeClass(p.visible)},activeItem:function(){M.removeClass(p.active)},filteredItem:function(){M.removeClass(p.filtered)},selectedItem:function(){M.removeClass(p.selected)}},is:{search:function(){return C.hasClass(p.search)},searchable:function(){return S.size()>0},searchSelection:function(){return m.is.searchable()&&S.parent().is(C)},selection:function(){return C.hasClass(p.selection)},animated:function(e){return e?e.is(":animated")||e.transition&&e.transition("is animating"):D.is(":animated")||D.transition&&D.transition("is animating")},active:function(){return C.hasClass(p.active)},visible:function(e){return e?e.is(":visible"):D.is(":visible")},hidden:function(e){return e?e.is(":hidden"):D.is(":hidden")}},can:{click:function(){return u||"click"==h.on},show:function(){return!C.hasClass(p.disabled)}},animate:{show:function(t,n){var o=n||D,s=n?function(){}:function(){m.hideOthers(),m.set.active(),m.set.scrollPosition()};t=t||function(){},m.verbose("Doing menu show animation",o),m.is.hidden(o)&&("none"==h.transition?e.proxy(t,I)():e.fn.transition!==i&&C.transition("is supported")?o.transition({animation:h.transition+" in",duration:h.duration,queue:!0,onStart:s,onComplete:function(){e.proxy(t,I)()}}):"slide down"==h.transition?(s(),o.hide().clearQueue().children().clearQueue().css("opacity",0).delay(50).animate({opacity:1},h.duration,"easeOutQuad",m.event.resetStyle).end().slideDown(100,"easeOutQuad",function(){e.proxy(m.event.resetStyle,this)(),e.proxy(t,I)()})):"fade"==h.transition?(s(),o.hide().clearQueue().fadeIn(h.duration,function(){e.proxy(m.event.resetStyle,this)(),e.proxy(t,I)()})):m.error(y.transition,h.transition))},hide:function(t,n){var o=n||D,s=n?function(){}:function(){m.can.click()&&m.unbind.intent(),m.hideSubMenus(),m.remove.active()};t=t||function(){},m.is.visible(o)&&(m.verbose("Doing menu hide animation",o),"none"==h.transition?e.proxy(t,I)():e.fn.transition!==i&&C.transition("is supported")?o.transition({animation:h.transition+" out",duration:h.duration,queue:!0,onStart:s,onComplete:function(){e.proxy(t,I)()}}):"slide down"==h.transition?(s(),o.show().clearQueue().children().clearQueue().css("opacity",1).animate({opacity:0},100,"easeOutQuad",m.event.resetStyle).end().delay(50).slideUp(100,"easeOutQuad",function(){e.proxy(m.event.resetStyle,this)(),e.proxy(t,I)()})):"fade"==h.transition?(s(),o.show().clearQueue().fadeOut(150,function(){e.proxy(m.event.resetStyle,this)(),e.proxy(t,I)()})):m.error(y.transition))}},delay:{show:function(){m.verbose("Delaying show event to ensure user intent"),clearTimeout(m.timer),m.timer=setTimeout(m.show,h.delay.show)},hide:function(){m.verbose("Delaying hide event to ensure user intent"),clearTimeout(m.timer),m.timer=setTimeout(m.hide,h.delay.hide)}},setting:function(t,n){if(m.debug("Changing setting",t,n),e.isPlainObject(t))e.extend(!0,h,t);else{if(n===i)return h[t];h[t]=n}},internal:function(t,n){if(e.isPlainObject(t))e.extend(!0,m,t);else{if(n===i)return m[t];m[t]=n}},debug:function(){h.debug&&(h.performance?m.performance.log(arguments):(m.debug=Function.prototype.bind.call(console.info,console,h.name+":"),m.debug.apply(console,arguments)))},verbose:function(){h.verbose&&h.debug&&(h.performance?m.performance.log(arguments):(m.verbose=Function.prototype.bind.call(console.info,console,h.name+":"),m.verbose.apply(console,arguments)))},error:function(){m.error=Function.prototype.bind.call(console.error,console,h.name+":"),m.error.apply(console,arguments)},performance:{log:function(e){var t,n,i;h.performance&&(t=(new Date).getTime(),i=c||t,n=t-i,c=t,d.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:I,"Execution Time":n})),clearTimeout(m.performance.timer),m.performance.timer=setTimeout(m.performance.display,100)},display:function(){var t=h.name+":",n=0;c=!1,clearTimeout(m.performance.timer),e.each(d,function(e,t){n+=t["Execution Time"]}),t+=" "+n+"ms",r&&(t+=" '"+r+"'"),(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,s){var a,r,u,c=Q;return n=n||f,s=I||s,"string"==typeof t&&c!==i&&(t=t.split(/[\. ]/),a=t.length-1,e.each(t,function(n,o){var s=n!=a?o+t[n+1].charAt(0).toUpperCase()+t[n+1].slice(1):t;if(e.isPlainObject(c[s])&&n!=a)c=c[s];else{if(c[s]!==i)return r=c[s],!1;if(!e.isPlainObject(c[o])||n==a)return c[o]!==i?(r=c[o],!1):(m.error(y.method,t),!1);c=c[o]}})),e.isFunction(r)?u=r.apply(s,n):r!==i&&(u=r),e.isArray(o)?o.push(u):o!==i?o=[o,u]:u!==i&&(o=u),r}},v?(Q===i&&m.initialize(),m.invoke(l)):(Q!==i&&m.destroy(),m.initialize())}),o!==i?o:this},e.fn.dropdown.settings={debug:!1,verbose:!0,performance:!0,on:"click",action:"activate",allowTab:!0,fullTextSearch:!0,preserveHTML:!0,delay:{show:200,hide:300,touch:50},transition:"slide down",duration:250,onChange:function(){},onShow:function(){},onHide:function(){},name:"Dropdown",namespace:"dropdown",error:{action:"You called a dropdown action that was not defined",method:"The method you called is not defined.",transition:"The requested transition was not found"},metadata:{defaultText:"defaultText",defaultValue:"defaultValue",text:"text",value:"value"},selector:{dropdown:".ui.dropdown",text:"> .text:not(.icon)",input:'> input[type="hidden"], > select',search:"> .search, .menu > .search > input, .menu > input.search",menu:".menu",item:".item"},className:{active:"active",animating:"animating",disabled:"disabled",dropdown:"ui dropdown",filtered:"filtered",menu:"menu",placeholder:"default",search:"search",selected:"selected",selection:"selection",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+=e===t?'
'+t+"
":'
'+t+"
"}),n},dropdown:function(t){var n=t.placeholder||!1,i=(t.values||{},"");return i+='',i+=t.placeholder?'
'+n+"
":'
',i+='"}},e.extend(e.easing,{easeOutQuad:function(e,t,n,i,o){return-i*(t/=o)*(t-2)+n}})}(jQuery,window,document);