1// CountDown Clock 2// Version : 1.0.2 3// Developer : Ekrem KAYA 4// Website : https://e-piksel.com 5// GitHub : https://github.com/epiksel/countdown 6 7(function ($) { 8 $.fn.countdown = function (options, callback) { 9 var settings = $.extend({ 10 date: null, 11 offset: null, 12 day: 'Day', 13 days: 'Days', 14 hour: 'Hour', 15 hours: 'Hours', 16 minute: 'Minute', 17 minutes: 'Minutes', 18 second: 'Second', 19 seconds: 'Seconds', 20 hideOnComplete: false 21 }, options); 22 23 // Throw error if date is not set 24 if (!settings.date) { 25 $.error('Date is not defined.'); 26 } 27 28 // Throw error if date is set incorectly 29 if (!Date.parse(settings.date)) { 30 $.error('Incorrect date format, it should look like this, 12/24/2012 12:00:00.'); 31 } 32 33 // Save container 34 var container = this; 35 36 /** 37 * Change client's local date to match offset timezone 38 * @return {Object} Fixed Date object. 39 */ 40 var currentDate = function () { 41 // get client's current date 42 var date = new Date(); 43 44 // turn date to utc 45 var utc = date.getTime() + (date.getTimezoneOffset() * 60000); 46 47 // set new Date object 48 var new_date = new Date(utc + (3600000*settings.offset)); 49 50 return new_date; 51 }; 52 53 /** 54 * Main countdown function that calculates everything 55 */ 56 function countdown() { 57 var target_date = new Date(settings.date), // set target date 58 current_date = currentDate(); // get fixed current date 59 60 // difference of dates 61 var difference = target_date - current_date; 62 63 // if difference is negative than it's pass the target date 64 if (difference < 0) { 65 // stop timer 66 clearInterval(interval); 67 68 if (settings.hideOnComplete) { 69 $(container).hide(); 70 } 71 72 if (callback && typeof callback === 'function') { 73 callback(container); 74 } 75 76 return; 77 } 78 79 // basic math variables 80 var _second = 1000, 81 _minute = _second * 60, 82 _hour = _minute * 60, 83 _day = _hour * 24; 84 85 // calculate dates 86 var days = Math.floor(difference / _day), 87 hours = Math.floor((difference % _day) / _hour), 88 minutes = Math.floor((difference % _hour) / _minute), 89 seconds = Math.floor((difference % _minute) / _second); 90 91 // based on the date change the refrence wording 92 var text_days = (days === 1) ? settings.day : settings.days, 93 text_hours = (hours === 1) ? settings.hour : settings.hours, 94 text_minutes = (minutes === 1) ? settings.minute : settings.minutes, 95 text_seconds = (seconds === 1) ? settings.second : settings.seconds; 96 97 // fix dates so that it will show two digets 98 days = (String(days).length >= 2) ? days : '0' + days; 99 hours = (String(hours).length >= 2) ? hours : '0' + hours; 100 minutes = (String(minutes).length >= 2) ? minutes : '0' + minutes; 101 seconds = (String(seconds).length >= 2) ? seconds : '0' + seconds; 102 103 // set to DOM 104 container.find('.days').text(days); 105 container.find('.hours').text(hours); 106 container.find('.minutes').text(minutes); 107 container.find('.seconds').text(seconds); 108 109 container.find('.days_text').text(text_days); 110 container.find('.hours_text').text(text_hours); 111 container.find('.minutes_text').text(text_minutes); 112 container.find('.seconds_text').text(text_seconds); 113 } 114 115 // start 116 var interval = setInterval(countdown, 1000); 117 }; 118 119})(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.