1jQuery(function ($) { 2 3 if ( 4 skilled_plugin && 5 skilled_plugin.data && 6 skilled_plugin.data.vcWidgets && 7 skilled_plugin.data.vcWidgets.countdown && 8 skilled_plugin.data.vcWidgets.countdown.items 9 ) { 10 11 12 var parser = /([0-9]{2})/gi; 13 var currDate = '00:00:00:00:00'; 14 var nextDate = '00:00:00:00:00'; 15 var newDateFormat = ''; 16 17 var symbols = { 18 years: '%Y', 19 months: '%m', 20 weeks: '%w', 21 days: '%d', 22 hours: '%H', 23 minutes: '%M', 24 seconds: '%S' 25 }; 26 27 var template = ''; 28 template += '<div class="time <%= label %>">'; 29 template += '<span class="count curr top"><%= curr %></span>'; 30 template += '<span class="count next top"><%= next %></span>'; 31 template += '<span class="count next bottom"><%= next %></span>'; 32 template += '<span class="count curr bottom"><%= curr %></span>'; 33 template += '<span class="label"><%= translation.length < 6 ? translation : translation.substr(0, 3) %></span>'; 34 template += '</div>'; 35 template = _.template(template); 36 37 $.each(skilled_plugin.data.vcWidgets.countdown.items, function (i, countdown) { 38 39 40 // Parse countdown string to an object 41 function strfobj(str) { 42 var parsed = str.match(parser), 43 obj = {}; 44 labels.forEach(function (label, i) { 45 if (parsed) { 46 obj[label] = parsed[i] 47 } 48 }); 49 return obj; 50 } 51 52 // Return the time components that diffs 53 function diff(obj1, obj2) { 54 var diff = []; 55 labels.forEach(function (key) { 56 if (obj1[key] !== obj2[key]) { 57 diff.push(key); 58 } 59 }); 60 return diff; 61 } 62 63 var out = ''; 64 var labels = countdown.options.labels.split(/[\s,]+/); 65 var labelTranslations = countdown.options.labelTranslations.split(/[\s,]+/); 66 var $countdown = $('#' + countdown.id); 67 68 // Build the layout 69 var initData = strfobj(currDate); 70 71 $.each(labels, function (i, label) { 72 73 var symbol = symbols[label]; 74 if (symbol) { 75 76 if (i) { 77 newDateFormat += ':' + symbol; 78 } else { 79 newDateFormat += symbol; 80 } 81 82 83 //out += '<div class="date-block"><span class="date ' + label + '">' + symbol + '</span><span class="label">' + label + '</span></div>'; 84 } 85 86 87 var translation =''; 88 if (labelTranslations.length && labelTranslations[i]) { 89 translation = labelTranslations[i]; 90 } else { 91 translation = label; 92 } 93 94 95 $countdown.append(template({ 96 curr: initData[label], 97 next: initData[label], 98 label: label, 99 translation: translation 100 })); 101 }); 102 103 //$countdown.countdown('2020/10/10', function (event) { 104 // var $this = $(this).html(event.strftime(out)); 105 //}); 106 107 108 109 $countdown.countdown(countdown.options.targetDate, function (event) { 110 111 var newDate = event.strftime(newDateFormat), 112 data; 113 114 if (newDate !== nextDate) { 115 currDate = nextDate; 116 nextDate = newDate; 117 // Setup the data 118 data = { 119 'curr': strfobj(currDate), 120 'next': strfobj(nextDate) 121 }; 122 // Apply the new values to each node that changed 123 diff(data.curr, data.next).forEach(function (label) { 124 var selector = '.%s'.replace(/%s/, label), 125 $node = $countdown.find(selector); 126 // Update the node 127 $node.removeClass('flip'); 128 $node.find('.curr').text(data.curr[label]); 129 $node.find('.next').text(data.next[label]); 130 // Wait for a repaint to then flip 131 _.delay(function ($node) { 132 $node.addClass('flip'); 133 }, 50, $node); 134 }); 135 } 136 }); 137 138 139 }); 140 141 142 } 143 144});
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.