Skip to content

Instantly share code, notes, and snippets.

@daniellizik-sc
Created June 22, 2016 14:51
Show Gist options
  • Save daniellizik-sc/8713b1ce1332707d2f4ea8cba5febd02 to your computer and use it in GitHub Desktop.
Save daniellizik-sc/8713b1ce1332707d2f4ea8cba5febd02 to your computer and use it in GitHub Desktop.
countdown timer script
!function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return e[n].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}var i=r(17),a=n(i);new a["default"]({mode:"decrement",delay:1e3})},,,,,,,,,,,,,,,,,function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var a=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),u=r(18),o=n(u),c=r(19),s=n(c),l=r(21),d=n(l),f=(r(20),r(22),r(23)),m=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?{delay:1e3,mode:"decrement"}:arguments[0];i(this,e),this.nextTick=(0,d["default"])(t.mode),this.delay=t.delay,this.mode=t.mode,this.view=(0,s["default"])(),this.time=(0,f.parseDateFromView)(this.view),this.dates={current:(0,f.formatDate)(this.time)},this.render(this.dates.current,"$current"),this.poll=this.tick(this.mode)}return a(e,[{key:"increment",value:function(){this.poll=this.tick("increment")}},{key:"decrement",value:function(){this.poll=this.tick("decrement")}},{key:"tick",value:function(e){var t=this;return(0,o["default"])({delay:this.delay,each:function(e,r,n){t.time+=t.nextTick,t.dates.current=(0,f.formatDate)(t.time),t.render(t.dates.current,"$current"),n()}})}},{key:"render",value:function(e,t){this.view.forEach(function(r){1*r[t].textContent!=e[r.format]&&(r[t].textContent=e[r.format])})}}]),e}();t["default"]=m},function(e,t,r){var n,i;!function(a,u,o){"use strict";return"object"==typeof e&&e.exports?e.exports=o():(n=[u,o],i="function"==typeof n?n.call(t,r,t,e):n,!(void 0!==i&&(e.exports=i)))}(this,"easyPoll",function(){"use strict";return function(e){function t(e,t){return"get"===e?function(){return u[t]}:"set"===e?function(e){u[t]=e}:void 0}function r(){return setTimeout(i,u.delay)+":"+u.time}function n(e){clearTimeout(u.id),u.after(u.current,r),"function"==typeof e&&e(u.current,r)}function i(){u.each(u.current,n,function(){u.current++,u.current>=u.max?n():u.id=r()})}function a(e){this.time=(new Date).getTime(),this.delay=e.delay||1e3,this.current=0,this.max=e.max||1/0,this.each=e.each||function(e,t,r){r()},this.after=e.after||function(){}}a.prototype.init=function(){this.id=r()};var u=new a(e);return u.init(),{stop:n,getCurrent:t("get","current"),setDelay:t("set","delay"),setMax:t("set","max"),setEach:t("set","each"),setAfter:t("set","after"),setCurrent:t("set","current")}}})},function(e,t,r){"use strict";function n(){return[].slice.call(document.querySelectorAll("["+i.dataAttribs.TIMESLOT_CONTAINER+"]")).map(function(e){var t=e.querySelector("["+i.dataAttribs.TIMESLOT_CURRENT+"]"),r=e.querySelector("["+i.dataAttribs.TIMESLOT_LABEL+"]"),n=e.querySelector("["+i.dataAttribs.TIMESLOT_NEXT+"]");return{current:1*t.textContent,label:r.textContent.toLowerCase(),format:r.getAttribute(i.dataAttribs.TIMESLOT_LABEL),$current:t,$next:n,$label:r}})}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=n;var i=r(20)},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.cssClassNames={TOP_CLASS:"timeslot--top",BOTTOM_CLASS:"timeslot--bottom"},t.dataAttribs={TIMESLOT_CONTAINER:"data-timeslot",TIMESLOT_NEXT:"data-timeslot-next",TIMESLOT_CURRENT:"data-timeslot-current",TIMESLOT_LABEL:"data-timeslot-label"},t.timekeeping={SECONDS_IN_MINUTE:60,MINUTES_IN_HOUR:60,HOURS_IN_DAY:24,SECONDS_IN_HOUR:3600,SECONDS_IN_DAY:86400,SECONDS_IN_WEEK:604800}},function(e,t){"use strict";function r(){var e,t=arguments.length<=0||void 0===arguments[0]?"decrement":arguments[0],r=arguments.length<=1||void 0===arguments[1]?1:arguments[1];return"increment"===t?e=1:"decrement"===t&&(e=-1),e*r}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r},function(e,t){"use strict";function r(e,t){e.className=e.className.split(" ").concat(t).join(" ")}function n(e,t){e.className.replace(t,"")}Object.defineProperty(t,"__esModule",{value:!0}),t.addClass=r,t.removeClass=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.parseDateFromView=t.formatDate=void 0;var n=r(20);t.formatDate=function(e){var t=arguments.length<=1||void 0===arguments[1]?"dd:hh:mm:ss":arguments[1];return t.split(":").reduce(function(e,t){var r,i;return"dd"===t?i=n.timekeeping.SECONDS_IN_DAY:"hh"===t?i=n.timekeeping.SECONDS_IN_HOUR:"mm"===t?i=n.timekeeping.SECONDS_IN_MINUTE:"ss"===t&&(i=1),r=parseInt(e.remainder/i,10),e.parts[t]=e.parts[t]||r,e.remainder=e.remainder%i,e},{parts:{},remainder:e,total:e}).parts},t.parseDateFromView=function(e){return e.reduce(function(e,t){switch(t.label){case"weeks":return e+=t.current*n.timekeeping.SECONDS_IN_WEEK;case"days":return e+=t.current*n.timekeeping.SECONDS_IN_DAY;case"hours":return e+=t.current*n.timekeeping.SECONDS_IN_HOUR;case"minutes":return e+=t.current*n.timekeeping.SECONDS_IN_MINUTE;case"seconds":return e+=t.current;default:return e}},0)}}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment