1(function($) { 2 3 'use strict'; 4 5 $.fn.countdown = function(options, callback) { 6 7 // :: custom 'this' selector 8 var thisEl = $(this); 9 10 // :: array of custom settings 11 var settings = { 12 'date': null, 13 'format': null 14 }; 15 16 // :: append the settings array to options 17 if(options) { 18 $.extend(settings, options); 19 } 20 21 // :: main countdown function 22 function countdown_proc() { 23 24 var eventDate = Date.parse(settings['date']) / 1000; 25 var currentDate = Math.floor($.now() / 1000); 26 27 if(eventDate <= currentDate) { 28 callback.call(this); 29 clearInterval(interval); 30 } 31 32 var seconds = eventDate - currentDate; 33 34 var days = Math.floor(seconds / (60 * 60 * 24)); //calculate the number of days 35 seconds -= days * 60 * 60 * 24; //update the seconds variable with no. of days removed 36 37 var hours = Math.floor(seconds / (60 * 60)); 38 seconds -= hours * 60 * 60; //update the seconds variable with no. of hours removed 39 40 var minutes = Math.floor(seconds / 60); 41 seconds -= minutes * 60; //update the seconds variable with no. of minutes removed 42 43 // :: conditional Ss 44 if (days == 1) { thisEl.find(".timeRefDays").text("day"); } else { thisEl.find(".timeRefDays").text("days"); } 45 if (hours == 1) { thisEl.find(".timeRefHours").text("hour"); } else { thisEl.find(".timeRefHours").text("hours"); } 46 if (minutes == 1) { thisEl.find(".timeRefMinutes").text("minute"); } else { thisEl.find(".timeRefMinutes").text("minutes"); } 47 if (seconds == 1) { thisEl.find(".timeRefSeconds").text("second"); } else { thisEl.find(".timeRefSeconds").text("seconds"); } 48 49 // :: logic for the two_digits ON setting 50 if(settings['format'] == "on") { 51 var days = (String(days).length >= 2) ? days : "0" + days; 52 var hours = (String(hours).length >= 2) ? hours : "0" + hours; 53 var minutes = (String(minutes).length >= 2) ? minutes : "0" + minutes; 54 var seconds = (String(seconds).length >= 2) ? seconds : "0" + seconds; 55 } 56 57 // :: update the countdown's html values. 58 if(!isNaN(eventDate)) { 59 thisEl.find(".days").text(days); 60 thisEl.find(".hours").text(hours); 61 thisEl.find(".minutes").text(minutes); 62 thisEl.find(".seconds").text(seconds); 63 } else { 64 alert("Invalid date. Here's an example: 12 Tuesday 2012 17:30:00"); 65 clearInterval(interval); 66 } 67 } 68 69 // :: run the function 70 countdown_proc(); 71 72 // :: loop the function 73 var interval = setInterval(countdown_proc, 1000); 74 75 } 76}) (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.