/* * easydropdown - a drop-down builder for styleable inputs and menus * version: 2.1.3 * license: creative commons attribution 3.0 unported - cc by 3.0 * http://creativecommons.org/licenses/by/3.0/ * this software may be used freely on commercial and non-commercial projects with attribution to the author/copyright holder. * author: patrick kunka * copyright 2013 patrick kunka, all rights reserved */ (function(d){function e(){this.isfield=!0;this.keyboardmode=this.haslabel=this.cutoff=this.disabled=this.infocus=this.down=!1;this.nativetouch=!0;this.wrapperclass="dropdown";this.onchange=null}e.prototype={constructor:e,instances:[],init:function(a,c){var b=this;d.extend(b,c);b.$select=d(a);b.id=a.id;b.options=[];b.$options=b.$select.find("option");b.istouch="ontouchend"in document;b.$select.removeclass(b.wrapperclass+" dropdown");b.$select.is(":disabled")&&(b.disabled=!0);b.$options.length&&(b.$options.each(function(a){var c= d(this);c.is(":selected")&&(b.selected={index:a,title:c.text()},b.focusindex=a);c.hasclass("label")&&0==a?(b.haslabel=!0,b.label=c.text(),c.attr("value","")):b.options.push({domnode:c[0],title:c.text(),value:c.val(),selected:c.is(":selected")})}),b.selected||(b.selected={index:0,title:b.$options.eq(0).text()},b.focusindex=0),b.render())},render:function(){var a=this;a.$container=a.$select.wrap('
').parent().parent(); a.$active=d(''+a.selected.title+"").appendto(a.$container);a.$carat=d('').appendto(a.$container);a.$scrollwrapper=d("
").appendto(a.$container);a.$dropdown=a.$scrollwrapper.find("ul");a.$form=a.$container.closest("form");d.each(a.options,function(){a.$dropdown.append(""+this.title+"")});a.$items=a.$dropdown.find("li");a.maxheight=0;a.cutoff&&a.$items.length>a.cutoff&&a.$container.addclass("scrollable"); for(i=0;ia.focusindex?a.$items.length-1:a.focusindex):40==b&&(a.focusindex++,a.focusindex=a.focusindex>a.$items.length-1?0:a.focusindex),a.down||a.open(),a.$items.removeclass("focus").eq(a.focusindex).addclass("focus"),a.cutoff&&a.scrolltoview(),a.query="";if(a.down)if(9==b||27==b)a.close();else{if(13==b)return c.preventdefault(),a.select(a.focusindex),a.close(),!1;if(8==b)return c.preventdefault(),a.query=a.query.slice(0,-1),a.search(),cleartimeout(a.resetquery), !1;38!=b&&40!=b&&(c=string.fromcharcode(b),a.query+=c,a.search(),cleartimeout(a.resetquery))}}},"keyup.easydropdown":function(){a.resetquery=settimeout(function(){a.query=""},1200)}});a.$dropdown.on("scroll.easydropdown",function(c){a.$dropdown[0].scrolltop>=a.$dropdown[0].scrollheight-a.maxheight?a.$container.addclass("bottom"):a.$container.removeclass("bottom")});if(a.$form.length)a.$form.on("reset.easydropdown",function(){a.$active.text(a.haslabel?a.label:a.options[0].title)})},unbindhandlers:function(){this.$container.add(this.$select).add(this.$items).add(this.$form).add(this.$dropdown).off(".easydropdown"); d("body").off("."+this.id)},open:function(){var a=window.scrolly||document.documentelement.scrolltop,c=window.scrollx||document.documentelement.scrollleft,b=this.notinviewport(a);this.closeall();this.$select.focus();window.scrollto(c,a+b);this.$container.addclass("open");this.$scrollwrapper.css("height",this.maxheight+"px");this.down=!0},close:function(){this.$container.removeclass("open");this.$scrollwrapper.css("height","0px");this.focusindex=this.selected.index;this.query="";this.down=!1},closeall:function(){var a= object.getprototypeof(this).instances,c;for(c in a)a[c].close()},select:function(a){"string"===typeof a&&(a=this.$select.find("option[value="+a+"]").index()-1);var c=this.options[a],b=this.haslabel?a+1:a;this.$items.removeclass("active").eq(a).addclass("active");this.$active.text(c.title);this.$select.find("option").removeattr("selected").eq(b).prop("selected",!0).parent().trigger("change");this.selected={index:a,title:c.title};this.focusindex=i;"function"===typeof this.onchange&&this.onchange.call(this.$select[0], {title:c.title,value:c.value})},search:function(){var a=this,c=function(b){a.focusindex=b;a.$items.removeclass("focus").eq(a.focusindex).addclass("focus");a.scrolltoview()};for(i=0;i=this.cutoff){var a=this.$items.eq(this.focusindex).outerheight()*(this.focusindex+ 1)-this.maxheight;this.$dropdown.scrolltop(a)}},notinviewport:function(a){var c=a+(window.innerheight||document.documentelement.clientheight),b=this.$dropdown.offset().top+this.maxheight;return b>=a&&b<=c?0:b-c+5},destroy:function(){this.unbindhandlers();this.$select.unwrap().siblings().remove();this.$select.unwrap();delete object.getprototypeof(this).instances[this.$select[0].id]},disable:function(){this.disabled=!0;this.$container.addclass("disabled");this.$select.attr("disabled",!0);this.down|| this.close()},enable:function(){this.disabled=!1;this.$container.removeclass("disabled");this.$select.attr("disabled",!1)}};var f=function(a,c){a.id=a.id?a.id:"easydropdown"+("00000"+(16777216*math.random()<<0).tostring(16)).substr(-6).touppercase();var b=new e;b.instances[a.id]||(b.instances[a.id]=b,b.init(a,c))};d.fn.easydropdown=function(){var a=arguments,c=[],b;b=this.each(function(){if(a&&"string"===typeof a[0]){var b=e.prototype.instances[this.id][a[0]](a[1],a[2]);b&&c.push(b)}else f(this,a[0])}); return c.length?1