UNPKG

magix-components

Version:
1 lines 6.38 kB
define("mx-time/index",["magix","$"],function(e,t,i){var n=e("magix"),s=e("$");n.applyStyle("G",".fn{width:58px;float:left;overflow:hidden}.fo{font-size:30px;height:50px;text-align:center;margin-bottom:10px}.fp{width:28px;height:28px;padding:0}.fq{font-size:27px;float:left;line-height:32px;margin-top:8px;font-weight:bolder;display:inline-block;width:30px;text-align:center}");var a=function(e){if(!e){var t=new Date;e=t.getHours()+":"+t.getMinutes()+":"+t.getSeconds()}var i=e.split(":");if(3!=i.length)throw new Error("bad time:"+e);return{hour:parseInt(i[0],10)||0,minute:parseInt(i[1],10)||0,second:parseInt(i[2],10)||0}},u=function(e){e||(e="all");var t={hour:!0,minute:!0,second:!0};if("all"!=e)for(var i in t)-1===e.indexOf(i)&&delete t[i];return t},d=function(e){return e<10?"0"+e:e};i.exports=n.View.extend({tmpl:{html:'<div class="fn"><input mx-guid="g0" class="an fo" value="<%=$$.format($$.time.hour)%>" <%if($$.types.hour){%> mx-change="__eW({type:\'hour\'})" <%}else{%> disabled<%}%> maxlength="2"><button mx-guid="g1" type="button" class="al fp Z" <%if($$.types.hour){%> mx-click="__eV({type:\'hour\'})" mx-mousedown="__cM({type:\'hour\'})" <%}else{%> disabled<%}%> tabindex="-1"><i class="_">&#xe6df;</i></button><button mx-guid="g2" type="button" class="al fp a_" <%if($$.types.hour){%> mx-click="__eV({type:\'hour\',inc:true})" mx-mousedown="__cM({type:\'hour\',inc:true})" <%}else{%> disabled<%}%> tabindex="-1"><i class="_">&#xe661;</i></button></div><span class="fq">:</span><div class="fn"><input mx-guid="g3" class="an fo" value="<%=$$.format($$.time.minute)%>" <%if($$.types.minute){%> mx-change="__eW({type:\'minute\'})" <%}else{%> disabled<%}%> maxlength="2"><button mx-guid="g4" type="button" class="al fp Z" <%if($$.types.minute){%> mx-click="__eV({type:\'minute\'})" mx-mousedown="__cM({type:\'minute\'})" <%}else{%> disabled<%}%> tabindex="-1"><i class="_">&#xe6df;</i></button><button mx-guid="g5" type="button" class="al fp a_" <%if($$.types.minute){%> mx-click="__eV({type:\'minute\',inc:true})" mx-mousedown="__cM({type:\'minute\',inc:true})" <%}else{%> disabled<%}%> tabindex="-1"><i class="_">&#xe661;</i></button></div><span class="fq">:</span><div class="fn"><input mx-guid="g6" class="an fo" value="<%=$$.format($$.time.second)%>" <%if($$.types.second){%> mx-change="__eW({type:\'second\'})" <%}else{%> disabled<%}%> maxlength="2"><button mx-guid="g7" type="button" class="al fp Z" <%if($$.types.second){%> mx-click="__eV({type:\'second\'})" mx-mousedown="__cM({type:\'second\'})" <%}else{%> disabled<%}%> tabindex="-1"><i class="_">&#xe6df;</i></button><button mx-guid="g8" type="button" class="al fp a_" <%if($$.types.second){%> mx-click="__eV({type:\'second\',inc:true})" mx-mousedown="__cM({type:\'second\',inc:true})" <%}else{%> disabled<%}%> tabindex="-1"><i class="_">&#xe661;</i></button></div>',subs:[{keys:["time","types"],path:'input[mx-guid="g0"]',attr:'value="<%=$$.format($$.time.hour)%>" <%if($$.types.hour){%> mx-change="__eW({type:\'hour\'})" <%}else{%> disabled<%}%>',attrs:[{n:"value",q:1,p:1},{n:"mx-change"},{n:"disabled",b:1,p:1}]},{keys:["types"],path:'button[mx-guid="g1"]',attr:"<%if($$.types.hour){%> mx-click=\"__eV({type:'hour'})\" mx-mousedown=\"__cM({type:'hour'})\" <%}else{%> disabled<%}%>",attrs:[{n:"mx-click"},{n:"mx-mousedown"},{n:"disabled",b:1,p:1}]},{keys:["types"],path:'button[mx-guid="g2"]',attr:"<%if($$.types.hour){%> mx-click=\"__eV({type:'hour',inc:true})\" mx-mousedown=\"__cM({type:'hour',inc:true})\" <%}else{%> disabled<%}%>",attrs:[{n:"mx-click"},{n:"mx-mousedown"},{n:"disabled",b:1,p:1}]},{keys:["time","types"],path:'input[mx-guid="g3"]',attr:'value="<%=$$.format($$.time.minute)%>" <%if($$.types.minute){%> mx-change="__eW({type:\'minute\'})" <%}else{%> disabled<%}%>',attrs:[{n:"value",q:1,p:1},{n:"mx-change"},{n:"disabled",b:1,p:1}]},{keys:["types"],path:'button[mx-guid="g4"]',attr:"<%if($$.types.minute){%> mx-click=\"__eV({type:'minute'})\" mx-mousedown=\"__cM({type:'minute'})\" <%}else{%> disabled<%}%>",attrs:[{n:"mx-click"},{n:"mx-mousedown"},{n:"disabled",b:1,p:1}]},{keys:["types"],path:'button[mx-guid="g5"]',attr:"<%if($$.types.minute){%> mx-click=\"__eV({type:'minute',inc:true})\" mx-mousedown=\"__cM({type:'minute',inc:true})\" <%}else{%> disabled<%}%>",attrs:[{n:"mx-click"},{n:"mx-mousedown"},{n:"disabled",b:1,p:1}]},{keys:["time","types"],path:'input[mx-guid="g6"]',attr:'value="<%=$$.format($$.time.second)%>" <%if($$.types.second){%> mx-change="__eW({type:\'second\'})" <%}else{%> disabled<%}%>',attrs:[{n:"value",q:1,p:1},{n:"mx-change"},{n:"disabled",b:1,p:1}]},{keys:["types"],path:'button[mx-guid="g7"]',attr:"<%if($$.types.second){%> mx-click=\"__eV({type:'second'})\" mx-mousedown=\"__cM({type:'second'})\" <%}else{%> disabled<%}%>",attrs:[{n:"mx-click"},{n:"mx-mousedown"},{n:"disabled",b:1,p:1}]},{keys:["types"],path:'button[mx-guid="g8"]',attr:"<%if($$.types.second){%> mx-click=\"__eV({type:'second',inc:true})\" mx-mousedown=\"__cM({type:'second',inc:true})\" <%}else{%> disabled<%}%>",attrs:[{n:"mx-click"},{n:"mx-mousedown"},{n:"disabled",b:1,p:1}]}]},init:function(e){var t=this,i=a(e.time),n=u(e.type);t.updater.set({format:d,time:i,types:n})},render:function(){this.updater.digest()},val:function(e){var t=this.updater;if(e){var i=a(e);t.digest({time:i})}return t.get("time")},__eU:function(e,t){var i=this,n=i.updater.get("time"),s="hour"==e?23:59;t?n[e]++:n[e]--,n[e]>s?n[e]=0:n[e]<0&&(n[e]=s),i.updater.digest({time:n}),i.__u()},__u:function(){var e=s("#"+this.id),t=this.updater.get("time");e.trigger({type:"change",time:d(t.hour)+":"+d(t.minute)+":"+d(t.second)})},"__eV<click>":function(e){if(!this.__cJ){var t=e.params;this.__eU(t.type,t.inc)}},"__eW<change>":function(e){e.stopPropagation();var t=e.params.type,i="hour"==t?23:59,n=e.eventTarget.value,s=parseInt(n,10),a=this.updater.get("time");s||0===s?(s<0?s=0:s>i&&(s=i),s!==a[t]?(a[t]=s,this.updater.digest({time:a}),this.__u()):e.eventTarget.value=d(s)):e.eventTarget.value=d(a[t])},"__cM<mousedown>":function(e){var t=this,i=e.params;t.__cK=setTimeout(t.wrapAsync(function(){t.__cL=setInterval(t.wrapAsync(function(){t.__cJ=!0,t.__eU(i.type,i.inc)}),80)}),300)},"$doc<mouseup>":function(){var e=this;clearTimeout(e.__cK),clearInterval(e.__cL),setTimeout(e.wrapAsync(function(){delete e.__cJ}),0)}})});