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