1/** 2 * downCount: Simple Countdown clock with offset 3 * Author: Sonny T. <[email protected]>, sonnyt.com 4 */ 5 6(function ($) { 7 8 $.fn.downCount = function (options, callback) { 9 var settings = $.extend({ 10 date: null, 11 offset: null 12 }, options); 13 14 // Throw error if date is not set 15 if (!settings.date) { 16 $.error('Date is not defined.'); 17 } 18 19 // Throw error if date is set incorectly 20 if (!Date.parse(settings.date)) { 21 $.error('Incorrect date format, it should look like this, 12/24/2012 12:00:00.'); 22 } 23 24 // Save container 25 var container = this; 26 27 /** 28 * Change client's local date to match offset timezone 29 * @return {Object} Fixed Date object. 30 */ 31 /* var currentDate = function () { 32 // get client's current date 33 var date = new Date(); 34 35 // turn date to utc 36 var utc = date.getTime() + (date.getTimezoneOffset() * 60000); 37 38 // set new Date object 39 var new_date = new Date(utc + (3600000*settings.offset)) 40 41 return new_date; 42 };*/ 43 44 /** 45 * Main downCount function that calculates everything 46 */ 47 function countdown () { 48 49 var target_date = new Date(settings.date).getTime(), // set target date 50 current_date = new Date().getTime(); // get fixed current date 51 52 // difference of dates 53 var difference = target_date - current_date; 54 55 // if difference is negative than it's pass the target date 56 if (difference < 0) { 57 // stop timer 58 clearInterval(interval); 59 60 if (callback && typeof callback === 'function') callback(); 61 62 return; 63 } 64 65 // basic math variables 66 var _second = 1000, 67 _minute = _second * 60, 68 _hour = _minute * 60, 69 _day = _hour * 24; 70 71 // calculate dates 72 var days = Math.floor(difference / _day), 73 hours = Math.floor((difference % _day) / _hour), 74 minutes = Math.floor((difference % _hour) / _minute), 75 seconds = Math.floor((difference % _minute) / _second); 76 77 // fix dates so that it will show two digets 78 days = (String(days).length >= 2) ? days : '0' + days; 79 hours = (String(hours).length >= 2) ? hours : '0' + hours; 80 minutes = (String(minutes).length >= 2) ? minutes : '0' + minutes; 81 seconds = (String(seconds).length >= 2) ? seconds : '0' + seconds; 82 83 // based on the date change the refrence wording 84 var ref_days = (days === 1) ? 'day' : 'd', 85 ref_hours = (hours === 1) ? 'hour' : 'h', 86 ref_minutes = (minutes === 1) ? 'minute' : 'm', 87 ref_seconds = (seconds === 1) ? 'second' : 's'; 88 89 // set to DOM 90 container.find('.days').text(days); 91 container.find('.hours').text(hours); 92 container.find('.minutes').text(minutes); 93 container.find('.seconds').text(seconds); 94 95 container.find('.days_ref').text(ref_days); 96 container.find('.hours_ref').text(ref_hours); 97 container.find('.minutes_ref').text(ref_minutes); 98 container.find('.seconds_ref').text(ref_seconds); 99 }; 100 101 // start 102 var interval = setInterval(countdown, 1000); 103 }; 104 105})(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.