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.

0 lines
16 KiB

  1. !function(a,b,c,d){"use strict";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,p=a.isPlainObject(b)?a.extend(!0,{},a.fn.dropdown.settings,b):a.extend({},a.fn.dropdown.settings),q=p.className,r=p.metadata,s=p.namespace,t=p.selector,u=p.error,v="."+s,w="module-"+s,x=a(this),y=x.find(t.text),z=x.find(t.search),A=x.find(t.input),B=x.prev().find(t.text).size()>0?x.prev().find(t.text):x.prev(),C=x.children(t.menu),D=C.find(t.item),E=!1,F=this,G=x.data(w);o={initialize:function(){o.debug("Initializing dropdown",p),o.setup.layout(),o.save.defaults(),o.set.selected(),i&&o.bind.touchEvents(),o.observeChanges(),o.bind.mouseEvents(),o.bind.keyboardEvents(),o.instantiate()},instantiate:function(){o.verbose("Storing instance of dropdown",o),G=o,x.data(w,o)},destroy:function(){o.verbose("Destroying previous dropdown for",x),x.off(v).removeData(w)},observeChanges:function(){MutationObserver!==d&&(c=new MutationObserver(function(){o.debug("DOM tree modified, updating selector cache"),o.refresh()}),c.observe(F,{childList:!0,subtree:!0}),o.debug("Setting up mutation observer",c))},setup:{layout:function(){x.is("select")&&o.setup.select(),o.is.search()&&!o.is.searchable()&&(z=a("<input />").addClass(q.search).insertBefore(y)),p.allowTab&&(o.is.searchable()?(o.debug("Searchable dropdown initialized"),z.val("").attr("tabindex",0),C.attr("tabindex","-1")):(o.debug("Simple selection dropdown initialized"),x.attr("tabindex")||(x.attr("tabindex",0),C.attr("tabindex","-1"))))},select:function(){var b=o.get.selectValues();o.debug("Dropdown initialized on a select",b),A=x,A.parents(t.dropdown).size()>0?(o.debug("Creating dropdown menu only from template"),x=A.closest(t.dropdown),0===x.find("."+q.dropdown).size()&&a("<div />").addClass(q.menu).html(p.templates.menu(b)).appendTo(x)):(o.debug("Creating entire dropdown from template"),x=a("<div />").attr("class",A.attr("class")).addClass(q.selection).addClass(q.dropdown).html(p.templates.dropdown(b)).insertBefore(A),A.removeAttr("class").prependTo(x)),o.refresh()}},refresh:function(){y=x.find(t.text),z=x.find(t.search),A=x.find(t.input),C=x.children(t.menu),D=C.find(t.item)},bind:{keyboardEvents:function(){o.debug("Binding keyboard events"),x.on("keydown"+v,o.event.keydown),o.is.searchable()&&x.on(o.get.inputEvent(),t.search,o.event.input),o.is.searchSelection()?x.on("focus"+v,t.search,o.event.searchFocus).on("blur"+v,t.search,o.event.blur):x.on("mousedown",o.event.mousedown).on("mouseup",o.event.mouseup).on("focus"+v,o.event.focus).on("blur"+v,o.event.blur)},touchEvents:function(){o.debug("Touch device detected binding touch events"),o.is.searchSelection()||x.on("touchstart"+v,o.event.test.toggle),x.on("touchstart"+v,t.item,o.event.item.mouseenter).on("touchstart"+v,t.item,o.event.item.click)},mouseEvents:function(){o.verbose("Mouse detected binding mouse events"),o.is.searchSelection()||("click"==p.on?x.on("click"+v,o.event.test.toggle):"hover"==p.on?x.on("mouseenter"+v,o.delay.show).on("mouseleave"+v,o.delay.hide):x.on(p.on+v,o.toggle)),x.on("mouseenter"+v,t.item,o.event.item.mouseenter).on("mouseleave"+v,t.item,o.event.item.mouseleave).on("click"+v,t.item,o.event.item.click)},intent:function(){o.verbose("Binding hide intent event to document"),i&&g.on("touchstart"+v,o.event.test.touch).on("touchmove"+v,o.event.test.touch),g.on("click"+v,o.event.test.hide)}},unbind:{intent:function(){o.verbose("Removing hide intent event from document"),i&&g.off("touchstart"+v).off("touchmove"+v),g.off("click"+v)}},filter:function(b){var c,e=a(),f=new RegExp("(?:s|^)"+b,"i"),g=new RegExp(b,"i");D.each(function(){var b=a(this),c=b.data(r.text)!==d?b.data(r.text):p.preserveHTML?b.html():b.text(),h=b.data(r.value)!==d?b.data(r.value):"string"==typeof c?c.toLowerCase():c;f.test(c)||f.test(h)?e=e.add(b):p.fullTextSearch&&(g.test(c)||g.test(h))&&(e=e.add(b))}),c=D.not(e),D.removeClass(q.filtered).removeClass(q.selected),c.addClass(q.filtered),