1"use strict"; 2 3/** 4 * @name jQuery Countdown Plugin 5 * @author Martin Angelov 6 * @version 1.0 7 * @url http://tutorialzine.com/2011/12/countdown-jquery/ 8 * @license MIT License 9 */ 10(function ($) { 11 // Number of seconds in every time division 12 var days = 24 * 60 * 60, 13 hours = 60 * 60, 14 minutes = 60; // Creating the plugin 15 16 $.fn.countdown = function (prop) { 17 var options = $.extend({ 18 callback: function callback() {}, 19 timestamp: 0 20 }, prop); 21 var left, d, h, m, s, positions; // Initialize the plugin 22 23 init(this, options); 24 positions = this.find('.position'); 25 26 (function tick() { 27 // Time left 28 left = Math.floor((options.timestamp - new Date()) / 1000); 29 30 if (left < 0) { 31 left = 0; 32 } // Number of days left 33 34 35 d = Math.floor(left / days); 36 updateDuo(0, 1, d); 37 left -= d * days; // Number of hours left 38 39 h = Math.floor(left / hours); 40 updateDuo(2, 3, h); 41 left -= h * hours; // Number of minutes left 42 43 m = Math.floor(left / minutes); 44 updateDuo(4, 5, m); 45 left -= m * minutes; // Number of seconds left 46 47 s = left; 48 updateDuo(6, 7, s); // Calling an optional user supplied callback 49 50 options.callback(d, h, m, s); // Scheduling another call of this function in 1s 51 52 setTimeout(tick, 1000); 53 })(); // This function updates two digit positions at once 54 55 56 function updateDuo(minor, major, value) { 57 switchDigit(positions.eq(minor), Math.floor(value / 10) % 10); 58 switchDigit(positions.eq(major), value % 10); 59 } 60 61 return this; 62 }; 63 64 function init(elem, options) { 65 elem.addClass('countdownHolder'); // Creating the markup inside the container 66 67 $.each({ 68 Days: daysStr, 69 Hours: hoursStr, 70 Minutes: minutesStr, 71 Seconds: secondsStr 72 }, function (key, i) { 73 $('<span class="count' + key + '">').html('<div class="countdown_label h4">' + this + '</div>\ 74 <span class="position h1">\ 75 <span class="digit static h1">0</span>\ 76 </span>\ 77 <span class="position h1">\ 78 <span class="digit static h1">0</span>\ 79 </span>').appendTo(elem); 80 81 if (key != "Seconds") { 82 elem.append('<span class="countDiv countDiv' + key + '"></span>'); 83 } 84 }); 85 } // Creates an animated transition between the two numbers 86 87 88 function switchDigit(position, number) { 89 var digit = position.find('.digit'); 90 91 if (digit.is(':animated')) { 92 return false; 93 } 94 95 if (position.data('digit') == number) { 96 // We are already showing this number 97 return false; 98 } 99 100 position.data('digit', number); 101 var replacement = $('<span>', { 102 'class': 'digit', 103 css: { 104 top: '-20px', 105 opacity: 0 106 }, 107 html: number 108 }); // The .static class is added when the animation 109 // completes. This makes it run smoother. 110 111 digit.before(replacement).removeClass('static').animate({ 112 top: '20px', 113 opacity: 0 114 }, 'fast', function () { 115 digit.remove(); 116 }); 117 replacement.delay(100).animate({ 118 top: 0, 119 opacity: 1 120 }, 'fast', function () { 121 replacement.addClass('static'); 122 }); 123 } 124})(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.