(function($){var base=$.fn.input.methods;$.fn.label=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);$.fn.input.apply(this,arguments);this.skin.parse({removeHTML:false,valueFormat:null,lang:false});this.initSkin=function(){this.skin.autoCreateStore=false;base.initSkin.call(this);this.skin.css+=" label";this.skin.html='
';this.skin.value=this.skin.value||this.html()};this.initHandler=function(){this.$text=this.$value=$(this.find(".box").children(0));if(this.skin.removeHTML){this.$value.val=function(){if(arguments.length==0)return this[0].innerText;else this.html(arguments[0])}}else this.$value.val=this.$value.html;base.initHandler.call(this)};this.set=function(v){if(this.skin.valueFormat)v=this.skin.valueFormat(v);if(this.skin.lang)v=ke.ui.lang(v);base.set.call(this,v)};this.disable=function(){};return this};$.fn.hidden=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);this._extend($.fn.input,arguments);this.initSkin=function(){base.initSkin.call(this);this.isHidden=true;this.skin.hidden=true;this.skin.width=1;this.skin.height=1;this.skin.html=''};this.initHandler=function(){this.$text=this.$value=this.find("input[type='hidden']");base.initHandler.call(this)};return this};$.fn.textbox=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);$.fn.input.apply(this,arguments);var sk=this.skin;this.skin.parse({multiline:false,multilineAutoHeight:false,password:false});if(!sk.placeholder&&!sk.readonly)sk.placeholder=ke.ui.lang("请输入")+(sk.multilineAutoHeight?" "+ke.ui.lang("支持换行"):"");this.initSkin=function(){base.initSkin.call(this);this.skin.css+=" textbox";if(sk.multiline||sk.multilineAutoHeight){sk.html="";sk.css+=sk.multiline?" textbox-multiline":" textbox-multiline-auto"}else{sk.html=''}};this.initHandler=function(){this.$text=this.$value=$(this.find(".box").children(0));if(sk.multilineAutoHeight){this.$text.keyup(this,function(e){e.data.autoHeight()})}if(ke.ui.mobile){if(this.store){this.find(".box").append('');this.find(".icon-btn").click(this,function(e){e.data.showLayer()})}else{this.find(".icon-btn").click(this,function(e){e.data.focus()})}}base.initHandler.call(this)};this.autoHeight=function(){this.$text[0].style.height="auto";var h=this.$text[0].scrollHeight;if(h<16)h=((this.$text.val().match(new RegExp("\n","g"))||[]).length+1)*16;this.$text.height(h)},this.set=function(v){base.set.call(this,v);if(sk.multilineAutoHeight)this.autoHeight()};return this};$.fn.numberbox=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);$.fn.input.apply(this,arguments);var sk=this.skin;if(!sk.placeholder&&!sk.readonly)this.skin.placeholder=ke.ui.lang("请输入数字");this.initSkin=function(){base.initSkin.call(this);sk.type=ke.types.float;sk.reg=/^[\+\-]?\d*?\.?\d{0,8}?$/;sk.css+=" numberbox";sk.html=''};this.initHandler=function(){this.$value=this.find("input[type='number']");this.$text=this.find("input[type='number']");base.initHandler.call(this);this.$text.bind("focus",this,function(e){e.data.$text.val(e.data.format())});this.$text.blur(this,function(e){e.data.set(e.data.format(null,true))})};this.format=function(v,formatLast){v=v||this.$text.val();var r="";for(var i=0;i=48&&ch<=57||ch==46&&v.indexOf(".")==i||ch==45&&v.indexOf("-")==i)r+=v[i]}return r};return this};$.fn.combobox=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);$.fn.input.apply(this,arguments);var sk=this.skin;if(!sk.placeholder&&!sk.readonly)sk.placeholder=ke.ui.lang("请选择");this.initSkin=function(){base.initSkin.call(this);$.extend(sk.layerOptions,{bodyCls:"combobox-layer",minWidth:this.skin.layerOptions.minWidth||80,allowOverflow:false});sk.css+=" combobox";var cls="icon-down";if(ke.ui.mobile){cls="icon-right"}sk.html='';sk.valueInStore=true};this.initHandler=function(){base.initHandler.call(this);this.$value=this.find("input[type='hidden']");this.$text=this.find("input[type='text']");this.$text.change(this,function(e){if(!e.data.$value.val())e.data.set(null)});this.find(".icon-btn").click(this,function(e){e.data.showLayer()});this.$text.keyup(this,function(e){if(e.which!=9){if(e.which==46){e.data.set(null)}e.data.$value.val("");e.data.showLayer(e.data.$text.val())}})};this.set=function(v){base.set.call(this,v);this.$text.val(this.selectedRows.joinField(this.skin.textField,this.skin.separator))};return this};$.fn.checkbox=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);$.fn.input.apply(this,arguments);this.initSkin=function(){base.initSkin.call(this);this.skin.parse({switch:false});this.skin.outputAttr=true;if(this.skin.switch){this.skin.css+=" switch-checkbox unselect";this.skin.html=''}else{this.skin.css+=" checkbox unselect";this.skin.html=''}};this.initHandler=function(){this.$value=this.find("input[type='hidden']");var fn=function(e){e.data.click();e.data.change()};if(!this.skin.switch){this.$text=this.children("label");this.find(".checkbox-rect").bind("click",this,fn);this.$text.bind("click",this,fn)}else{this.$text=this.$value;this.find(".switch-checkbox-bar").bind("click",this,fn);this.find(".switch-checkbox-point").bind("click",this,fn)}};this.setTitle=function(val){if(!this.skin.switch)this.$text.html(ke.ui.lang(val));else base.setTitle.call(this,val)};this.click=function(){this.set(this.get()!="1")},this.set=function(v){if(v=="1"||v===true){this.addClass("checkbox-selected");v=1}else{this.removeClass("checkbox-selected");v=0}base.set.call(this,v)};return this};$.fn.triggerbox=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);$.fn.input.apply(this,arguments);if(!this.skin.placeholder)this.skin.placeholder=ke.ui.lang(this.skin.readonly?"请选择":"请输入或选择");this.initSkin=function(){base.initSkin.call(this);this.skin.parse({textAppend:null});this.skin.css+=" triggerbox";var htm='';htm+='
';this.skin.html=htm};this.initHandler=function(){base.initHandler.call(this);this.$text=this.find("input[type='text']");if(this.skin.textAppend)this.$value=this.find("input[type='hidden']");else this.$value=this.$text;this.find(".icon-zoom").click(this,function(e){e.data.triggerClick()})};this.triggerClick=function(){ke.bindOrTrriger(this,"triggerClick",arguments)};this.set=function(v){base.set.call(this,v);if(this.skin.textAppend)v+=" "+this.skin.textAppend.get();this.$text.val(v)};return this};$.fn.datebox=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);this.ymd=[];$.fn.input.apply(this,arguments);if(!this.skin.placeholder)this.skin.placeholder=ke.ui.lang(this.skin.readonly?"请选择":"请输入或选择");this.initSkin=function(){base.initSkin.call(this);this.skin.css+=" datebox";this.skin.reg=/[\d]{4,4}[-]{1}[\d]{1,2}[-]{1}[\d]{1,2}/g;this.skin.layerOptions.syncOwnerWidth=false;this.skin.layerOptions.bodyCls="date-layer";this.skin.layerOptions.height=400;this.skin.html=''};this.initHandler=function(){this.$value=this.find("input[type='text']");this.$text=this.find("input[type='text']");base.initHandler.call(this);this.find(".icon-btn").click(this,function(e){e.data.showLayer()});this.bind("layerShowBefore",this,function(e){if(e.data.get()!="")e.data.ymd=ke.getYMD(e.data.get());else e.data.ymd=ke.getYMD(new Date)});this.unbind("layerShowAfter").bind("layerShowAfter",this,function(e){datePickerHandler(e.data)});this.$text.mouseup(this,function(e){autoSelectTxt(e.target)});this.change(this,function(e){var txt=ke.getDate(e.data.$value.val());if(!txt||isNaN(txt.getTime()))e.data.set(null);else e.data.set(txt)})};function datePickerHandler(c){var lay=c.layerCompnent;lay.find(".icon-btn").click(function(e){var obj=$(e.target);if(obj.hasClass("icon-left"))c.addMonth(-1,0);else if(obj.hasClass("icon-backward"))c.addMonth(0,-1);else if(obj.hasClass("icon-right"))c.addMonth(1,0);else if(obj.hasClass("icon-forward"))c.addMonth(0,1)});lay.find(".date-days div").click(function(cell){c.select($(cell.target).attr("data-value"));c.change()});lay.find(".data-select-header .fll").click(function(e){c.layerHide()})}function autoSelectTxt(dom){var val=dom.value;var s=dom.selectionStart;if(val){if(s<=5){dom.selectionStart=0;dom.selectionEnd=4}else if(s>5&&s<=7){dom.selectionStart=5;dom.selectionEnd=7}else if(s>=8){dom.selectionStart=8;dom.selectionEnd=val.length}}}this.select=function(v){this.set(v);this.layerHide()};this.set=function(v){this.$value.val(ke.getDateTip(v));this.validate()};this.get=function(type){type=type||this.skin.type;if(type==ke.types.int){return ke.getTimeSpan(this.$value.val())||""}else return this.$value.val()};this.addMonth=function(m,y){this.ymd[1]+=m;this.ymd[0]+=y;if(this.ymd[1]<1){this.ymd[1]=12;this.ymd[0]-=1}else if(this.ymd[1]>12){this.ymd[1]=1;this.ymd[0]+=1}this.layerCompnent.loadHtml(this.layerHtml());this.layerCompnent.show();datePickerHandler(this)};this.today=function(){this.ymd=ke.getYMD(new Date);this.layerCompnent.loadHtml(this.layerHtml());this.layerCompnent.show();datePickerHandler(this)};this.layerHtml=function(){var now=new Date;var year=this.ymd[0];var month=this.ymd[1];var day=this.ymd[2];var now_dt=ke.getYMD(now);var val_dt=ke.getYMD(this.get());var header=["日","一","二","三","四","五","六"];var items=[];var sub=year+"年"+(month<10?"0":"")+month+"月";var htm_header='';htm_header+='';var htm='
';var sdt=new Date(year,month-1,1);for(var i=0;i<7;i++){htm_header+="
"+header[i]+"
";if(i
"}htm_header+="
";for(var i=0;i<31;i++){temp=new Date(sdt.getTime()+864e5*i);_mon=temp.getMonth()+1;_day=i+1;var weekDay=temp.getDay();if(_mon==month){var cls=[];if(temp.getFullYear()==val_dt[0]&&_mon==val_dt[1]&&_day==val_dt[2])cls.push("date-selected");else if(_mon==now_dt[1]&&_day==now_dt[2])cls.push("date-today");if(weekDay==0||weekDay==6)cls.push("date-weekend");htm+='0)htm+='class="'+cls.join(" ")+'"';htm+=">"+_day+"
"}else break}var ts=ke.getTimeSpan(now);var ymd=ke.getYMD(now);var items=[];items.push({n:"今天",v:ke.getDateTip(now)});items.push({n:"明天",v:ke.getDateTip(ts+86400)});items.push({n:"下周",v:ke.getDateTip(ts+86400*7)});items.push({n:"下月",v:ke.getDateTip(new Date(ymd[0],ymd[1],ymd[2]))});items.push({n:"半年后",v:ke.getDateTip(new Date(ymd[0],ymd[1]+5,ymd[2]))});var part=ke.formatForeach('{n}
',items);htm+=''+part+"";return htm_header+htm+""};return this};$.fn.timebox=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);$.fn.input.apply(this,arguments);if(!this.skin.placeholder)this.skin.placeholder=ke.ui.lang(this.skin.readonly?"请选择":"请输入或选择");this.radix=[23,59,59];this.initSkin=function(){base.initSkin.call(this);this.skin.parse({enableSecond:false});if(this.skin.enableSecond){this.skin.layerOptions.minWidth=150;this.skin.reg=/^(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$/}else{this.skin.layerOptions.minWidth=100;this.skin.reg=/^(20|21|22|23|[0-1]\d):[0-5]\d$/}this.skin.css+=" timebox";this.skin.layerOptions.bodyCls="time-layer";this.skin.html=''};this.initHandler=function(){base.initHandler.call(this);this.find(".icon-btn").click(this,function(e){e.data.showLayer()});this.$text.bind("focus",this,function(e){e.data.$text.val(e.data.format())});this.$text.blur(this,function(e){e.data.set(e.data.format(null,true))});this.$text.mouseup(this,function(e){var dom=e.target;var val=dom.value;var s=dom.selectionStart;if(val){if(s<=3){dom.selectionStart=0;dom.selectionEnd=2}else if(s<=5){dom.selectionStart=3;dom.selectionEnd=5}else{dom.selectionStart=6;dom.selectionEnd=val.length}}})};this.format=function(v,formatLast){v=v||this.$text.val();var hms=[];var ts="";for(var i=0;i=48&&ch<=57)ts+=v[i];else if(v[i]==":"&&ts.length==1)ts="0"+ts;if(ts.length==2){if(parseInt(ts)>this.radix[hms.length])ts=this.radix[hms.length];hms.push(ts);ts=""}}if(formatLast&&ts.length==1)ts="0"+ts;hms.push(ts);v=hms.join(":");return v.substr(0,this.skin.enableSecond?8:5)};this.getHms=function(v){var r=[0,0];if(this.skin.enableSecond)r.push(0);var items=null;if($.isNumeric(v))items=ke.getYMD(v,"time");else items=(v||this.$value.val()).split(":");for(var i=0;ii){var ms=parseInt(items[i]);if(ms)r[i]=ms>this.radix[i]?this.radix[i]:ms}}return r};this.set=function(v){if(v!=null&&v!="")this.$value.val(this.format(this.getHms(v).join(":"),true));else this.$value.val("");this.validate()};this.get=function(type){type=type||this.skin.type;if(type==ke.types.int){var sec=[3600,60,1];var r=0;this.getHms().forEach(function(d,i){r+=d*sec[i]});return r}else return this.$value.val()};this.layerHtml=function(){var r=this.getHms();var parts=[24,60];if(this.skin.enableSecond)parts.push(60);var htm="";parts.forEach(function(d,k){htm+='';for(var i=0;i'+(i<10?"0":"")+i+"
"}htm+=""});return htm};this.itemClick=function(dom){var r=this.getHms();dom=$(dom);r[ke.getInt(dom.attr("data-index"))]=ke.getInt(dom.html());this.set(r.join(":"));this.layerHide()};return this};$.fn.switchbox=function(config){if(ke.ui.exists(this))return ke.ui.find(this[0]);var con=this.combobox(config);con.initSkin=function(){$.fn.input.methods.initSkin.call(this);this.skin.parse({radio:false});this.skin.valueInStore=true;this.skin.css+=this.skin.radio?" radiobox":" switchbox";this.skin.html='';this.html("");this.skin.clickShowLayer=false};con.bindStore=function(store){var htm="";if(this.skin.radio)htm='{'+this.skin.textField+"}
";else htm='{'+this.skin.textField+"}
";var tabs=ke.formatForeach(htm,store.toArray());this.find(".box").html(tabs);this.find(this.skin.radio?".radiobox-item":".switchbox-item").click(this,function(e){e.data.itemClick(e.target)});$.fn.input.methods.bindStore.call(this,store)};con.initHandler=function(){this.$text=this.$value=this.find("input[type='hidden']");this.setTitle(this.skin.title)};con.set=function(v){var con=this;con.find(".selected").removeClass("selected");$.fn.input.methods.set.call(con,v);this.selectedRows.forEach(function(d){con.find('[data-value="'+d[con.skin.valueField]+'"]').addClass("selected")})};return con};$.fn.menubox=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);$.fn.input.apply(this,arguments);this.initSkin=function(){base.initSkin.call(this);this.skin.valueInStore=true;this.skin.css+=" menubox";this.skin.html=''};this.initHandler=function(){base.initHandler.call(this);this.$value=this.find("input[type='hidden']");this.$text=this.find(".box div")};this.set=function(v){base.set.call(this,v);var txt=this.selectedRows.joinField(this.skin.textField,this.skin.separator);this.$text.html(txt)};return this};$.fn.optionbox=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);$.fn.input.apply(this,arguments);this.initSkin=function(){base.initSkin.call(this);this.skin.valueInStore=true;this.skin.css+=" optionbox";this.skin.html=''};this.bindStore=function(store){this.store=store;this.find(".box").html(this.optionsHtml(store,"",this.get()));this.find(".box div").bind("click",this,function(e){e.data.itemClick(e.target)});this.set(this.get())};this.initHandler=function(){base.initHandler.call(this);this.$value=this.find("input[type='hidden']")};this.set=function(v){base.set.call(this,v);this.find(".box div").removeClass("data-item-selected");for(var i=0;i'};this.bindStore=function(store){if(store){store.singleSelect=false;var htm=ke.formatForeach('",store.toArray());this.store=store;this.find(".box").html(htm);this.find(".box .checkbox").click(this,function(e){e.data.itemClick(e)})}};this.initHandler=function(){this.$text=this.$value=this.find("input[type='hidden']");$.fn.input.methods.initHandler.call(this)};this.set=function(v){var items=v?v.split(this.skin.split):[];var eles=this.find(".box .checkbox");for(var i=0;i-1;$(eles[i]).toggleClass("checkbox-selected",this.store.rows[i].selected)}};this.get=function(){var r="";var id=this.skin.valueField;this.store.getSelected().forEach(function(d){r+=","+d.data[id]});if(r)r=r.substr(1);return r};this.itemClick=function(e){var ele=$(e.target);while(ele.length&&!ele.hasClass("checkbox"))ele=ele.parent();var index=ke.getInt(ele.attr("data-options"));var row=this.store.rows[index];row.selected=!row.selected;ele.toggleClass("checkbox-selected",row.selected)};return this};$.fn.htmlbox=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);$.fn.input.apply(this,arguments);var self=this;this._value="";this._disable=false;this.initSkin=function(){base.initSkin.call(this);this.skin.parse($.fn.htmlbox.defaults);this.skin.css+=" htmlbox";if(ke.ui.mobile)this.skin.autoHeight=true;var url=window.KEUI_CONFIG.path+"ueditor/editor.html?con="+this.skin.id;this.skin.html='';this.skin.value=this.skin.value||this.html()};this.initHandler=function(){this.$value=this.$text=this.find(".box");this.setTitle(this.skin.title);base.initHandler.call(this)};this.initSize=function(first){base.initSize.call(this,first);if(this.skin.fullscreen){this.$text._setSize(true,ke.ui.winWidth,ke.ui.winHeight)}else{var h=this.autoSizeBox.height();this.$text._setSize(true,null,h)}};this.getEditor=function(){try{var r=this.find("iframe");var win=r[0].contentWindow;if(win.view&&win.view.editor)return win.view}catch(e){return null}},this.get=function(){var e=this.getEditor();if(e)this._value=e.getContent();return this._value};this.set=function(v){this._value=v;var e=this.getEditor();if(e)e.setContent(v)};this.disable=function(v){this._disable=v;var e=this.getEditor();if(e)e.disable(v)},this.fullscreen=function(v){if(v==null)v=!this.skin.fullscreen;this.toggleClass("fullscreen",v);this.skin.fullscreen=v;this.initSize()};this.changeDisplayMode=function(){this._value=this.get();this.skin.displayMode=this.skin.displayMode=="simple"?"full":"simple";var url=window.KEUI_CONFIG.path+"ueditor/editor.html?con="+this.skin.id;this.find("iframe").attr("src",url)};this.setInitialStyle=function(css){this.skin.initialStyle=css;this._value=this.get();var url=window.KEUI_CONFIG.path+"ueditor/editor.html?con="+this.skin.id;this.find("iframe").attr("src",url)};return this};$.fn.htmlbox.defaults={displayMode:"simple",fullscreen:false,autoHeight:false,initialStyle:""};$.fn.structurebox=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);$.fn.input.apply(this,arguments);var self=this;this._value="";this._disable=false;this._visible=true;this.initSkin=function(){base.initSkin.call(this);this.skin.parse({lang:0});this.skin.css+=" structurebox";var url=window.KEUI_CONFIG.path+"ketcher/editor.html?con="+this.skin.id+"&lang="+this.skin.lang;this.skin.html='';this.skin.value=this.skin.value||this.html()};this.initHandler=function(){this.$value=this.$text=this.find(".box");this.setTitle(this.skin.title);base.initHandler.call(this)};this.getEditor=function(){try{var r=this.find("iframe");var win=r[0].contentWindow;if(win.ketcher&&win.ketcher.editor)return win.view}catch(e){return null}},this.get=function(){var e=this.getEditor();if(e)this._value=e.get();return this._value};this.set=function(v){this._value=v;var e=this.getEditor();if(e)e.set(v)};this.molfile=function(v){var e=this.getEditor();if(e)return e.molfile(v)};this.graph=function(v){this._graphValue=v;var e=this.getEditor();if(e)return e.graph(v)};this.disable=function(v){this._disable=v;var e=this.getEditor();if(e)e.disable(v)};this.hasChange=function(){var e=this.getEditor();if(e)return e.hasChange();return false};this.addFragment=function(v){var e=this.getEditor();e.addFragment(v)};return this};$.fn.daterangebox=function(){if(ke.ui.exists(this))return ke.ui.find(this[0]);$.fn.input.apply(this,arguments);if(!this.skin.placeholder)this.skin.placeholder="请选择";this.initSkin=function(){base.initSkin.call(this);this.skin.css+=" daterangebox";this.skin.reg=/[\d]{4,4}[-]{1}[\d]{1,2}[-]{1}[\d]{1,2}/g;this.skin.layerOptions.syncOwnerWidth=false;this.skin.layerOptions.bodyCls="daterange-layer";this.skin.layerOptions.width=490;this.skin.layerOptions.height=430;this.skin.layerOptions.url="/res/keui/date-range-picker.html?con="+this.skin.id;this.skin.html=''};this.initHandler=function(){this.$value=this.find("input[type='hidden']");this.$text=this.find("input[type='text']");base.initHandler.call(this);this.find(".icon-btn").click(this,function(e){e.data.showLayer()})};this.set=function(v){this.$value.val(v);var parts=v.split(" ");var names=["按年","按季度","按月","按周","按天"];this.$text.val(names[parseInt(parts[0])]+" "+parts[1]+" ~ "+parts[2]);this.validate()};this.get=function(type){return this.$value.val()};this.getTimeSpan=function(){var val=this.get()||"0 0 0";var parts=val.split(" ");return[parseInt(parts[0]),ke.getTimeSpan(parts[1]),ke.getTimeSpan(parts[2])]};return this}})(jQuery);