﻿//彦磊下拉列表插件1.3(2011.1.8),插件升级：http://hi.baidu.com/dpxdqx;
//s1
try { document.execCommand('BackgroundImageCache', false, true); } catch (e) { }; (function($) { $.fn.ylDropDownList01 = function(o) { o = $.extend({ arrowUrl: "images/select_bg.gif", arrowWidth: 22, arrowHeight: 21, borderColor: "#afcbe8", dropDownListHeight: 200, hoverColor: "#b0d7ff", currItemAddStyle: true }, o || {}); var ul, lis, currItem = $("<div  />"), arrowHeight = parseInt(o.arrowHeight), arrowWidth = parseInt(o.arrowWidth), borderColor = o.borderColor, select = $(this).hide(), options = $("option", select), optionsSize = options.size(), dropDownListHeight = optionsSize * arrowHeight > parseInt(o.dropDownListHeight) ? parseInt(o.dropDownListHeight) : optionsSize * arrowHeight, getListItem = function(option) { var currText = option.text(), currClass = $.trim(option.attr("class")), currStyle = $.trim(option.attr("style")); return $("<div   />").text(currText).addClass(currClass).attr("style", currStyle); }, getSelectedItem = function() { return $("option:selected", select); }, getListItems = function() { var $ul = $("<ul class='ylDropDownUl' tabindex='0' />"); options.each(function() { var li = $("<li />"), option = $(this); li.append(getListItem(option)); $ul.append(li); }); ul = $ul; lis = $("li", ul); return $ul; }, setCurrItem = function() { currItem.empty(); if (o.currItemAddStyle) { currItem.append(getListItem(getSelectedItem())); } else { currItem.text(getSelectedItem().text()); } }, createElem = function() { select.wrap("<div  />"); select.after(getListItems()); select.after(currItem); setCurrItem(); }, setElem = function() { currItem.css({ "display": "inline-block", "padding": "0 3px", "background-image": "url(" + o.arrowUrl + ")", "line-height": arrowHeight + "px", "background-repeat": "no-repeat", "background-position": "right top", "z-index": "500", "border": "0px"  }).height(arrowHeight); ul.css({ "position": "absolute", "height": dropDownListHeight + "px", "line-height": arrowHeight + "px", "border": "0px", "border-top": "0", "padding": "0", "margin": "0", "list-style": "none", "background-color": "#fff", "z-index": "1002", "white-space": "nowrap", "overflow": "hidden", "overflow-y": "auto" }); select.parent().css({ "display": "inline-block", margin: "0 2px" }).height(25); var width = 87; ul.hide(); if ($.browser.msie && ($.browser.version == 7 || $.browser.version == 6)) { select.parent().css({ "display": "inline", "zoom": "1", "vertical-align": "middle" }) }; lis.css({ "padding-left": "4px", "padding-right": "22px", "line-height": arrowHeight + "px" }).height(arrowHeight); currItem.width(width); ul.width(width + 6); }, setScrollTop = function(index) { var visibleNum = parseInt(dropDownListHeight / arrowHeight); ul.scrollTop((index - visibleNum + 1) * arrowHeight); }, showUl = function() { $(".ylDropDownUl").hide(); var index = options.index(getSelectedItem()); lis.css("background-color", "transparent"); lis.eq(index).css("background-color", o.hoverColor); ul.show(); ul.focus(); setScrollTop(index); }, hideUl = function() { ul.hide(); }, toggleUl = function() { if (ul.css("display") == "none") { showUl(); } else { hideUl(); } }, setScroll = function(step) { var index = options.index(getSelectedItem()); index = index + step; if (index == -1) index = optionsSize - 1; currIndex = index % optionsSize; lis.eq(currIndex).mouseover(); options.eq(currIndex).attr("selected", true); setScrollTop(currIndex + 1); setCurrItem(); }, bindEvents = function() { $("html").click(function() { hideUl(); }); currItem.click(function(event) { event.stopPropagation(); toggleUl(); }).keydown(function(event) { switch (event.keyCode) { case 40: event.preventDefault(); showUl(); break; } }); ul.click(function(event) { event.stopPropagation(); }).keydown(function(event) { switch (event.keyCode) { case 38: event.preventDefault(); setScroll(-1); break; case 40: event.preventDefault(); setScroll(1); break; case 9: case 13: case 27: hideUl(); break; } }); lis.click(function(event) { event.stopPropagation(); var index = lis.index($(this)); options.eq(index).attr("selected", true); setCurrItem(); hideUl(); select.change(); }).mouseover(function() { lis.css("background-color", "transparent"); $(this).css("background-color", o.hoverColor); }); }; createElem(); setElem(); bindEvents(); return $(this); }; })(jQuery);


//s2
try { document.execCommand('BackgroundImageCache', false, true); } catch (e) { }; (function($) { $.fn.ylDropDownList02 = function(o) { o = $.extend({ arrowUrl: "images/select_bg.gif", arrowWidth: 22, arrowHeight: 21, borderColor: "#afcbe8", dropDownListHeight: 200, hoverColor: "#b0d7ff", currItemAddStyle: true }, o || {}); var ul, lis, currItem = $("<div  />"), arrowHeight = parseInt(o.arrowHeight), arrowWidth = parseInt(o.arrowWidth), borderColor = o.borderColor, select = $(this).hide(), options = $("option", select), optionsSize = options.size(), dropDownListHeight = optionsSize * arrowHeight > parseInt(o.dropDownListHeight) ? parseInt(o.dropDownListHeight) : optionsSize * arrowHeight, getListItem = function(option) { var currText = option.text(), currClass = $.trim(option.attr("class")), currStyle = $.trim(option.attr("style")); return $("<div   />").text(currText).addClass(currClass).attr("style", currStyle); }, getSelectedItem = function() { return $("option:selected", select); }, getListItems = function() { var $ul = $("<ul class='ylDropDownUl' tabindex='0' />"); options.each(function() { var li = $("<li />"), option = $(this); li.append(getListItem(option)); $ul.append(li); }); ul = $ul; lis = $("li", ul); return $ul; }, setCurrItem = function() { currItem.empty(); if (o.currItemAddStyle) { currItem.append(getListItem(getSelectedItem())); } else { currItem.text(getSelectedItem().text()); } }, createElem = function() { select.wrap("<div  />"); select.after(getListItems()); select.after(currItem); setCurrItem(); }, setElem = function() { currItem.css({ "display": "inline-block","padding": "0 3px", "background-image": "url(" + o.arrowUrl + ")", "line-height": arrowHeight + "px", "background-repeat": "no-repeat", "background-position": "right top", "z-index": "1000", "border": "0px"  }).height(arrowHeight); ul.css({ "position": "absolute", "height": dropDownListHeight + "px", "line-height": arrowHeight + "px", "border": "0px", "border-top": "0", "padding": "0", "margin": "0", "list-style": "none", "background-color": "#fff", "z-index": "501", "white-space": "nowrap", "overflow": "hidden", "overflow-y": "auto" }); select.parent().css({ "display": "inline-block", margin: "0 2px" }).height(25); var width = ul.width() + 1; ul.hide(); if ($.browser.msie && ($.browser.version == 7 || $.browser.version == 6)) { select.parent().css({ "display": "inline", "zoom": "1", "vertical-align": "middle" }) }; lis.css({ "padding-left": "4px", "padding-right": "22px", "line-height": arrowHeight + "px" }).height(arrowHeight); currItem.width(width); ul.width(width + 6); }, setScrollTop = function(index) { var visibleNum = parseInt(dropDownListHeight / arrowHeight); ul.scrollTop((index - visibleNum + 1) * arrowHeight); }, showUl = function() { $(".ylDropDownUl").hide(); var index = options.index(getSelectedItem()); lis.css("background-color", "transparent"); lis.eq(index).css("background-color", o.hoverColor); ul.show(); ul.focus(); setScrollTop(index); }, hideUl = function() { ul.hide(); }, toggleUl = function() { if (ul.css("display") == "none") { showUl(); } else { hideUl(); } }, setScroll = function(step) { var index = options.index(getSelectedItem()); index = index + step; if (index == -1) index = optionsSize - 1; currIndex = index % optionsSize; lis.eq(currIndex).mouseover(); options.eq(currIndex).attr("selected", true); setScrollTop(currIndex + 1); setCurrItem(); }, bindEvents = function() { $("html").click(function() { hideUl(); }); currItem.click(function(event) { event.stopPropagation(); toggleUl(); }).keydown(function(event) { switch (event.keyCode) { case 40: event.preventDefault(); showUl(); break; } }); ul.click(function(event) { event.stopPropagation(); }).keydown(function(event) { switch (event.keyCode) { case 38: event.preventDefault(); setScroll(-1); break; case 40: event.preventDefault(); setScroll(1); break; case 9: case 13: case 27: hideUl(); break; } }); lis.click(function(event) { event.stopPropagation(); var index = lis.index($(this)); options.eq(index).attr("selected", true); setCurrItem(); hideUl(); select.change(); }).mouseover(function() { lis.css("background-color", "transparent"); $(this).css("background-color", o.hoverColor); }); }; createElem(); setElem(); bindEvents(); return $(this); }; })(jQuery);


//s3
try { document.execCommand('BackgroundImageCache', false, true); } catch (e) { }; (function($) { $.fn.ylDropDownList03 = function(o) { o = $.extend({ arrowUrl: "images/select_bg.gif", arrowWidth: 22, arrowHeight: 21, borderColor: "#afcbe8", dropDownListHeight: 200, hoverColor: "#b0d7ff", currItemAddStyle: true }, o || {}); var ul, lis, currItem = $("<div  />"), arrowHeight = parseInt(o.arrowHeight), arrowWidth = parseInt(o.arrowWidth), borderColor = o.borderColor, select = $(this).hide(), options = $("option", select), optionsSize = options.size(), dropDownListHeight = optionsSize * arrowHeight > parseInt(o.dropDownListHeight) ? parseInt(o.dropDownListHeight) : optionsSize * arrowHeight, getListItem = function(option) { var currText = option.text(), currClass = $.trim(option.attr("class")), currStyle = $.trim(option.attr("style")); return $("<div   />").text(currText).addClass(currClass).attr("style", currStyle); }, getSelectedItem = function() { return $("option:selected", select); }, getListItems = function() { var $ul = $("<ul class='ylDropDownUl' tabindex='0' />"); options.each(function() { var li = $("<li />"), option = $(this); li.append(getListItem(option)); $ul.append(li); }); ul = $ul; lis = $("li", ul); return $ul; }, setCurrItem = function() { currItem.empty(); if (o.currItemAddStyle) { currItem.append(getListItem(getSelectedItem())); } else { currItem.text(getSelectedItem().text()); } }, createElem = function() { select.wrap("<div  />"); select.after(getListItems()); select.after(currItem); setCurrItem(); }, setElem = function() { currItem.css({ "display": "inline-block", "padding": "0 3px", "background-image": "url(" + o.arrowUrl + ")", "line-height": arrowHeight + "px", "background-repeat": "no-repeat", "background-position": "right top", "z-index": "1000", "border": "0px"  }).height(arrowHeight); ul.css({ "position": "absolute", "height": dropDownListHeight + "px", "line-height": arrowHeight + "px", "border": "0px", "border-top": "0", "padding": "0", "margin": "0", "list-style": "none", "background-color": "#fff", "z-index": "501", "white-space": "nowrap", "overflow": "hidden", "overflow-y": "auto" }); select.parent().css({ "display": "inline-block", margin: "0 2px" }).height(25); var width = ul.width() + 1; ul.hide(); if ($.browser.msie && ($.browser.version == 7 || $.browser.version == 6)) { select.parent().css({ "display": "inline", "zoom": "1", "vertical-align": "middle" }) }; lis.css({ "padding-left": "4px", "padding-right": "22px", "line-height": arrowHeight + "px" }).height(arrowHeight); currItem.width(width + 12); ul.width(width + 6); }, setScrollTop = function(index) { var visibleNum = parseInt(dropDownListHeight / arrowHeight); ul.scrollTop((index - visibleNum + 1) * arrowHeight); }, showUl = function() { $(".ylDropDownUl").hide(); var index = options.index(getSelectedItem()); lis.css("background-color", "transparent"); lis.eq(index).css("background-color", o.hoverColor); ul.show(); ul.focus(); setScrollTop(index); }, hideUl = function() { ul.hide(); }, toggleUl = function() { if (ul.css("display") == "none") { showUl(); } else { hideUl(); } }, setScroll = function(step) { var index = options.index(getSelectedItem()); index = index + step; if (index == -1) index = optionsSize - 1; currIndex = index % optionsSize; lis.eq(currIndex).mouseover(); options.eq(currIndex).attr("selected", true); setScrollTop(currIndex + 1); setCurrItem(); }, bindEvents = function() { $("html").click(function() { hideUl(); }); currItem.click(function(event) { event.stopPropagation(); toggleUl(); }).keydown(function(event) { switch (event.keyCode) { case 40: event.preventDefault(); showUl(); break; } }); ul.click(function(event) { event.stopPropagation(); }).keydown(function(event) { switch (event.keyCode) { case 38: event.preventDefault(); setScroll(-1); break; case 40: event.preventDefault(); setScroll(1); break; case 9: case 13: case 27: hideUl(); break; } }); lis.click(function(event) { event.stopPropagation(); var index = lis.index($(this)); options.eq(index).attr("selected", true); setCurrItem(); hideUl(); select.change(); }).mouseover(function() { lis.css("background-color", "transparent"); $(this).css("background-color", o.hoverColor); }); }; createElem(); setElem(); bindEvents(); return $(this); }; })(jQuery);
