/** * Делаем автозамену селектов для ие. * Пока что так - некрасиво- будет время - оформим. :( */ $(document).ready(function(){ if( $.browser.msie ){ $('select').hide().each( function( i, elem ){ elem = $(elem); sID = elem.attr('id') + '__customSelect'; if( elem.attr('id') == 'select-search' ){ iClientWidth = '241px'; sPicture = 'http://softline.ru/legalboss/js/customselect/select_small.gif'; }else{ iClientWidth = '321px'; sPicture = 'http://softline.ru/legalboss/js/customselect/select.gif'; }; tmpstr = $('option:selected', elem ).text(); if( tmpstr.length > 46 ) tmpstr=tmpstr.substring(0,46)+'...'; finalSelect = elem.parent().prepend('
').children('.selectHandler').finalselect({ id: sID, zIndex: 100, animalSpeed: 0, viewWidth: 'auto', viewHeight: 'auto', selectText: tmpstr, defaultValue: elem.val(), selectName: elem.attr('name') + '__customSelect', selectWidth: iClientWidth, selectImage: sPicture, viewTop:"24px",//top,bottom viewLeft:"0"//left,right }); options = $('option', elem); $('option', elem).each(function(j, item){ item = $(item); finalSelect.addItem( ''+item.text()+'', item.val() ); }); }); $('a.close').click(function(){ $('#select-client__customSelect-select').show(); }); $('a#showdesc-terminal').click(function(){ if( $('#showdesc-terminal').parent().children('.info').css('display') == 'block' ){ $('#select-client__customSelect-select').hide(); }else{ $('#select-client__customSelect-select').show(); }; }); } }); $(document).ready(function(){ $(document.body).click(function(){ $('.SlCustomSelect').hide(); $('.SlCustomSelectI').parent().removeClass("hover"); }); }); $(document).ready(function(){ $(".SlCustomSelectI").click( function () { $(this).parent().addClass("hover"); }); }); //select表示select本身,view表示跳出的選項 (function($){ $.fn.extend({ //計算文字Byte數,並回傳 getByteLength: function(strIN){ var i, cnt=0; for (i=0; i= 4) cnt+=2; else cnt++; } return cnt; } }); $.fn.extend({ //檢查文字的Byte數,超過limit指定的個數的話,就回傳true 和 未超過之前的文字index getIndexByByte: function(strIN,limit){ var i, cnt=0; for (i=0; i= 4) cnt+=2; else cnt++; if(cnt>limit) { return [true,i]; } } return false; } }); $.fn.extend({ finalselect: function(options) { var settings = { id:null, animalSpeed:100, selectWidth:"190px", selectImage:"image/select.png", selectText:"My friend", defaultValue: 0, selectName: 'SlInput', zIndex: 0, viewHeight:"100px", viewWidth:"300px", viewMouseoverColor:"#cfdfff",//#dcdcdc viewTop:"28px",//top,bottom viewLeft:" -1px"//left,right }; if (typeof(options)!='undefined') { //將整批options的值assign給settings jQuery.extend(settings, options); } var tmp='
' tmp+='
'; tmp+='
'+settings.selectText+'
'; var _handler = function() { // 從這裡開始 $(this).html(tmp); bindArrowClick(); bindSelectMouseover(); bindSelectMouseleave(); }; var bindArrowClick=function(){ var tmp=$('#'+settings.id+'-Text'); $("#"+settings.id+'-Text').bind("click", function(e){ var obj=$('#'+settings.id+'-selectshow'); if(obj.css('display')=='none') { $('.SlCustomSelect').hide(); // obj.slide(); obj.slideDown(settings.animalSpeed,function(){ obj.show(); }); } else { obj.slideUp(settings.animalSpeed,function(){ obj.hide(); }); } window.maxWidth = 0; obj.children('.selectitem').each( function(n, item){ if(window.maxWidth < $(item).width()) window.maxWidth = $(item).width(); } ); if( window.maxWidth > 0 ) obj.children('.selectitem').width( window.maxWidth ); return false; }); }; var bindItemMouseover=function(){ var inx=0; while($(".selectitem",$("#"+settings.id+"-selectshow")).get(inx)!=null) { var item=$(".selectitem",$("#"+settings.id+"-selectshow")).get(inx); $(item).bind("mouseover", function(e){ $(this).css('background-color',settings.viewMouseoverColor); }); $(item).bind("mouseout", function(e){ $(this).css('background-color','#fff'); }); $(item).bind("click", function(e){ var tmpstr=$(".thistext",$(this)).html(); /*var arr=$().getIndexByByte(tmpstr,50); if(arr[0]==true)*/ if( tmpstr.length > 46 ) tmpstr=tmpstr.substring(0,46)+'...'; //var tmpstr = $( '.thistext', $(this) ).html(); $(".textshow",$("#"+settings.id+"-Text")).html(tmpstr); document.getElementById(settings.id+'-selectshow').style.display="none"; $(".valueshow",$("#"+settings.id+"-Text")).html($(".selectvalue",$(this)).html()); value = $( ".selectvalue", $(this) ).html() $("#"+settings.id+"-input").val( value ); $(this).parents('.s-inner').children('select').val( value ).change(); //console.log($(this).parents('.s-inner').children('select').length); }); inx++; } } var bindSelectMouseover=function(){ $('#'+settings.id+'-Text').bind("mouseover",function(){ //if($.browser.msie==false) $('#'+settings.id+'-Text').css("background-position","0 -22px"); }); } var bindSelectMouseleave=function(){ $('#'+settings.id+'-Text').bind("mouseout",function(){ //if($.browser.msie==false) $('#'+settings.id+'-Text').css("background-position","0 0px"); }); } this.setViewTop = function(top){ $('#'+settings.id+'-selectshow').css('top',top+'px'); } this.setViewLeft = function(left){ $('#'+settings.id+'-selectshow').css('left',left+'px'); } this.getLength = function(){ return $('.selectitem',$('#'+settings.id+'-selectshow')).length; } //add item到select裡面 //在傳itemtext時,用包起要顯示的 "文字" //例如:哇哈哈,這樣select選擇後,就會顯示 "哇哈哈" this.addItem = function(itemtext,itemvalue){ var itemhtml='
'+itemtext +'
'+itemvalue+'
'; $("#"+settings.id+'-selectshow').html($("#"+settings.id+'-selectshow').html()+itemhtml); bindItemMouseover(); }; this.removeItem = function(index){ if($('.selectitem',$('#'+settings.id+'-selectshow')).length>index) $($('.selectitem',$('#'+settings.id+'-selectshow')).get(index)).remove(); if($('.selectborder',$('#'+settings.id+'-selectshow')).length>index) $($('.selectborder',$('#'+settings.id+'-selectshow')).get(index)).remove(); } this.getValue = function(){ return $('.valueshow',$('#'+settings.id+'-Text')).html(); } this.getText = function(){ return $('.textshow',$('#'+settings.id+'-Text')).html(); } return this.each(_handler); } }); })(jQuery);