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

10 years ago
  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=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),y.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)),o.allowTab&&(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(){var b=c.get.selectValues();c.debug("Dropdown initialized on a select",b),z=w,z.parents(s.dropdown).size()>0?(c.debug("Creating dropdown menu only from template"),w=z.closest(s.dropdown),0===w.find("."+p.dropdown).size()&&a("<div />").addClass(p.menu).html(o.templates.menu(b)).appendTo(w)):(c.debug("Creating entire dropdown from template"),w=a("<div />").attr("class",z.attr("class")).addClass(p.selection).addClass(p.dropdown).html(o.templates.dropdown(b)).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(c.get.inputEvent(),c.event.input),c.is.searchSelection()?y.on("focus"+u,c.event.searchFocus).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.searchSelection()||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.searchSelection()||("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");console.log(l),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(){D||c.hide()},input:function(){var a=y.val();console.log(y,a),x.addClass(p.filtered),c.filte