game/scripts/wSelect.js

1 line
6.1 KiB
JavaScript
Raw Normal View History

2022-06-06 21:30:34 +00:00
/*! wSelect - v1.2.1 - 2014-04-08 */!function(a){function b(b,c){this.$el=a(b),this.id=Math.random(),this.options=c,this.multiple=this.$el.prop("multiple"),this.activeOpt=null,this.widthSet=!1,this.generate()}function c(b,c){this.$el=a(b),this.wSelect=c}b.prototype={generate:function(){if(!this.$select){var b=this;this.$select=a('<div class="wSelect"><div class="wSelect-arrow"></div></div>'),this.$optionsHolder=a('<div class="wSelect-options-holder"></div>'),this.$options=a('<div class="wSelect-options"></div>'),a.support.placeholder||this.$select.css("zIndex",100-this.$el.index());var c=function(c){c.stopPropagation(),a("select").each(function(){var c=a(this).data("wSelect");c&&c.id!==b.id&&(c.multiple||c.$optionsHolder.hide(),c.onBlur())}),b.multiple||b.onClick(c),b.$el.focus()};this.multiple?(this.$select.addClass("wSelect-multiple"),this.$optionsHolder.click(c)):(this.$selected=a('<div class="wSelect-selected"></div>'),this.$select.append(this.$selected),this.$select.click(c),this.$optionsHolder.click(function(a){a.stopPropagation(),b.$el.focus()})),this.$select.hover(function(){b.onFocus("hover")},function(){b.onBlur("hover")}),this.$el.addClass("wSelect-el").change(function(){b.change()}).focus(function(){b.onFocus()}).keydown(function(a){b.keydown(a)}).keyup(function(a){b.keyup(a)}),a(document).click(function(){b.multiple||b.$optionsHolder.hide(),b.onBlur()}),this.widthSet=this.$select.width()>0,this.setTheme(this.options.theme),this.setSize(this.options.size),this.reset(),this.$optionsHolder.append(this.$options),this.$select.append(this.$optionsHolder),this.$el.after(this.$select)}return this.$select},reset:function(){var b=this;this.$options.children().remove(),this.$el.children().each(function(){var d=new c(this,b);a.data(this,"wSelect-option",d),b.$options.append(d.generate())}),this.$options.children().removeClass("wSelect-option-last").last().addClass("wSelect-option-last"),this.setSize(this.options.size)},change:function(){this.$options.children().removeClass("wSelect-option-selected wSelect-option-active"),this.$el.children(":selected").each(function(){a(this).data("wSelect-option").select()})},keydown:function(a){9===a.keyCode&&(this.$optionsHolder.hide(),this.onBlur())},keyup:function(a){if(13===a.keyCode)this.$optionsHolder.hide();else if(a.keyCode>=37&&a.keyCode<=40){this.change();var b=this.$options.find(".wSelect-option-selected:last"),c=this.$options.scrollTop(),d=b.position().top+c,e=this.$options.height(),f=b.outerHeight(!0);0>d-c?this.$options.scrollTop(d):d+f-c>e&&this.$options.scrollTop(d-e+f)}},onClick:function(){if(!this.$optionsHolder.is(":visible")){var b=this.$select.offset().top-a(window).scrollTop(),c=this.$optionsHolder.outerHeight(),d=b-c,e=a(window).height()-(b+this.$select.outerHeight()+c+5),f=e>0||e>d?this.$select.height():-c;this.$optionsHolder.css("top",f)}this.$optionsHolder.toggle()},onFocus:function(a){a=a||"active",this.options.highlight&&this.$select.addClass("wSelect-"+a)},onBlur:function(a){a=a||"active",this.options.highlight&&this.$select.removeClass("wSelect-"+a)},setTheme:function(a){this.$select.attr("class",this.$select.attr("class").replace(/wSelect-theme-.+\s|wSelect-theme-.+$/,"")),this.$select.addClass("wSelect-theme-"+a)},setSize:function(b){var c,d=this.$options.children(":first").clone().css({position:"absolute",left:-1e4}),e=this.$el.children().length;a("body").append(d),c=d.outerHeight(!0),d.remove(),!this.multiple&&b>e&&(b=e),this.$options.height(c*b-1)}},c.prototype={generate:function(){var b=this;if(!this.$option){var c=this.$el.attr("data-icon");this.$option=a('<div class="wSelect-option"></div>'),this.$value=a('<div class="wSelect-option-value"></div>'),this.$option.append(this.$value),"string"==typeof c&&(this.$value.addClass("wSelect-option-icon"),this.$value.css("backgroundImage","url("+c+")"))}return this.$el.prop("selected")&&this.select(),this.$el.prop("disabled")?this.$option.addClass("wSelect-option-disabled"):(this.$option.removeClass("wSelect-option-disabled"),this.$option.unbind("click").click(function(a){b.onClick(a)})),this.$value.html(thi