1 |
- UI.extend.htmlSelect=function(option){var opt={type:this.getAttribute("type")||1,skip:this.getAttribute("skip")||"orange"};opt=$.extend(opt,option);var first=$(this).find("option").first();var arr=$(this).find("option");var templeteHtml="";var clickSelector="";var className="";if(opt.skip=="orange"){className="_orange"}switch(parseInt(opt.type)){case 1:var str="";for(var i=1;i<arr.length;i++){var n=arr.eq(i);var attr="";var on="";$.each(n[0].attributes,function(){if(!/^(onclick|class)$/.test(this.name)){attr+=" "+this.name+"='"+this.value+"'"}});if(n.attr("checked")){attr+=' class="checked"';on="sure_icon_on"}str+="<li "+attr+'><a href="javascript:void(0)">'+n.html()+'<i class="icon_skin sure_icon '+on+'"></i></a></li>'}templeteHtml='<span click style="cursor:pointer;width:100%;">'+first.html()+'</span><i class="icon_skin show_select_arrow'+className+'" click></i>'+' <div class="show_listbox'+className+'" style="display:none;">'+" <ul>"+str+" </ul>"+" </div>";var pt=$(this).parent();var change=this.onchange;var id=this.id;var name=this.name;$(this).replaceWith("<div class='htmlSelect' id='"+id+"' name='"+name+"' type='1'>"+templeteHtml+"</div>");var make=pt.find("[click]");make.mousedown(function(){$("ul[type=2]").hide();return false}).click(function(){var list=$(this).nextAll(".show_listbox");list.toggle(150);if($(window).height()-20<list.offset().top+list.height()){list.css("top",-list.height()-5)}}).next().find("li").click(function(){var i=$(this).find("i").toggleClass("sure_icon_on");this.className=i.hasClass("sure_icon_on")?"checked":"";change&&change.call(this)});break;case 2:var str="";for(var i=1;i<arr.length;i++){var n=arr.eq(i);var attr="";$.each(n[0].attributes,function(){if(!/^(onclick|class)$/.test(this.name)){attr+=" "+this.name+"='"+this.value+"'"}});if(n.attr("onclick")){attr+=' onclick="this.ismousedown=true;'+n.attr("onclick")+';"'}str+="<li "+attr+">"+n.html()+"</li>"}var id=this.id||"";templeteHtml='<div class="select_box'+className.substring(1)+'"><span click style="cursor:pointer;width:100%;display:inline-block;">'+first.html()+"</span>"+' <span class="icon_skin select_arrow'+className+'" click></span>'+' <ul class="select_listvalue" style="display:none" id="'+id+'" type=2 >'+str+" </ul>"+" </div>";var pt=$(this).parent();var change=this.onchange;$(this).replaceWith("<div class='htmlSelect' type='2'>"+templeteHtml+"</div>");var make=pt.find("[click]");make.mousedown(function(){}).click(function(){var list=$(this).nextAll(".select_listvalue");list.toggle();if(list.find("li").length==0){return}if($(window).height()-20<list.offset().top+list.height()){list.css("top",-list.height()-5)}}).next().delegate("li","click",function(){if(this.ismousedown){return}make.nextAll(".select_listvalue").hide();change&&change.call(this)});break;case 3:var str="";var selValue="";for(var i=0;i<arr.length;i++){var n=arr.eq(i);var attr="";$.each(n[0].attributes,function(){if(!/^(onclick|class)$/.test(this.name)){attr+=" "+this.name+"='"+this.value+"'"}});if(n.attr("checked")){attr+=' checked="true"';selValue=n.html()}str+="<li "+attr+">"+n.html()+"</li>"}templeteHtml='<div class="inputbg_focus pad_none set_typeinput"><input type="text" '+(selValue=="自定义"?"":"readonly")+' value="'+selValue+'">'+' <div class="listbox dn" style="width:100%;display: none;">'+" <ul>"+str+" </ul>"+" </div>"+' <i class="icon_skin inputbg_rt_downarrow" click></i>'+"</div>";var pt=$(this).parent();var change=this.onchange;var className=this.className;$(this).replaceWith("<div class='"+className+"'>"+templeteHtml+"</div>");var make=pt.find("[click]");pt.find("input").click(function(){$(this).next().toggle()});make.click(function(){$(this).prev().toggle();var input=$(this).prev().prev();if($(this).prev().is(":visible")){input.focus()}return false}).prev().prev().blur(function(){var elt=this;setTimeout(function(){$(elt).next().hide()},100)}).next().find("li").mousedown(function(){$(this).parent().parent().hide().prev().val(this.innerHTML);change&&change.call(this)});break}};$(document).mousedown(function(e){var obj=e.srcElement||e.target;var main=$(".htmlSelect ul:visible");if(main.length==0){return}var m=main.parent().parent()[0];if(m.contains(obj)||m==obj){return}if($(obj).parents(".type_showselect").length>0||$(obj).parents(".show_select").length>0){return}main.each(function(){if(!$(this).attr("class")){$(this).parent().hide()}else{$(this).hide()}})});
|