|
|
!function(a,b,c,d){a.fn.dropdown=function(b){var e,f=a(this),g=a(c),h=f.selector||"",i="ontouchstart"in c.documentElement,j=(new Date).getTime(),k=[],l=arguments[0],m="string"==typeof l,n=[].slice.call(arguments,1);return f.each(function(){var c,o=a.isPlainObject(b)?a.extend(!0,{},a.fn.dropdown.settings,b):a.extend({},a.fn.dropdown.settings),p=o.className,q=o.metadata,r=o.namespace,s=o.selector,t=o.error,u="."+r,v="module-"+r,w=a(this),x=w.find(s.text),y=w.find(s.search),z=w.find(s.input),A=w.prev().find(s.text).size()>0?w.prev().find(s.text):w.prev(),B=w.children(s.menu),C=B.find(s.item),D=!1,E=this,F=w.data(v);c={initialize:function(){c.debug("Initializing dropdown",o),c.setup.layout(),c.save.defaults(),c.set.selected(),i&&c.bind.touchEvents(),c.bind.mouseEvents(),c.bind.keyboardEvents(),c.instantiate()},instantiate:function(){c.verbose("Storing instance of dropdown",c),F=c,w.data(v,c)},destroy:function(){c.verbose("Destroying previous dropdown for",w),C.off(u),w.off(u).removeData(v)},setup:{layout:function(){w.is("select")&&c.setup.select(),c.is.search()&&!c.is.searchable()&&(y=a("<input />").addClass(p.search).insertBefore(x)),c.is.searchable()?(c.debug("Searchable dropdown initialized"),y.val("").attr("tabindex",0),B.attr("tabindex","-1")):(c.debug("Simple selection dropdown initialized"),w.attr("tabindex")||(w.attr("tabindex",0),B.attr("tabindex","-1")))},select:function(){c.debug("Dropdown initialized on a select, generating html"),z=w,w=a("<div />").attr("class",z.attr("class")).addClass(p.selection).html(o.templates.select(c.get.selectValues())).insertBefore(z),z.removeAttr("class").prependTo(w),c.refresh()}},refresh:function(){x=w.find(s.text),y=w.find(s.search),z=w.find(s.input),B=w.children(s.menu),C=B.find(s.item)},bind:{keyboardEvents:function(){c.debug("Binding keyboard events"),w.on("keydown"+u,c.event.keydown),c.is.searchable()?(y.on("focus"+u,c.event.searchFocus).on(c.get.inputEvent(),c.event.input),w.on("blur"+u,c.event.blur)):w.on("mousedown",c.event.mousedown).on("mouseup",c.event.mouseup).on("focus"+u,c.event.focus).on("blur"+u,c.event.blur)},touchEvents:function(){c.debug("Touch device detected binding touch events"),c.is.searchable()||w.on("touchstart"+u,c.event.test.toggle),C.on("touchstart"+u,c.event.item.mouseenter).on("touchstart"+u,c.event.item.click)},mouseEvents:function(){c.verbose("Mouse detected binding mouse events"),c.is.searchable()||("click"==o.on?w.on("click"+u,c.event.test.toggle):"hover"==o.on?w.on("mouseenter"+u,c.delay.show).on("mouseleave"+u,c.delay.hide):w.on(o.on+u,c.toggle)),C.on("mouseenter"+u,c.event.item.mouseenter).on("mouseleave"+u,c.event.item.mouseleave).on("click"+u,c.event.item.click)},intent:function(){c.verbose("Binding hide intent event to document"),i&&g.on("touchstart"+u,c.event.test.touch).on("touchmove"+u,c.event.test.touch),g.on("click"+u,c.event.test.hide)}},unbind:{intent:function(){c.verbose("Removing hide intent event from document"),i&&g.off("touchstart"+u).off("touchmove"+u),g.off("click"+u)}},filter:function(b){var c,e=a(),f=new RegExp("(?:s|^)"+b,"i"),g=new RegExp(b,"i");C.each(function(){var b=a(this),c=b.data(q.text)!==d?b.data(q.text):o.preserveHTML?b.html():b.text(),h=b.data(q.value)!==d?b.data(q.value):"string"==typeof c?c.toLowerCase():c;f.test(c)||f.test(h)?e=e.add(b):o.fullTextSearch&&(g.test(c)||g.test(h))&&(e=e.add(b))}),c=C.not(e),C.removeClass(p.filtered).removeClass(p.selected),c.addClass(p.filtered),C.not("."+p.filtered).eq(0).addClass(p.selected)},event:{mousedown:function(){D=!0},mouseup:function(){D=!1},focus:function(){D||c.show()},searchFocus:function(){D=!0,c.show()},blur:function(a){D=!1,c.determine.eventInModule(a,c.hide)},input:function(){var a=y.val();x.addClass(p.filtered),c.filter(a)},keydown:function(b){var d,e=C.not(p.filtered).filter("."+p.selected).eq(0),f=C.not("."+p.filtered),g=b.which,h={enter:13,escape:27,upArrow:38,downArrow:40},i=p.selected,j=f.index(e),k=e.size()>0;if(k||(e=C.filter("."+p.active).eq(0),k=e.size()>0),g==h.escape&&(c.verbose("Escape key pressed, closing dropdown"),y.blur(),c.hide()),c.is.visible())
|