mirror of
https://github.com/rembo10/headphones.git
synced 2026-03-21 04:09:26 +00:00
6 lines
2.8 KiB
JavaScript
6 lines
2.8 KiB
JavaScript
(function (a) { a.fn.selectFix = function (b) { a(this).each(function () { var d = a.extend({ extraStyles: true, responsive: false, arrow: true, arrowWidth: 20, arrowContent: "", className: "select", classText: "text", classArrow: "arrow", classFocus: "focused", classEnd: "selected", display: "inline-block" }, b); var g = "." + d.className; var k = a(this); k.css({ "-webkit-appearance": "none", "box-sizing": "border-box", "-moz-box-sizing": "border-box", "-webkit-box-sizing": "border-box", cursor: "pointer" }); var f; if (k.children("option:selected").size() > 0) { f = k.children("option:selected").eq(0).text(); } else { f = k.children("option").eq(0).text(); } var j = k.css("height"); var c = k.css("width").replace("px", ""); var h; if (d.responsive) { h = (100 * parseInt(c.replace("px", "")) / parseInt(k.parent().css("width").replace("px", ""))) + "%"; } else { h = c + "px"; } var i; var e = String(d.arrowWidth); if (e.indexOf("px") < 0 && e.indexOf("%") < 0) { e = e + "px"; } if (d.arrow == true) { i = '<span style="display: block; height: 100%; position: absolute; right: 0; width: ' + e + ';" class="' + d.classArrow + '">' + d.arrowContent + "</span>"; } else { i = ""; } k.css({ display: "block", left: 0, opacity: 0, position: "absolute", top: 0, "z-index": 1 }).wrap('<div class="' + d.className + '"style="overflow: hidden; display: ' + d.display + "; position: relative; width: " + h + ';"></div>').closest(g).append('<span style="display: block; left: 0; height: ' + j + '; line-height: inherit; position: absolute; top: 0; width: 100%;" class="' + d.classText + '">' + f + "</span>" + i); k.bind({ change: function (l) { k.siblings("." + d.classText).html(k.children("option[value=" + k.val() + "]").text()); if (d.extraStyles == true) { k.parent(g).addClass(d.classEnd).removeClass(d.classFocus); } if (k.val() == "" || k.val() == undefined || k.val() == null) { k.parent(g).removeClass(d.classEnd); } }, focus: function (l) { if (d.extraStyles == true) { k.parent(g).addClass(d.classFocus); } k.keyup(function () { k.siblings("." + d.classText).html(a(this).children("option:selected").text()); }); }, click: function () { if (d.extraStyles == true) { k.parent(g).addClass(d.classFocus); } }, blur: function () { if (d.extraStyles == true) { k.parent(g).removeClass(d.classFocus); } } }); if (a(".stlyesFor" + d.className).size() < 1) { k.after('<style type="text/css" class="stlyesFor' + d.className + '">.' + d.className + " select {width: 100%;}</style>"); } }); }; })(jQuery);
|
|
/*/////////////////////////////////////////////////////////////////////////////////
|
|
VERSION 1.3 - Updated January 4, 2011
|
|
CREATED BY KEVIN MACK
|
|
DETAILS: http://nicetransition.com/_plugins/jQuery-Cross-Browser-Select-Fix
|
|
//////////////////////////////////////////////////////////////////////////////////*/ |