﻿/**
* Stylish Select 0.4.5 - jQuery plugin to replace a select drop down box with a stylable unordered list
* http://github.com/sko77sun/Stylish-Select
* 
* Requires: jQuery 1.3 or newer
* 
* Contributions from Justin Beasley: http://www.harvest.org/ Anatoly Ressin: http://www.artazor.lv/ Wilfred Hughes: https://github.com/Wilfred
* 
* Dual licensed under the MIT and GPL licenses.
*/
(function(a) { a("html").addClass("stylish-select"); if (!Array.prototype.indexOf) Array.prototype.indexOf = function(a) { if (this === void 0 || this === null) throw new TypeError; var n = Object(this), j = n.length >>> 0; if (j === 0) return -1; var b = 0; arguments.length > 0 && (b = Number(arguments[1]), b !== b ? b = 0 : b !== 0 && b !== 1 / 0 && b !== -(1 / 0) && (b = (b > 0 || -1) * Math.floor(Math.abs(b)))); if (b >= j) return -1; for (b = b >= 0 ? b : Math.max(j - Math.abs(b), 0); b < j; b++) if (b in n && n[b] === a) return b; return -1 }; a.fn.extend({ getSetSSValue: function(m) { return m ? (a(this).val(m).change(), this) : a(this).find(":selected").val() }, resetSS: function() { var m = a(this).data("ssOpts"); $this = a(this); $this.next().remove(); $this.unbind(".sSelect").sSelect(m) } }); a.fn.sSelect = function(m) { return this.each(function() { function n() { var h = d.offset().top, c = a(window).height(), b = a(window).scrollTop(); k > parseInt(o.ddMaxHeight) && (k = parseInt(o.ddMaxHeight)); h -= b; h + k >= c ? (f.css({ height: k }), i.css({ top: "-" + k + "px", height: k }), e.onTop = !0) : (f.css({ height: k }), i.css({ top: s + "px", height: k }), e.onTop = !1) } function j(a, x) { a == !0 && (p = c, e.change()); x == !0 && (c = p, b(c)); i.hide(); d.css({ position: "static" }) } function b(a, c) { if (a == -1) l.text(o.defaultText), g.removeClass("hiLite"); else { g.removeClass("hiLite").eq(a).addClass("hiLite"); var b = g.eq(a).text(), d = g.eq(a).parent().data("key"); try { e.val(d) } catch (f) { e[0].selectedIndex = a } l.text(b); c == !0 && (p = a, e.change()); i.is(":visible") && g.eq(a).focus() } } function t(h) { a(h).unbind("keydown.sSelect").bind("keydown.sSelect", function(a) { a = a.which; r = !0; switch (a) { case 40: case 39: return c < u - 1 && (++c, b(c)), !1; case 38: case 37: return c > 0 && (--c, b(c)), !1; case 33: case 36: return c = 0, b(c), !1; case 34: case 35: return c = u - 1, b(c), !1; case 13: case 27: return j(!0), !1 } keyPressed = String.fromCharCode(a).toLowerCase(); if (typeof q.indexOf(keyPressed) != "undefined") { ++c; c = q.indexOf(keyPressed, c); if (c == -1 || c == null || v != keyPressed) c = q.indexOf(keyPressed); b(c); v = keyPressed; return !1 } }) } var o = a.extend({ defaultText: "Please select", animationSpeed: 0, ddMaxHeight: "", containerClass: "" }, m), e = a(this), l = a('<div class="selectedTxt"></div>'), d = a('<div class="newListSelected ' + o.containerClass + '"></div>'), i = a('<div class="SSContainerDivWrapper" style="visibility:hidden;"></div>'), f = a('<ul class="newList"></ul>'), w = -1, c = -1, p = -1, q = [], v = !1, r = !1, g; a(this).data("ssOpts", m); d.insertAfter(e); d.attr("tabindex", e.attr("tabindex") || "0"); l.prependTo(d); f.appendTo(d); f.wrap(i); i = f.parent(); e.hide(); l.data("ssReRender", !l.is(":visible")); e.children("optgroup").length == 0 ? (e.children().each(function(b) { var d = a(this).text(), e = a(this).val(); q.push(d.charAt(0).toLowerCase()); if (a(this).attr("selected") == "selected" || a(this).attr("selected") == !0) o.defaultText = d, c = p = b; f.append(a('<li><a href="JavaScript:void(0);">' + d + "</a></li>").data("key", e)) }), g = f.children().children()) : (e.children("optgroup").each(function() { var b = a(this).attr("label"), b = a('<li class="newListOptionTitle">' + b + "</li>"), d = a("<ul></ul>"); b.appendTo(f); d.appendTo(b); a(this).children().each(function() { ++w; var b = a(this).text(), h = a(this).val(); q.push(b.charAt(0).toLowerCase()); if (a(this).attr("selected") == "selected" || a(this).attr("selected") == !0) o.defaultText = b, c = p = w; d.append(a('<li><a href="JavaScript:void(0);">' + b + "</a></li>").data("key", h)) }) }), g = f.find("ul li a")); var k = f.height(), s = d.height(), u = g.length; c != -1 ? b(c) : l.text(o.defaultText); n(); a(window).bind("resize.sSelect scroll.sSelect", n); l.bind("click.sSelect", function(b) { b.stopPropagation(); a(this).data("ssReRender") && (k = f.height("").height(), i.height(""), s = d.height(), a(this).data("ssReRender", !1), n()); a(".SSContainerDivWrapper").not(a(this).next()).hide().parent().css("position", "static").removeClass("newListSelFocus"); i.toggle(); d.css("position", "relative"); c == -1 && (c = 0); g.eq(c).focus() }); g.bind("click.sSelect", function(h) { h = a(h.target); c = g.index(h); r = !0; b(c, !0); j() }); g.bind("mouseenter.sSelect", function(b) { a(b.target).addClass("newListHover") }).bind("mouseleave.sSelect", function(b) { a(b.target).removeClass("newListHover") }); e.bind("change.sSelect", function(d) { d = a(d.target); if (r == !0) return r = !1; var e = d.find(":selected"); c = d.find("option").index(e); b(c) }); d.bind("click.sSelect", function(a) { a.stopPropagation(); t(this) }); d.bind("focus.sSelect", function() { a(this).addClass("newListSelFocus"); t(this) }); d.bind("blur.sSelect", function() { a(this).removeClass("newListSelFocus") }); a(document).bind("click.sSelect", function() { d.removeClass("newListSelFocus"); i.is(":visible") ? j(!1, !0) : j(!1) }); l.bind("mouseenter.sSelect", function(b) { a(b.target).parent().addClass("newListSelHover") }).bind("mouseleave.sSelect", function(b) { a(b.target).parent().removeClass("newListSelHover") }); i.css({ left: "0", display: "none", visibility: "visible" }) }) } })(jQuery);

