Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. 'use strict';
  2. $(document).ready(function() {
  3. $('.yourCountdownContainer').countdown({
  4. date: "23 mar,2017 15:03:26"
  5. });
  6. ! function(e) {
  7. if ("object" == typeof exports && "undefined" != typeof module) module.exports = e();
  8. else if ("function" == typeof define && define.amd) define([], e);
  9. else {
  10. var n; "undefined" != typeof window ? n = window : "undefined" != typeof global ? n = global : "undefined" != typeof self && (n = self), n.Countdown = e() } }(function() {
  11. var define, module, exports;
  12. return (function e(t, n, r) {
  13. function s(o, u) {
  14. if (!n[o]) {
  15. if (!t[o]) {
  16. var a = typeof require == "function" && require;
  17. if (!u && a) return a(o, !0);
  18. if (i) return i(o, !0);
  19. var f = new Error("Cannot find module '" + o + "'");
  20. throw f.code = "MODULE_NOT_FOUND", f }
  21. var l = n[o] = { exports: {} };
  22. t[o][0].call(l.exports, function(e) {
  23. var n = t[o][1][e];
  24. return s(n ? n : e) }, l, l.exports, e, t, n, r) }
  25. return n[o].exports }
  26. var i = typeof require == "function" && require;
  27. for (var o = 0; o < r.length; o++) s(r[o]);
  28. return s })({
  29. 1: [function(require, module, exports) {
  30. var defaultOptions = {
  31. date: "June 31, 2018 15:03:25",
  32. refresh: 1000,
  33. offset: 0,
  34. onEnd: function() {
  35. return;
  36. },
  37. render: function(date) {
  38. this.el.innerHTML = '<div class="row"><div class="col-xs-3"><h2 class="f-20 f-w-400">' +
  39. date.days + '</h2><p class="f-18 f-w-400"> Days ' +
  40. '</p></div><div class="col-xs-3"><h2 class="f-20 f-w-400">' +
  41. this.leadingZeros(date.hours) +
  42. '</h2><p class="f-18 f-w-400">Hours</p></div><div class="col-xs-3"><h2 class="f-20 f-w-400">' +
  43. this.leadingZeros(date.min) +
  44. '</h2><p class="f-18 f-w-400">Minutes</p></div><div class="col-xs-3"><h2 class="f-20 f-w-400">' +
  45. this.leadingZeros(date.sec) +
  46. '</h2><p class="f-18 f-w-400">Seconds</p></div></div>';
  47. }
  48. };
  49. /**
  50. * Countdown constructor
  51. * @param {HTMLElement} el DOM node of the countdown
  52. * @param {Object} options (optional) Options for the plugin
  53. */
  54. var Countdown = function(el, options) {
  55. /**
  56. * Reference to the DOM element
  57. * @type {HTMLElement}
  58. */
  59. this.el = el;
  60. /**
  61. * Options of the countdown plugin
  62. * @type {Object}
  63. */
  64. this.options = {};
  65. /**
  66. * Interval reference or false if counter is stopped
  67. * @type {Mixed}
  68. */
  69. this.interval = false;
  70. // merge default options and options into this.options
  71. this.mergeOptions = function(options) {
  72. for (var i in defaultOptions) {
  73. if (defaultOptions.hasOwnProperty(i)) {
  74. this.options[i] = typeof options[i] !== 'undefined' ? options[i] : defaultOptions[i];
  75. if (i === 'date' && typeof this.options.date !== 'object') {
  76. this.options.date = new Date(this.options.date);
  77. }
  78. // bind context for functions
  79. if (typeof this.options[i] === 'function') {
  80. this.options[i] = this.options[i].bind(this);
  81. }
  82. }
  83. }
  84. if (typeof this.options.date !== 'object') {
  85. this.options.date = new Date(this.options.date);
  86. }
  87. }.bind(this);
  88. this.mergeOptions(options);
  89. /**
  90. * Get the difference between now and the end date
  91. * @return {Object} Object with the diff information (years, days, hours, min, sec, millisec)
  92. */
  93. this.getDiffDate = function() {
  94. var diff = (this.options.date.getTime() - Date.now() + this.options.offset) / 1000;
  95. var dateData = {
  96. years: 0,
  97. days: 0,
  98. hours: 0,
  99. min: 0,
  100. sec: 0,
  101. millisec: 0
  102. };
  103. if (diff <= 0) {
  104. if (this.interval) {
  105. this.stop();
  106. this.options.onEnd();
  107. }
  108. return dateData;
  109. }
  110. if (diff >= (365.25 * 86400)) {
  111. dateData.years = Math.floor(diff / (365.25 * 86400));
  112. diff -= dateData.years * 365.25 * 86400;
  113. }
  114. if (diff >= 86400) {
  115. dateData.days = Math.floor(diff / 86400);
  116. diff -= dateData.days * 86400;
  117. }
  118. if (diff >= 3600) {
  119. dateData.hours = Math.floor(diff / 3600);
  120. diff -= dateData.hours * 3600;
  121. }
  122. if (diff >= 60) {
  123. dateData.min = Math.floor(diff / 60);
  124. diff -= dateData.min * 60;
  125. }
  126. dateData.sec = Math.round(diff);
  127. dateData.millisec = diff % 1 * 1000;
  128. return dateData;
  129. }.bind(this);
  130. /**
  131. * Add leading zeros to a number
  132. * @param {Number} num Input number
  133. * @param {Number} length Length of the desired output
  134. * @return {String} String of the desired length with leading zeros
  135. */
  136. this.leadingZeros = function(num, length) {
  137. length = length || 2;
  138. num = String(num);
  139. if (num.length > length) {
  140. return num;
  141. }
  142. return (Array(length + 1).join('0') + num).substr(-length);
  143. };
  144. /**
  145. * Update the end date of the countdown
  146. * @param {Mixed} newDate Date object or a String/Number that can be passed to the Date constructor
  147. * @return {Countdown} Countdown instance
  148. */
  149. this.update = function(newDate) {
  150. if (typeof newDate !== 'object') {
  151. newDate = new Date(newDate);
  152. }
  153. this.options.date = newDate;
  154. this.render();
  155. return this;
  156. }.bind(this);
  157. /**
  158. * Stop the countdown refresh / rerender
  159. * @return {Countdown} Countdown instance
  160. */
  161. this.stop = function() {
  162. if (this.interval) {
  163. clearInterval(this.interval);
  164. this.interval = false;
  165. }
  166. return this;
  167. }.bind(this);
  168. /**
  169. * Render the countdown
  170. * @return {Countdown} Countdown instance
  171. */
  172. this.render = function() {
  173. this.options.render(this.getDiffDate());
  174. return this;
  175. }.bind(this);
  176. /**
  177. * Start the countdown
  178. * @return {Countdown} Countdown instance
  179. */
  180. this.start = function() {
  181. // don't start if the countdown is already started
  182. if (this.interval) {
  183. return; }
  184. this.render();
  185. if (this.options.refresh) {
  186. this.interval = setInterval(this.render, this.options.refresh);
  187. }
  188. return this;
  189. }.bind(this);
  190. /**
  191. * Update the offset
  192. * @param {Number} offset New offset in ms
  193. * @return {Countdown} Countdown instance
  194. */
  195. this.updateOffset = function(offset) {
  196. this.options.offset = offset;
  197. return this;
  198. }.bind(this);
  199. /**
  200. * Restart the countdown and update options
  201. */
  202. this.restart = function(options) {
  203. this.mergeOptions(options);
  204. this.interval = false;
  205. this.start();
  206. return this;
  207. }.bind(this);
  208. // initial start of the countdown or initial render
  209. this.start();
  210. };
  211. module.exports = Countdown;
  212. }, {}],
  213. 2: [function(require, module, exports) {
  214. var Countdown = require('./countdown.js');
  215. var NAME = 'countdown';
  216. var DATA_ATTR = 'date';
  217. jQuery.fn.countdown = function(options) {
  218. return $.each(this, function(i, el) {
  219. var $el = $(el);
  220. if (!$el.data(NAME)) {
  221. // allow setting the date via the data-date attribute
  222. if ($el.data(DATA_ATTR)) {
  223. options.date = $el.data(DATA_ATTR);
  224. }
  225. $el.data(NAME, new Countdown(el, options));
  226. }
  227. });
  228. };
  229. module.exports = Countdown;
  230. }, { "./countdown.js": 1 }]
  231. }, {}, [2])(2)
  232. });
  233. });