This repository was archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
2 lines (2 loc) · 15.6 KB
/
app.js
1
2
!function(){"use strict";function t(t,n){for(var e=[],o=[],i=arguments.length,s=Array(i>2?i-2:0),r=2;r<i;r++)s[r-2]=arguments[r];for(var a=s.length,l=void 0;a-- >0;)e.push(s[a]);for(n&&n.key&&(l=n.key,delete n.key);e.length;){var u=e.pop();if(u&&u.pop)for(a=u.length;a--;)e.push(u[a]);else null!=u&&!0!==u&&!1!==u&&o.push(u)}return"function"==typeof t?t(n||{},o):{type:t,props:n||{},children:o,key:l}}var n=function(t){return t?t.key:null};function e(t,n){var e={};for(var o in t)e[o]=t[o];for(var i in n)e[i]=n[i];return e}function o(t,n,o,i,s){var r,a,l,u;"key"!==n&&"onComponentDidMount"!==n&&"onComponentDidUpdate"!==n&&"onComponentWillUnmount"!==n&&("style"===n&&"string"!=typeof o?function(t,n,o,i){for(var s in e(i,o)){var r=null==o||null==o[s]?"":o[s];"-"===s[0]?t[n].setProperty(s,r):t[n][s]=r}}(t,n,o,i):(n=n.toLowerCase(),"classname"===(u=n)&&(u="class"),l=o,"dangerouslysetinnerhtml"===(n=u)&&(t.innerHTML=l),n in t&&"list"!==n&&!s?t[n]="no"==o?"":o:null!=o&&"null"!==o&&"false"!==o&&"no"!==o&&"off"!==o&&("xlink-href"===n?(a=o,(r=t).setAttributeNS("http://www.w3.org/1999/xlink","href",a),r.setAttribute("href",a)):("true"===o&&(o=""),"dangerouslysetinnerhtml"!==n&&t.setAttribute(n,o))),null!=o&&"null"!==o&&"undefined"!==o&&"false"!==o&&"no"!==o&&"off"!==o||t.removeAttribute(n)))}var i=function(t,n,e){t.removeChild(function t(n,e){if(e.props)for(var o=0;o<e.children.length;o++)t(n.childNodes[o],e.children[o]);return n}(n,e)),e&&e.props&&e.props.onComponentDidUnmount&&e.props.onComponentDidUnmount.call(e.props.onComponentDidUnmount,t)};function s(t,r,a,l,u){if(l!==a){if(null==a||a.type!==l.type){var c=function t(n,e){var i=void 0;"number"==typeof n&&(n=n.toString()),i="string"==typeof n?document.createTextNode(n):(e=e||"svg"===n.type)?document.createElementNS("http://www.w3.org/2000/svg",n.type):document.createElement(n.type);var s=n.props;if(s){for(var r=0;r<n.children.length;r++)i.appendChild(t(n.children[r],e));for(var a in s)o(i,a,s[a],null,e)}return i}(l,u);t&&(t.insertBefore(c,r),null!=a&&i(t,r,a)),r=c}else if(null==a.type)r.nodeValue=l;else{!function(t,n,i,s){for(var r in e(n,i))i[r]!==("value"===r||"checked"===r?t[r]:n[r])&&o(t,r,i[r],n[r],s);t.mounted&&i&&i.onComponentDidUpdate&&i.onComponentDidUpdate.call(i.onComponentDidUpdate,n,i,t)}(r,a.props,l.props,u=u||"svg"===l.type);for(var h={},p={},m=[],d=a.children,f=l.children,v=0;v<d.length;v++){m[v]=r.childNodes[v];var y=n(d[v]);null!=y&&(h[y]=[m[v],d[v]])}for(var b=0,S=0;S<f.length;){var g=n(d[b]),k=n(f[S]);if(p[g])b++;else if(null==k||k!==n(d[b+1]))if(null==k)null==g&&(s(r,m[b],d[b],f[S],u),S++),b++;else{var C=h[k]||[];g===k?(s(r,C[0],C[1],f[S],u),b++):C[0]?s(r,r.insertBefore(C[0],m[b]),C[1],f[S],u):s(r,m[b],null,f[S],u),p[k]=f[S],S++}else null==g&&i(r,m[b],d[b]),b++}for(;b<d.length;)null==n(d[b])&&i(r,m[b],d[b]),b++;for(var T in h)p[T]||i(r,h[T][0],h[T][1])}return r}}var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a=(function(){function t(t){this.value=t}function n(n){var e,o;function i(e,o){try{var r=n[e](o),a=r.value;a instanceof t?Promise.resolve(a.value).then(function(t){i("next",t)},function(t){i("throw",t)}):s(r.done?"return":"normal",r.value)}catch(t){s("throw",t)}}function s(t,n){switch(t){case"return":e.resolve({value:n,done:!0});break;case"throw":e.reject(n);break;default:e.resolve({value:n,done:!1})}(e=e.next)?i(e.key,e.arg):o=null}this._invoke=function(t,n){return new Promise(function(s,r){var a={key:t,arg:n,resolve:s,reject:r,next:null};o?o=o.next=a:(e=o=a,i(t,n))})},"function"!=typeof n.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(n.prototype[Symbol.asyncIterator]=function(){return this}),n.prototype.next=function(t){return this._invoke("next",t)},n.prototype.throw=function(t){return this._invoke("throw",t)},n.prototype.return=function(t){return this._invoke("return",t)}}(),function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}),l=function(){function t(t,n){for(var e=0;e<n.length;e++){var o=n[e];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(n,e,o){return e&&t(n.prototype,e),o&&t(n,o),n}}(),u=function(t,n){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!n||"object"!=typeof n&&"function"!=typeof n?t:n},c=window&&window.requestAnimationFrame||window&&window.msRequestAnimationFrame||function(t){return setTimeout(t,16)};function h(t){return!Array.isArray(t)&&"object"===(void 0===t?"undefined":r(t))}var p=(new Date).getTime(),m=function(){function t(n){a(this,t),n||(n={}),this.props=n,this.selector=n.container||"body",n.render&&(this.render=n.render),n.state&&(this.state=n.state),this.selector&&(this.container=document.querySelector(this.selector)),this.componentShouldUpdate=!0,this.mounted=!1,this.element,n.componentWillMount&&(this.componentWillMount=n.componentWillMount),n.componentDidMount&&(this.componentDidMount=n.componentDidMount),n.componentWillUpdate&&(this.componentWillUpdate=n.componentWillUpdate),n.componentDidUpdate&&(this.componentDidUpdate=n.componentDidUpdate),n.componentWillUnmount&&(this.componentWillUnmount=n.componentWillUnmount)}return l(t,[{key:"componentWillMount",value:function(t){return t}},{key:"componentDidMount",value:function(t){return t}},{key:"componentWillUpdate",value:function(t){return t}},{key:"componentDidUpdate",value:function(t){return t}},{key:"componentWillUnmount",value:function(t){return t}},{key:"render",value:function(t){return t}},{key:"setState",value:function(t){if("function"==typeof t){var n=t.call(this,this.state);n&&(this.state=n)}else if(h(this.state)&&h(t)){var o=this.state;this.state=e(o,t)}else this.state=t}},{key:"update",value:function(t){if(this.render&&(this.componentShouldUpdate||!this.mounted)){var n=this.state;!0!==t&&t&&(n=t),this.container&&"string"==typeof this.container&&(this.selector=this.container,this.container=document.querySelector(this.container));var e=this.render(n),o=void 0;e&&e.props&&e.props.id&&this.container&&(o=this.container&&this.container.querySelector("#"+e.props.id)),o&&!this.mounted&&o.parentNode.removeChild(o);var i=this.element&&this.element.node;if(r=i,a=n,!(l=this)||JSON.stringify(r)!==JSON.stringify(l.render(a))){var r,a,l,u,c;if(this.element=(u=this.render(n),(c=this.element)?s(c.parentNode,c,c&&c.node,u):c=s(null,null,null,u),c.node=u,c),!this.mounted)return this.componentWillMount&&this.componentWillMount(this),this.container&&1===this.container.nodeType||console.error("The container for a class component is not a valid DOM node. Check the selector provided for the class to make sure it is a valid CSS selector and that the container exists in the DOM. You might be targeting a nonexistent node."),this.container.appendChild(this.element),this.mounted=!0,void(this.componentDidMount&&this.componentDidMount(this));this.componentWillUpdate&&this.componentWillUpdate(this),this.componentDidUpdate&&this.componentDidUpdate(this)}}}},{key:"unmount",value:function(){var t=this;if(this.element){this.componentWillUnmount&&this.componentWillUnmount(this),["change","click","dblclick","input","keydown","keypress","keyup","mousedown","mouseleave","mouseout","mouseover","mouseup","pointercancel","pointerdown","pointermove","pointerup","select","submit","touchcancel","touchend","touchmove","touchstart"].map(function(n){t.element.removeEventListener(n,t)}),this.container.removeChild(this.element),this.container=void 0;for(var n in this)delete this[n];delete this.state,this.update=void 0,this.unmount=void 0}}},{key:"state",get:function(){return this[p]},set:function(t){var n=this;this[p]=t,c(function(){return n.update()})}}]),t}(),d=new m({container:"header",render:function(n){return t("nav",null,t("i",{className:"fa fa fa-clock-o text-white"}),t("h1",null,"Composi ",n))}}),f=function(){function t(){a(this,t)}return l(t,[{key:"getTime",value:function(t){var n=t,e=this.formatUnitOfTime(Math.floor(n/36e5));n%=36e5;var o=this.formatUnitOfTime(Math.floor(n/6e4));return n%=6e4,e+":"+o+":"+this.formatUnitOfTime(Math.floor(n/1e3))+":"+this.formatUnitOfTime(n%1e3)}},{key:"formatUnitOfTime",value:function(t){return t<10?("0"+t).substring(0,2):t.toString().substring(0,2)}}]),t}(),v=function(n){var e=new f;return t("div",null,n.timeInterval&&t("div",{className:"display-countdown"},t("div",null,t("label",{type:"text",className:"display-countdown-label"},"H"),t("label",{type:"text",className:"display-countdown-label"},"M"),t("label",{type:"text",className:"display-countdown-label"},"S"),t("label",{type:"text",className:"display-countdown-label"},"MS")),t("div",{className:"display-countdown-time"},e.getTime(n.timeInterval))),!n.timeInterval&&t("div",{className:"display"},t("div",null,t("div",null,t("label",{type:"text",className:"display-label"},"H"),t("label",{type:"text",className:"display-label"},"M"),t("label",{type:"text",className:"display-label"},"S")),t("div",{className:"input-group input-group-lg display-input-group"},t("input",{type:"text",className:"form-control display-time display-hours",maxLength:"2",placeholder:"00",onFocus:function(){return n.onFocusChange("HH")},value:n.hours,onChange:n.onInputChange}),t("span",{className:"display-time display-separator"},":"),t("input",{type:"text",className:"form-control display-time display-minutes",maxLength:"2",placeholder:"00",onFocus:function(){return n.onFocusChange("MM")},value:n.minutes,onChange:n.onInputChange}),t("span",{className:"display-time display-separator"},":"),t("input",{type:"text",className:"form-control display-time display-seconds",maxLength:"2",placeholder:"00",onFocus:function(){return n.onFocusChange("SS")},value:n.seconds,onChange:n.onInputChange})))))},y=function(n){return t("div",null,t("div",null),null===n.status&&t("div",{className:"keypad"},t("div",{className:"keypad-row"},t("button",{className:"btn btn-light btn-sm",onClick:function(){return n.onClick(1)}},"1"),t("button",{className:"btn btn-light btn-sm",onClick:function(){return n.onClick(2)}},"2"),t("button",{className:"btn btn-light btn-sm",onClick:function(){return n.onClick(3)}},"3")),t("div",{className:"keypad-row"},t("button",{className:"btn btn-light btn-sm",onClick:function(){return n.onClick(4)}},"4"),t("button",{className:"btn btn-light btn-sm",onClick:function(){return n.onClick(5)}},"5"),t("button",{className:"btn btn-light btn-sm",onClick:function(){return n.onClick(6)}},"6")),t("div",{className:"keypad-row"},t("button",{className:"btn btn-light btn-sm",onClick:function(){return n.onClick(7)}},"7"),t("button",{className:"btn btn-light btn-sm",onClick:function(){return n.onClick(8)}},"8"),t("button",{className:"btn btn-light btn-sm",onClick:function(){return n.onClick(9)}},"9")),t("div",{className:"keypad-row"},t("button",{className:"btn btn-light btn-sm",onClick:function(){return n.onClick(-1)}},t("i",{className:"fa fa-close"})),t("button",{className:"btn btn-light btn-sm",onClick:function(){return n.onClick(0)}},"0"),t("button",{className:"btn btn-light btn-sm"}," "))))},b=function(n){return"STARTED"!==n.status&&"STOPPED"!==n.status?t("div",{className:"controls"},t("button",{className:"btn btn-success btn-lg btn-block",onClick:n.onStart,disabled:!n.canStart},"START")):"STARTED"===n.status||"STOPPED"===n.status?t("div",{className:"controls"},"STARTED"===n.status&&t("button",{className:"btn btn-danger btn-lg",onClick:n.onStop},"STOP"),"STOPPED"===n.status&&t("button",{className:"btn btn-success btn-lg",onClick:n.onResume},"RESUME"),t("button",{className:"btn btn-primary btn-lg",onClick:n.onReset},"RESET")):void 0},S=function(n){function e(t){a(this,e);var n=u(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return n.container="section",n.state={hours:"00",minutes:"00",seconds:"00",unitOfTime:null,status:null,canStart:null},n.handleDisplayFocusChange=n.handleDisplayFocusChange.bind(n),n.handleKeypadClick=n.handleKeypadClick.bind(n),n.handleControlsStart=n.handleControlsStart.bind(n),n.handleControlsResume=n.handleControlsResume.bind(n),n.handleControlsStop=n.handleControlsStop.bind(n),n.handleControlsReset=n.handleControlsReset.bind(n),n}return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function, not "+typeof n);t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),n&&(Object.setPrototypeOf?Object.setPrototypeOf(t,n):t.__proto__=n)}(e,m),l(e,[{key:"componentWillUnmount",value:function(){clearInterval(this.interval)}},{key:"handleDisplayFocusChange",value:function(t){console.log(t),this.setState(function(n){return n.unitOfTime=t,n})}},{key:"handleKeypadClick",value:function(t){"HH"===this.state.unitOfTime?this.setHours(t):"MM"===this.state.unitOfTime?this.setMinutes(t):"SS"===this.state.unitOfTime&&this.setSeconds(t),this.canStart()}},{key:"setHours",value:function(t){var n=this;t<0?this.setState(function(t){return t.hours="00",t}):this.setState(function(e){return(t=parseInt(n.formatTime(e.hours+t)))>99&&(t=e.hours),e.hours=n.formatTime(t),e})}},{key:"setMinutes",value:function(t){var n=this;t<0?this.setState(function(t){return t.minutes="00",t}):this.setState(function(e){return(t=parseInt(n.formatTime(e.minutes+t)))<60?parseInt(t.toString()[0])>5&&(t=59):t>59&&(t=parseInt(t.toString().slice(t.toString().length-1))),e.minutes=n.formatTime(t),e})}},{key:"setSeconds",value:function(t){var n=this;t<0?this.setState(function(t){return t.seconds="00",t}):this.setState(function(e){return(t=parseInt(n.formatTime(e.seconds+t)))<60?parseInt(t.toString()[0])>5&&(t=59):t>59&&(t=parseInt(t.toString().slice(t.toString().length-1))),e.seconds=n.formatTime(t),e})}},{key:"formatTime",value:function(t){return(t=parseInt(t))<10?"0"+t:t.toString().slice(t.toString().length-2)}},{key:"canStart",value:function(){this.setState(function(t){return t.canStart="STARTED"!==t.status&&(parseInt(t.hours)>0||parseInt(t.minutes)>0||parseInt(t.seconds)>0),t})}},{key:"handleControlsStart",value:function(){this.startTimer()}},{key:"startTimer",value:function(){var t=this;if("STARTED"!==this.state.status){this.setState(function(t){return t.status="STARTED",t});var n=1e3*(60*parseInt(this.state.hours)*60+60*parseInt(this.state.minutes)+parseInt(this.state.seconds));this.setState(function(t){return t.timeInterval=parseInt(n),t}),this.interval=setInterval(function(){t.setState(function(t){return t.timeInterval=t.timeInterval-10,t}),0===t.state.timeInterval&&(clearInterval(t.interval),t.setState(function(t){t.status=null}))},10)}}},{key:"handleControlsStop",value:function(){"STARTED"===this.state.status&&(clearInterval(this.interval),this.setState(function(t){return t.status="STOPPED",t}))}},{key:"handleControlsResume",value:function(){var t=this;"STOPPED"===this.state.status&&(this.interval=setInterval(function(){t.setState(function(t){return t.status="STARTED",t.timeInterval=t.timeInterval-10,t}),0===t.state.timeInterval&&(clearInterval(t.interval),t.setState(function(t){return t.status=null,t}))},10))}},{key:"handleControlsReset",value:function(){clearInterval(this.interval),this.setState(function(t){return t.status=null,t.timeInterval=null,t})}},{key:"render",value:function(){return t("div",{className:"timer"},t(v,{onFocusChange:this.handleDisplayFocusChange,hours:this.state.hours,minutes:this.state.minutes,seconds:this.state.seconds,timeInterval:this.state.timeInterval}),t(y,{onClick:this.handleKeypadClick,status:this.state.status}),t(b,{onStart:this.handleControlsStart,onStop:this.handleControlsStop,onResume:this.handleControlsResume,onReset:this.handleControlsReset,canStart:this.state.canStart,status:this.state.status}))}}]),e}();d.setState("Advanced Timer");new S}();
//# sourceMappingURL=app.js.map