1/* 2 3 * Author - Harshen Amarnath Pandey 4 * Version - 1.0.8 5 * Release - 18th April 2015 6 * Copyright (c) 2014 - 2018 Harshen Pandey 7 */ 8 9(function ($) { 10 $.fn.countdowntimer = function (options) { 11 return this.each(function () { 12 countdown($(this), options); 13 }); 14 }; 15 16 //Definition of private function countdown. 17 function countdown($this, options) { 18 var opts = $.extend({}, $.fn.countdowntimer.defaults, options); 19 var $this = $this; 20 $this.addClass("style"); 21 var size = ""; 22 var borderColor = ""; 23 var fontColor = ""; 24 var backgroundColor = ""; 25 var regexpMatchFormat = ""; 26 var regexpReplaceWith = ""; 27 size = opts.size; 28 borderColor = opts.borderColor; 29 fontColor = opts.fontColor; 30 backgroundColor = opts.backgroundColor; 31 32 if (options.regexpMatchFormat != undefined && options.regexpReplaceWith != undefined && options.timeSeparator == undefined) { 33 window['regexpMatchFormat_' + $this.attr('id')] = options.regexpMatchFormat; 34 window['regexpReplaceWith_' + $this.attr('id')] = options.regexpReplaceWith; 35 } 36 37 if (options.borderColor != undefined || options.fontColor != undefined || options.backgroundColor != undefined) { 38 var customStyle = { 39 "background": backgroundColor, 40 "color": fontColor, 41 "border-color": borderColor 42 } 43 $this.css(customStyle); 44 } else { 45 $this.addClass("colorDefinition"); 46 } 47 48 if (options.size != undefined) { 49 switch (size) { 50 case "xl" : 51 $this.addClass("size_xl"); 52 break; 53 case "lg" : 54 $this.addClass("size_lg"); 55 break; 56 case "md" : 57 $this.addClass("size_md"); 58 break; 59 case "sm" : 60 $this.addClass("size_sm"); 61 break; 62 case "xs" : 63 $this.addClass("size_xs"); 64 break; 65 } 66 } else if (size == "sm") { 67 $this.addClass("size_sm"); 68 } 69 70 if (options.startDate == undefined && options.dateAndTime == undefined && options.currentTime == undefined && (options.hours != undefined || options.minutes != undefined || options.seconds != undefined)) { 71 72 if (options.hours != undefined && options.minutes == undefined && options.seconds == undefined) { 73 hours_H = ""; 74 minutes_H = ""; 75 seconds_H = ""; 76 timer_H = ""; 77 window['hours_H' + $this.attr('id')] = opts.hours; 78 window['minutes_H' + $this.attr('id')] = opts.minutes; 79 window['seconds_H' + $this.attr('id')] = opts.seconds; 80 if (options.pauseButton != undefined) { 81 pauseTimer($this, "H", opts, onlyHours); 82 } 83 if (options.stopButton != undefined) { 84 stopTimer($this, "H", opts, onlyHours); 85 } 86 onlyHours($this, opts); 87 window['timer_H' + $this.attr('id')] = setInterval(function () { 88 onlyHours($this, opts) 89 }, opts.tickInterval * 1000); 90 } else if (options.hours == undefined && options.minutes != undefined && options.seconds == undefined) { 91 hours_M = ""; 92 minutes_M = ""; 93 seconds_M = ""; 94 timer_M = ""; 95 window['hours_M' + $this.attr('id')] = opts.hours; 96 window['minutes_M' + $this.attr('id')] = opts.minutes; 97 window['seconds_M' + $this.attr('id')] = opts.seconds; 98 if (options.pauseButton != undefined) { 99 pauseTimer($this, "M", opts, onlyMinutes); 100 } 101 if (options.stopButton != undefined) { 102 stopTimer($this, "M", opts, onlyMinutes); 103 } 104 onlyMinutes($this, opts); 105 window['timer_M' + $this.attr('id')] = setInterval(function () { 106 onlyMinutes($this, opts) 107 }, opts.tickInterval * 1000); 108 } else if (options.hours == undefined && options.minutes == undefined && options.seconds != undefined) { 109 hours_S = ""; 110 minutes_S = ""; 111 seconds_S = ""; 112 timer_S = ""; 113 window['hours_S' + $this.attr('id')] = opts.hours; 114 window['minutes_S' + $this.attr('id')] = opts.minutes; 115 window['seconds_S' + $this.attr('id')] = opts.seconds; 116 if (options.pauseButton != undefined) { 117 pauseTimer($this, "S", opts, onlySeconds); 118 } 119 if (options.stopButton != undefined) { 120 stopTimer($this, "S", opts, onlySeconds); 121 } 122 onlySeconds($this, opts); 123 window['timer_S' + $this.attr('id')] = setInterval(function () { 124 onlySeconds($this, opts) 125 }, opts.tickInterval * 1000); 126 } else if (options.hours != undefined && options.minutes != undefined && options.seconds == undefined) { 127 hours_HM = ""; 128 minutes_HM = ""; 129 seconds_HM = ""; 130 timer_HM = ""; 131 window['hours_HM' + $this.attr('id')] = opts.hours; 132 window['minutes_HM' + $this.attr('id')] = opts.minutes; 133 window['seconds_HM' + $this.attr('id')] = opts.seconds; 134 if (options.pauseButton != undefined) { 135 pauseTimer($this, "HM", opts, hoursMinutes); 136 } 137 if (options.stopButton != undefined) { 138 stopTimer($this, "HM", opts, hoursMinutes); 139 } 140 hoursMinutes($this, opts); 141 window['timer_HM' + $this.attr('id')] = setInterval(function () { 142 hoursMinutes($this, opts) 143 }, opts.tickInterval * 1000); 144 } else if (options.hours == undefined && options.minutes != undefined && options.seconds != undefined) { 145 hours_MS = ""; 146 minutes_MS = ""; 147 seconds_MS = ""; 148 timer_MS = ""; 149 window['hours_MS' + $this.attr('id')] = opts.hours; 150 window['minutes_MS' + $this.attr('id')] = opts.minutes; 151 window['seconds_MS' + $this.attr('id')] = opts.seconds; 152 if (options.pauseButton != undefined) { 153 pauseTimer($this, "MS", opts, minutesSeconds); 154 } 155 if (options.stopButton != undefined) { 156 stopTimer($this, "MS", opts, minutesSeconds); 157 } 158 minutesSeconds($this, opts); 159 window['timer_MS' + $this.attr('id')] = setInterval(function () { 160 minutesSeconds($this, opts) 161 }, opts.tickInterval * 1000); 162 } else if (options.hours != undefined && options.minutes == undefined && options.seconds != undefined) { 163 hours_HS = ""; 164 minutes_HS = ""; 165 seconds_HS = ""; 166 timer_HS = ""; 167 window['hours_HS' + $this.attr('id')] = opts.hours; 168 window['minutes_HS' + $this.attr('id')] = opts.minutes; 169 window['seconds_HS' + $this.attr('id')] = opts.seconds; 170 if (options.pauseButton != undefined) { 171 pauseTimer($this, "HS", opts, hoursSeconds); 172 } 173 if (options.stopButton != undefined) { 174 stopTimer($this, "HS", opts, hoursSeconds); 175 } 176 hoursSeconds($this, opts); 177 window['timer_HS' + $this.attr('id')] = setInterval(function () { 178 hoursSeconds($this, opts) 179 }, opts.tickInterval * 1000); 180 } else if (options.hours != undefined && options.minutes != undefined && options.seconds != undefined) { 181 hours_HMS = ""; 182 minutes_HMS = ""; 183 seconds_HMS = ""; 184 timer_HMS = ""; 185 window['hours_HMS' + $this.attr('id')] = opts.hours; 186 window['minutes_HMS' + $this.attr('id')] = opts.minutes;
187 window['seconds_HMS' + $this.attr('id')] = opts.seconds; 188 if (options.pauseButton != undefined) { 189 pauseTimer($this, "HMS", opts, hoursMinutesSeconds); 190 } 191 if (options.stopButton != undefined) { 192 stopTimer($this, "HMS", opts, hoursMinutesSeconds); 193 } 194 hoursMinutesSeconds($this, opts); 195 window['timer_HMS' + $this.attr('id')] = setInterval(function () { 196 hoursMinutesSeconds($this, opts) 197 }, opts.tickInterval * 1000); 198 } 199 200 } else if (options.startDate != undefined && options.dateAndTime != undefined && options.currentTime == undefined) { 201 startDate = ""; 202 endDate = ""; 203 timer_startDate = ""; 204 window['startDate' + $this.attr('id')] = new Date(opts.startDate); 205 window['endDate' + $this.attr('id')] = new Date(opts.dateAndTime); 206 var type = "withStart"; 207 givenDate($this, opts, type); 208 window['timer_startDate' + $this.attr('id')] = setInterval(function () { 209 givenDate($this, opts, type) 210 }, opts.tickInterval * 1000); 211 } else if (options.startDate == undefined && options.dateAndTime != undefined && options.currentTime == undefined) { 212 startTime = ""; 213 dateTime = ""; 214 timer_givenDate = ""; 215 var hour = opts.startDate.getHours() < 10 ? '0' + opts.startDate.getHours() : opts.startDate.getHours(); 216 var minutes = opts.startDate.getMinutes() < 10 ? '0' + opts.startDate.getMinutes() : opts.startDate.getMinutes(); 217 var seconds = opts.startDate.getSeconds() < 10 ? '0' + opts.startDate.getSeconds() : opts.startDate.getSeconds(); 218 var month = (opts.startDate.getMonth() + 1) < 10 ? '0' + (opts.startDate.getMonth() + 1) : (opts.startDate.getMonth() + 1); 219 var date = opts.startDate.getDate() < 10 ? '0' + opts.startDate.getDate() : opts.startDate.getDate(); 220 var year = opts.startDate.getFullYear(); 221 window['startTime' + $this.attr('id')] = new Date(year + '/' + month + '/' + date + ' ' + hour + ':' + minutes + ':' + seconds); 222 window['dateTime' + $this.attr('id')] = new Date(opts.dateAndTime); 223 var type = "withnoStart"; 224 givenDate($this, opts, type); 225 window['timer_givenDate' + $this.attr('id')] = setInterval(function () { 226 givenDate($this, opts, type) 227 }, opts.tickInterval * 1000); 228 } else if (options.currentTime != undefined) { 229 currentTime = ""; 230 timer_currentDate = ""; 231 window['currentTime' + $this.attr('id')] = opts.currentTime; 232 currentDate($this, opts); 233 window['timer_currentDate' + $this.attr('id')] = setInterval(function () { 234 currentDate($this, opts) 235 }, opts.tickInterval * 1000); 236 } else { 237 countSeconds = ""; 238 timer_secondsTimer = ""; 239 window['countSeconds' + $this.attr('id')] = opts.seconds; 240 window['timer_secondsTimer' + $this.attr('id')] = setInterval(function () { 241 secondsTimer($this) 242 }, 1000); 243 } 244 } 245 ; 246 247 //Function for only hours are set when invoking plugin. 248 function onlyHours($this, opts) { 249 var id = $this.attr('id'); 250 if (window['minutes_H' + id] == opts.minutes && window['seconds_H' + id] == opts.seconds && window['hours_H' + id] == opts.hours) { 251 if (window['hours_H' + id].toString().length < 2) { 252 window['hours_H' + id] = "0" + window['hours_H' + id]; 253 } 254 html($this, window['hours_H' + id] + opts.timeSeparator + "00" + opts.timeSeparator + "00"); 255 window['seconds_H' + id] = 60 - opts.tickInterval; 256 window['minutes_H' + id] = 59; 257 if (window['hours_H' + id] != 0) { 258 window['hours_H' + id]--; 259 } else { 260 delete window['hours_H' + id]; 261 delete window['minutes_H' + id]; 262 delete window['seconds_H' + id]; 263 clearInterval(window['timer_H' + id]); 264 timeUp($this, opts); 265 } 266 } else { 267 if (window['hours_H' + id].toString().length < 2) { 268 window['hours_H' + id] = "0" + window['hours_H' + id]; 269 } 270 if (window['minutes_H' + id].toString().length < 2) { 271 window['minutes_H' + id] = "0" + window['minutes_H' + id]; 272 } 273 if (window['seconds_H' + id].toString().length < 2) { 274 window['seconds_H' + id] = "0" + window['seconds_H' + id]; 275 } 276 html($this, window['hours_H' + id] + opts.timeSeparator + window['minutes_H' + id] + opts.timeSeparator + window['seconds_H' + id]); 277 window['seconds_H' + id] -= opts.tickInterval; 278 if (window['minutes_H' + id] != 0 && window['seconds_H' + id] < 0) { 279 window['minutes_H' + id]--; 280 window['seconds_H' + id] = 60 - opts.tickInterval; 281 } 282 if (window['minutes_H' + id] == 0 && window['seconds_H' + id] < 0 && window['hours_H' + id] != 0) 283 { 284 window['hours_H' + id]--; 285 window['minutes_H' + id] = 59; 286 window['seconds_H' + id] = 60 - opts.tickInterval; 287 } 288 if (window['minutes_H' + id] == 0 && window['seconds_H' + id] < 0 && window['hours_H' + id] == 0) 289 { 290 delete window['hours_H' + id]; 291 delete window['minutes_H' + id]; 292 delete window['seconds_H' + id]; 293 clearInterval(window['timer_H' + id]); 294 timeUp($this, opts); 295 } 296 } 297 id = null; 298 } 299 300 //Function for only minutes are set when invoking plugin. 301 function onlyMinutes($this, opts) { 302 var id = $this.attr('id'); 303 if (window['minutes_M' + id] == opts.minutes && window['seconds_M' + id] == opts.seconds) { 304 if (window['minutes_M' + id].toString().length < 2) { 305 window['minutes_M' + id] = "0" + window['minutes_M' + id]; 306 } 307 html($this, window['minutes_M' + id] + opts.timeSeparator + "00"); 308 window['seconds_M' + id] = 60 - opts.tickInterval; 309 if (window['minutes_M' + id] != 0) { 310 window['minutes_M' + id]--; 311 } else { 312 delete window['hours_M' + id]; 313 delete window['minutes_M' + id]; 314 delete window['seconds_M' + id]; 315 clearInterval(window['timer_M' + id]); 316 timeUp($this, opts); 317 } 318 } else { 319 if (window['minutes_M' + id].toString().length < 2) { 320 window['minutes_M' + id] = "0" + window['minutes_M' + id]; 321 } 322 if (window['seconds_M' + id].toString().length < 2) { 323 window['seconds_M' + id] = "0" + window['seconds_M' + id]; 324 } 325 html($this, window['minutes_M' + id] + opts.timeSeparator + window['seconds_M' + id]); 326 window['seconds_M' + id] -= opts.tickInterval; 327 if (window['minutes_M' + id] != 0 && window['seconds_M' + id] < 0) { 328 window['minutes_M' + id]--; 329 window['seconds_M' + id] = 60 - opts.tickInterval; 330 } 331 if (window['minutes_M' + id] == 0 && window['seconds_M' + id] < 0) 332 { 333 delete window['hours_M' + id]; 334 delete window['minutes_M' + id]; 335 delete window['seconds_M' + id]; 336 clearInterval(window['timer_M' + id]); 337 timeUp($this, opts); 338 } 339 } 340 id = null; 341 } 342 343 //Function for only seconds are set when invoking plugin. 344 function onlySeconds($this, opts) { 345 var id = $this.attr('id'); 346 if (window['seconds_S' + id].toString().length < 2) { 347 window['seconds_S' + id] = "0" + window['seconds_S' + id]; 348 } 349 html($this, window['seconds_S' + id] + " " + "sec"); 350 window['seconds_S' + id] -= opts.tickInterval; 351 if (window['seconds_S' + id] < 0) 352 { 353 delete window['hours_S' + id]; 354 delete window['minutes_S' + id]; 355 delete window['seconds_S' + id]; 356 clearInterval(window['timer_S' + id]); 357 timeUp($this, opts); 358 } 359 id = null; 360 } 361 362 //Function for hours and minutes are set when invoking plugin. 363 function hoursMinutes($this, opts) { 364 var id = $this.attr('id'); 365 if (window['minutes_HM' + id] == opts.minutes && window['hours_HM' + id] == opts.hours) { 366 if (window['hours_HM' + id].toString().length < 2) { 367 window['hours_HM' + id] = "0" + window['hours_HM' + id]; 368 } 369 if (window['minutes_HM' + id].toString().length < 2) { 370 window['minutes_HM' + id] = "0" + window['minutes_HM' + id]; 371 } 372 html($this, window['hours_HM' + id] + opts.timeSeparator + window['minutes_HM' + id] + opts.timeSeparator + "00"); 373 if (window['hours_HM' + id] != 0 && window['minutes_HM' + id] == 0) { 374 window['hours_HM' + id]--; 375 window['minutes_HM' + id] = 59; 376 window['seconds_HM' + id] = 60 - opts.tickInterval; 377 } else if (window['hours_HM' + id] == 0 && window['minutes_HM' + id] != 0) { 378 window['seconds_HM' + id] = 60 - opts.tickInterval; 379 window['minutes_HM' + id]--; 380 } else { 381 window['seconds_HM' + id] = 60 - opts.tickInterval; 382 window['minutes_HM' + id]--; 383 } 384 if (window['hours_HM' + id] == 0 && window['minutes_HM' + id] == 0 && window['seconds_HM' + id] == 60) 385 { 386 delete window['hours_HM' + id]; 387 delete window['minutes_HM' + id]; 388 delete window['seconds_HM' + id]; 389 clearInterval(window['timer_HM' + id]); 390 timeUp($this, opts); 391 } 392 } else { 393 if (window['hours_HM' + id].toString().length < 2) { 394 window['hours_HM' + id] = "0" + window['hours_HM' + id]; 395 } 396 if (window['minutes_HM' + id].toString().length < 2) { 397 window['minutes_HM' + id] = "0" + window['minutes_HM' + id]; 398 } 399 if (window['seconds_HM' + id].toString().length < 2) { 400 window['seconds_HM' + id] = "0" + window['seconds_HM' + id]; 401 } 402 html($this, window['hours_HM' + id] + opts.timeSeparator + window['minutes_HM' + id] + opts.timeSeparator + window['seconds_HM' + id]); 403 window['seconds_HM' + id] -= opts.tickInterval; 404 if (window['minutes_HM' + id] != 0 && window['seconds_HM' + id] < 0) { 405 window['minutes_HM' + id]--; 406 window['seconds_HM' + id] = 60 - opts.tickInterval; 407 } 408 if (window['minutes_HM' + id] == 0 && window['seconds_HM' + id] < 0 && window['hours_HM' + id] != 0) 409 { 410 window['hours_HM' + id]--; 411 window['minutes_HM' + id] = 59; 412 window['seconds_HM' + id] = 60 - opts.tickInterval; 413 } 414 if (window['minutes_HM' + id] == 0 && window['seconds_HM' + id] < 0 && window['hours_HM' + id] == 0) 415 { 416 delete window['hours_HM' + id]; 417 delete window['minutes_HM' + id]; 418 delete window['seconds_HM' + id]; 419 clearInterval(window['timer_HM' + id]); 420 timeUp($this, opts); 421 } 422 } 423 id = null; 424 } 425 426 //Function for minutes and seconds are set when invoking plugin. 427 function minutesSeconds($this, opts) { 428 var id = $this.attr('id'); 429 if (window['minutes_MS' + id] == opts.minutes && window['seconds_MS' + id] == opts.seconds) { 430 if (window['minutes_MS' + id].toString().length < 2) { 431 window['minutes_MS' + id] = "0" + window['minutes_MS' + id]; 432 } 433 if (window['seconds_MS' + id].toString().length < 2) { 434 window['seconds_MS' + id] = "0" + window['seconds_MS' + id]; 435 } 436 html($this, window['minutes_MS' + id] + opts.timeSeparator + window['seconds_MS' + id]); 437 if (window['minutes_MS' + id] != 0 && window['seconds_MS' + id] == 0) { 438 window['minutes_MS' + id]--; 439 window['seconds_MS' + id] = 60 - opts.tickInterval; 440 } else if (window['minutes_MS' + id] == 0 && window['seconds_MS' + id] == 0) { 441 delete window['hours_MS' + id]; 442 delete window['minutes_MS' + id]; 443 delete window['seconds_MS' + id]; 444 clearInterval(window['timer_MS' + id]); 445 timeUp($this, opts); 446 } else { 447 window['seconds_MS' + id] -= opts.tickInterval; 448 } 449 } else { 450 if (window['minutes_MS' + id].toString().length < 2) { 451 window['minutes_MS' + id] = "0" + window['minutes_MS' + id]; 452 } 453 if (window['seconds_MS' + id].toString().length < 2) { 454 window['seconds_MS' + id] = "0" + window['seconds_MS' + id]; 455 } 456 html($this, window['minutes_MS' + id] + opts.timeSeparator + window['seconds_MS' + id]); 457 window['seconds_MS' + id] -= opts.tickInterval; 458 if (window['minutes_MS' + id] != 0 && window['seconds_MS' + id] < 0) { 459 window['minutes_MS' + id]--; 460 window['seconds_MS' + id] = 60 - opts.tickInterval; 461 } 462 if (window['minutes_MS' + id] == 0 && window['seconds_MS' + id] < 0) 463 { 464 delete window['hours_MS' + id]; 465 delete window['minutes_MS' + id]; 466 delete window['seconds_MS' + id]; 467 clearInterval(window['timer_MS' + id]); 468 timeUp($this, opts); 469 } 470 } 471 id = null; 472 } 473 474 //Function for hours and seconds are set when invoking plugin. 475 function hoursSeconds($this, opts) { 476 var id = $this.attr('id'); 477 if (window['seconds_HS' + id] == opts.seconds && window['hours_HS' + id] == opts.hours) { 478 if (window['hours_HS' + id].toString().length < 2) { 479 window['hours_HS' + id] = "0" + window['hours_HS' + id]; 480 } 481 if (window['seconds_HS' + id].toString().length < 2) { 482 window['seconds_HS' + id] = "0" + window['seconds_HS' + id]; 483 } 484 html($this, window['hours_HS' + id] + opts.timeSeparator + "00" + opts.timeSeparator + window['seconds_HS' + id]); 485 if (window['hours_HS' + id] == 0 && window['seconds_HS' + id] == 0) { 486 delete window['hours_HS' + id]; 487 delete window['minutes_HS' + id]; 488 delete window['seconds_HS' + id]; 489 clearInterval(window['timer_HS' + id]); 490 timeUp($this, opts); 491 } else if (window['hours_HS' + id] != 0 && window['seconds_HS' + id] == 0) { 492 window['hours_HS' + id]--; 493 window['minutes_HS' + id] = 59; 494 window['seconds_HS' + id] = 60 - opts.tickInterval; 495 } else { 496 window['seconds_HS' + id] -= opts.tickInterval; 497 } 498 } else { 499 if (window['hours_HS' + id].toString().length < 2) { 500 window['hours_HS' + id] = "0" + window['hours_HS' + id]; 501 } 502 if (window['minutes_HS' + id].toString().length < 2) { 503 window['minutes_HS' + id] = "0" + window['minutes_HS' + id]; 504 } 505 if (window['seconds_HS' + id].toString().length < 2) { 506 window['seconds_HS' + id] = "0" + window['seconds_HS' + id]; 507 } 508 html($this, window['hours_HS' + id] + opts.timeSeparator + window['minutes_HS' + id] + opts.timeSeparator + window['seconds_HS' + id]); 509 window['seconds_HS' + id] -= opts.tickInterval; 510 if (window['minutes_HS' + id] != 0 && window['seconds_HS' + id] < 0) { 511 window['minu
511tes_HS' + id]--; 512 window['seconds_HS' + id] = 60 - opts.tickInterval; 513 } 514 if (window['minutes_HS' + id] == 0 && window['seconds_HS' + id] < 0 && window['hours_HS' + id] != 0) 515 { 516 window['hours_HS' + id]--; 517 window['minutes_HS' + id] = 59; 518 window['seconds_HS' + id] = 60 - opts.tickInterval; 519 } 520 if (window['minutes_HS' + id] == 0 && window['seconds_HS' + id] < 0 && window['hours_HS' + id] == 0) 521 { 522 delete window['hours_HS' + id]; 523 delete window['minutes_HS' + id]; 524 delete window['seconds_HS' + id]; 525 clearInterval(window['timer_HS' + id]); 526 timeUp($this, opts); 527 } 528 } 529 id = null; 530 } 531 532 //Function for hours, minutes and seconds are set when invoking plugin. 533 function hoursMinutesSeconds($this, opts) { 534 var id = $this.attr('id'); 535 if (window['minutes_HMS' + id] == opts.minutes && window['seconds_HMS' + id] == opts.seconds && window['hours_HMS' + id] == opts.hours) { 536 if (window['hours_HMS' + id].toString().length < 2) { 537 window['hours_HMS' + id] = "0" + window['hours_HMS' + id]; 538 } 539 if (window['minutes_HMS' + id].toString().length < 2) { 540 window['minutes_HMS' + id] = "0" + window['minutes_HMS' + id]; 541 } 542 if (window['seconds_HMS' + id].toString().length < 2) { 543 window['seconds_HMS' + id] = "0" + window['seconds_HMS' + id]; 544 } 545 html($this, window['hours_HMS' + id] + opts.timeSeparator + window['minutes_HMS' + id] + opts.timeSeparator + window['seconds_HMS' + id]); 546 if (window['hours_HMS' + id] == 0 && window['minutes_HMS' + id] == 0 && window['seconds_HMS' + id] == 0) { 547 delete window['hours_HMS' + id]; 548 delete window['minutes_HMS' + id]; 549 delete window['seconds_HMS' + id]; 550 clearInterval(window['timer_HMS' + id]); 551 timeUp($this, opts); 552 } else if (window['hours_HMS' + id] != 0 && window['minutes_HMS' + id] == 0 && window['seconds_HMS' + id] == 0) { 553 window['hours_HMS' + id]--; 554 window['minutes_HMS' + id] = 59; 555 window['seconds_HMS' + id] = 60 - opts.tickInterval; 556 } else if (window['hours_HMS' + id] == 0 && window['minutes_HMS' + id] != 0 && window['seconds_HMS' + id] == 0) { 557 window['minutes_HMS' + id]--; 558 window['seconds_HMS' + id] = 60 - opts.tickInterval; 559 } else if (window['hours_HMS' + id] != 0 && window['minutes_HMS' + id] != 0 && window['seconds_HMS' + id] == 0) { 560 window['minutes_HMS' + id]--; 561 window['seconds_HMS' + id] = 60 - opts.tickInterval; 562 } else { 563 window['seconds_HMS' + id] -= opts.tickInterval; 564 } 565 } else { 566 if (window['hours_HMS' + id].toString().length < 2) { 567 window['hours_HMS' + id] = "0" + window['hours_HMS' + id]; 568 } 569 if (window['minutes_HMS' + id].toString().length < 2) { 570 window['minutes_HMS' + id] = "0" + window['minutes_HMS' + id]; 571 } 572 if (window['seconds_HMS' + id].toString().length < 2) { 573 window['seconds_HMS' + id] = "0" + window['seconds_HMS' + id]; 574 } 575 html($this, window['hours_HMS' + id] + opts.timeSeparator + window['minutes_HMS' + id] + opts.timeSeparator + window['seconds_HMS' + id]); 576 window['seconds_HMS' + id] -= opts.tickInterval; 577 if (window['minutes_HMS' + id] != 0 && window['seconds_HMS' + id] < 0) { 578 window['minutes_HMS' + id]--; 579 window['seconds_HMS' + id] = 60 - opts.tickInterval; 580 } 581 if (window['minutes_HMS' + id] == 0 && window['seconds_HMS' + id] < 0 && window['hours_HMS' + id] != 0) 582 { 583 window['hours_HMS' + id]--; 584 window['minutes_HMS' + id] = 59;
585 window['seconds_HMS' + id] = 60 - opts.tickInterval; 586 } 587 if (window['minutes_HMS' + id] == 0 && window['seconds_HMS' + id] < 0 && window['hours_HMS' + id] == 0) 588 { 589 delete window['hours_HMS' + id]; 590 delete window['minutes_HMS' + id]; 591 delete window['seconds_HMS' + id]; 592 clearInterval(window['timer_HMS' + id]); 593 timeUp($this, opts); 594 } 595 } 596 id = null; 597 } 598 599 //Function for reverse timer to given date. 600 function givenDate($this, opts, type) { 601 var id = $this.attr('id'); 602 var endDate = (type == "withnoStart") ? window['dateTime' + id] : window['endDate' + id]; 603 var startDate = (type == "withnoStart") ? window['startTime' + id] : window['startDate' + id]; 604 var days = Math.floor((endDate - startDate) / (24 * 60 * 60 * 1000)); 605 var hours = Math.floor(((endDate - startDate) % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000)); 606 var minutes = Math.floor(((endDate - startDate) % (24 * 60 * 60 * 1000)) / (60 * 1000)) % 60; 607 var seconds = Math.floor(((endDate - startDate) % (24 * 60 * 60 * 1000)) / 1000) % 60 % 60; 608 609 if ((endDate - startDate) > 0) { 610 if (days.toString().length < 2) { 611 days = "0" + days; 612 } 613 if (hours.toString().length < 2) { 614 hours = "0" + hours; 615 } 616 if (minutes.toString().length < 2) { 617 minutes = "0" + minutes; 618 } 619 if (seconds.toString().length < 2) { 620 seconds = "0" + seconds; 621 } 622 html($this, days + opts.timeSeparator + hours + opts.timeSeparator + minutes + opts.timeSeparator + seconds); 623 (type == "withnoStart") ? (window['startTime' + id].setSeconds(window['startTime' + id].getSeconds() + opts.tickInterval)) : (window['startDate' + id].setSeconds(window['startDate' + id].getSeconds() + opts.tickInterval)); 624 } else { 625 html($this, "00" + opts.timeSeparator + "00" + opts.timeSeparator + "00" + opts.timeSeparator + "00"); 626 if (type == "withnoStart") { 627 delete window['dateTime' + id]; 628 delete window['startTime' + id]; 629 clearInterval(window['timer_givenDate' + id]); 630 } else if (type == "withStart") { 631 delete window['startDate' + id]; 632 delete window['endDate' + id]; 633 clearInterval(window['timer_startDate' + id]); 634 } 635 timeUp($this, opts); 636 } 637 id = null; 638 } 639 640 //Function for displaying current time. 641 function currentDate($this, opts) { 642 if (window['currentTime' + $this.attr('id')] == true) { 643 var today = new Date(); 644 var hours = today.getHours(); 645 var minutes = today.getMinutes(); 646 var seconds = today.getSeconds() 647 648 if (hours.toString().length < 2) { 649 hours = "0" + hours; 650 } 651 if (minutes.toString().length < 2) { 652 minutes = "0" + minutes; 653 } 654 if (seconds.toString().length < 2) { 655 seconds = "0" + seconds; 656 } 657 html($this, hours + opts.timeSeparator + minutes + opts.timeSeparator + seconds); 658 } else { 659 alert('Set Current Time option.'); 660 } 661 } 662 663 //Default function called when no options are set. 664 function secondsTimer($this) { 665 var id = $this.attr('id'); 666 if (window['countSeconds' + id].toString().length < 2) { 667 window['countSeconds' + id] = "0" + window['countSeconds' + id]; 668 } 669 html($this, window['countSeconds' + id] + " " + "sec"); 670 window['countSeconds' + id]--; 671 if (window['countSeconds' + id] == -1) 672 { 673 delete window['countSeconds' + id]; 674 clearInterval(window['timer_secondsTimer' + id]); 675 } 676 id = null; 677 } 678 679 //Function for calling the given function name when time is expired. 680 function timeUp($this, opts) { 681 if (opts.timeUp != null) { 682 if ($.isFunction(opts.timeUp) == true) { 683 opts.timeUp.apply($this, []); 684 } 685 } 686 if (opts.expiryUrl != null) { 687 window.location = opts.expiryUrl; 688 } 689 } 690 691 //Function for displaying the timer. 692 function html($this, content) { 693 var processedContent = content; 694 if (typeof window['regexpMatchFormat_' + $this.attr('id')] !== 'undefined' && 695 typeof window['regexpReplaceWith_' + $this.attr('id')] !== 'undefined') { 696 var regexp = new RegExp(window['regexpMatchFormat_' + $this.attr('id')]); 697 processedContent = content.replace(regexp, 698 window['regexpReplaceWith_' + $this.attr('id')]); 699 } 700 $this.html(processedContent); 701 } 702 703 //Function to Pause/Resume Timer. 704 function pauseTimer($this, timerType, opts, func) { 705 $("#" + opts.pauseButton).click(function () { 706 if ($(this).val() != "resume") { 707 $("#" + opts.pauseButton).val("resume").text("Resume"); 708 clearInterval(window['timer_' + timerType + $this.attr('id')]); 709 } 710 else if ($(this).val() == "resume") { 711 $("#" + opts.pauseButton).val("pause").text("Pause"); 712 window['timer_' + timerType + $this.attr('id')] = setInterval(function () { 713 func($this, opts) 714 }, opts.tickInterval * 1000); 715 } 716 }); 717 } 718 719 //Function to Start/Stop Timer. 720 function stopTimer($this, timerType, opts, func) { 721 $("#" + opts.stopButton).click(function () { 722 if ($(this).val() != "start") { 723 $("#" + opts.stopButton).val("start").text("Start"); 724 clearInterval(window['timer_' + timerType + $this.attr('id')]); 725 window['hours_' + timerType + $this.attr('id')] = opts.hours; 726 window['minutes_' + timerType + $this.attr('id')] = opts.minutes; 727 window['seconds_' + timerType + $this.attr('id')] = opts.seconds; 728 func($this, opts); 729 } 730 else if ($(this).val() == "start") { 731 $("#" + opts.stopButton).val("stop").text("Stop"); 732 window['timer_' + timerType + $this.attr('id')] = setInterval(function () { 733 func($this, opts) 734 }, opts.tickInterval * 1000); 735 } 736 }); 737 } 738 739 //Giving default value for options. 740 $.fn.countdowntimer.defaults = { 741 hours: 0, 742 minutes: 0, 743 seconds: 60, 744 startDate: new Date(), 745 dateAndTime: new Date("0000/00/00 00:00:00"), 746 currentTime: false, 747 size: "sm", 748 borderColor: "#F0068E", 749 fontColor: "#FFFFFF", 750 backgroundColor: "#000000", 751 timeSeparator: ":", 752 tickInterval: 1, 753 timeUp: null, 754 expiryUrl: null, 755 regexpMatchFormat: null, 756 regexpReplaceWith: null, 757 pauseButton: null, 758 stopButton: null 759 }; 760 761}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.