/** bootsform */ (function ($) { function bootstigger(element, options){ var obj = element; var can = options; var rand = can.rand; var me = this; //初始化 this.init = function(){ this.mainidss = 'main_'+rand+''; if(can.namedisplay=='')can.namedisplay=''+can.name+'_text'; var s = '
'; s += ' '; s += ' '; s += ' '; if(can.clearbool){ s += ' '; } s += ' '; s += ' '; s += '
'; var s1 = '
'+s+'
'; obj.html(s1); $('#down_'+rand+'').click(function(){ me._down(this); }); if(can.clearbool){ $('#downclear_'+rand+'').click(function(){ me._downclear(this); }); } this.setDefault(can.value, can.data); this._loadbool = false; this._fistload(0);//自动加载 }; this._down = function(o1){ var o = $(o1);// if(!get(this.mainidss)){ var s = '
'; s += ''; s += ' '; s += ' '; s += '
'; s += '
'; var w = can.width; if(w==0)w = obj.width()-2; var s1 = ''; $('#div_'+rand+'').append(s1); this._showdata(can.data); js.addbody(rand, 'hide', this.mainidss); if(!this._loadbool)this._fistload(1); $('#keysou_'+rand+'').keyup(function(e){ me._soukeysss(this, e); return false; }); $('#keysoubtn_'+rand+'').click(function(){ me._soukeybtn(this); return false; }); } $('#'+this.mainidss+'').toggle(); if(get(this.mainidss).style.display!='none'){ get('keysou_'+rand+'').focus(); this._setselcol(); this._showeizhi(); } }; this._showdata = function(a){ var s = '',i,val1,s1,len = a.length; this.nowdata = a; for(i=0; i'; if(can.checked){ s+=' '; } s1= can.renderer(a[i], this); if(!s1){ s+= a[i][can.displayfields]; }else{ s+= s1; } s+= ''; } var o = $('#list_'+rand+''); o.html(s); o.find("div.div01").click(function(){ me._itemsclick(this); }); if(can.checked){ o.find("input[type='checkbox']").click(function(){ me._itemscheckclick(this); }); } var h = can.height,h1 = i*can.listheight; if(h1>h)h1 = h; o.css('height',''+h1+'px'); this._setselcol(); }; this._showeizhi= function(){ var o,jg,t; o = $('#'+this.mainidss+''); jg = $('#div_'+rand+'').offset().top+o.height()-winHb()+10; t = 33; if(jg>0)t = 0-jg; o.css('top',''+t+'px'); }; this._setselcol= function(){ var vals = this.getValue(),i,o1,val1; var o = $('#list_'+rand+'').find("div[val]"); o.removeClass(); o.addClass('div01'); var o2 = $('#list_'+rand+'').find("input[type='checkbox']"); o2.attr('checked', false); if(vals!=''){ var a = vals.split(','); for(i=0; i-1)o1.checked=true; } } }; this._cenghide = function(){ $('#'+this.mainidss+'').hide(); }; this._itemsclick = function(o1){ if(can.checked)return; var o = $(o1); var oi = parseInt(o.attr('oi')); var d = this.nowdata[oi], nae = d[can.displayfields], val = d[can.valuefields]; $('#display_'+rand+'').val(nae); $('#value_'+rand+'').val(val); $('#display_'+rand+'').focus(); can.itemsclick(d, this, oi); this._cenghide(); }; this._itemscheckclick = function(o1){ var s = js.getchecked('checkbox_'+rand+''); var nae='',val='',i,s1,d,oi; if(s!=''){ s1 = s.split(','); for(i=0;i-1){ if(!can.checked){ nae = d[can.displayfields]; break; }else{ if(oi==0)nae=''; nae+=','+d[can.displayfields]; oi++; } } } if(nae.substr(0,1)==',')nae=nae.substr(1); $('#display_'+rand+'').val(nae); $('#value_'+rand+'').val(val); }; this.getValue = function(){ return $('#value_'+rand+'').val(); }; this.getRawValue = function(){ return $('#display_'+rand+'').val(); }; this.setValue = function(val){ this.setDefault(val, can.data); }; this.setRawValue = function(v, v1){ $('#display_'+rand+'').val(v); $('#value_'+rand+'').val(v1); }; this._load = function(url){ if(isempt(url))return; if(get('list_'+rand+'')){ $('#list_'+rand+'').html('
'); } $.post(url,{key:$('#keysou_'+rand+'').val()},function(da){ var a = js.decode(da); me._loadbool = true; me._loadback(a); }); }; //搜索 this._soukeysss = function(o1, e){ var code = e.keyCode; if(code==13){ this._soukeybtn(); }else{ this._soukey(); } //38 39 40 41 //js.msg('msg',code) } this._soukey = function(){ clearTimeout(this._soukeytime); this._soukeytime = setTimeout(function(){ me._soukey1(); },300); }; this._soukey1 = function(){ var d=[],i,bo,k,d1, val = strreplace($('#keysou_'+rand+'').val()), a = can.data; if(a.length<=0 || this._oldvalue==val)return; if(!isempt(val)){ val = val.toLowerCase(); for(i=0; i10)break; d1 = a[i];bo = false; for(k in d1){ if(!isempt(d1[k])){ if(d1[k].toLowerCase().indexOf(val)==0){ bo = true;break; }}; } if(bo)d.push(d1); } }else{ d = a; } this._showdata(d); this._oldvalue = val; }; this._soukeybtn = function(){ if(can.url==''){ this._soukey(); }else{ this._fistload(1); } }; this._loadback = function(a){ this.setData(a); }; this._fistload = function(lx){ if(!can.autoLoad && lx==0 )return; if(can.url=='')return; this._load(can.url); }; this._downclear = function(){ this.setValue(''); $('#display_'+rand+'').focus(); }; this.reload = function(url){ if(!url)url = can.url; this._load(can.url); }; this.setData = function(a, naf, nafid){ can.data = a; if(get('list_'+rand+'')){ this._showdata(a); this.setValue(this.getValue()); } if(naf)can.displayfields=naf; if(nafid)can.valuefields=nafid; }; this.setDisabled = function(bo){ get('down_'+rand+'').disabled = bo; get('display_'+rand+'').disabled = bo; if(can.clearbool)get('downclear_'+rand+'').disabled = bo; }; this.hide = function(){ obj.hide(); }; this.show = function(){ obj.show(); }; this.setVisible=function(bo){ if(bo){ this.show(); }else{ this.hide(); } }; }; $.fn.bootstigger = function(options){ var defaultVal = { items:[],rand:js.getrand(),name:'',namedisplay:'',data:[], displayfields:'name',valuefields:'name', renderer:function(){return ''},listheight:38, itemsclick:function(){},height:300,width:0,placeholder:'', maxlist:1000,//最多列表数 checked:false, clearbool:false, value:'',display:'', autoLoad:false,url:'',load:function(){} }; var can = $.extend({}, defaultVal, options); clsa = new bootstigger($(this), can); clsa.init(); return clsa; }; })(jQuery);