1//var wc_format = "hhmmssdA"; 2//var wc_format = "HHmmssd"; 3function setCookie(cname, cvalue, exdays) { 4 var d = new Date(); 5 d.setTime(d.getTime() + (exdays*24*60*60*1000)); 6 var expires = "expires="+d.toUTCString(); 7 document.cookie = cname + "=" + cvalue + "; " + expires; 8} 9 10function getCookie(cname) { 11 var name = cname + "="; 12 var ca = document.cookie.split(';'); 13 for(var i=0; i<ca.length; i++) { 14 var c = ca[i]; 15 while (c.charAt(0)==' ') c = c.substring(1); 16 if (c.indexOf(name) == 0) return c.substring(name.length, c.length); 17 } 18 return ""; 19} 20 21jQuery(function(){ 22 23 24 //If timezone cookie not set 25 if(getCookie("wc_timezone").length == 0){ 26 27 //Get ip 28 jQuery.getJSON('http://jsonip.com/?callback=?', function(r){ 29 setCookie("wc_ip",r.ip,60); 30 }); 31 32 jQuery.getJSON( "http://ip-api.com/json/"+getCookie("wc_ip") ).done(function(json){ 33 34 setCookie("wc_timezone",json.timezone,60); 35 }) 36 } 37 38 // Cache some selectors 39 40 var clock = jQuery('#world_clock_widget'); 41 42 // Map digits to their names (this will be an array) 43 var digit_to_name = 'zero one two three four five six seven eight nine'.split(' '); 44 45 // This object will hold the digit elements 46 var digits = {}; 47 48 // Positions for the hours, minutes, and seconds 49 var positions = [ 50 'h1', 'h2', ':', 'm1', 'm2', ':', 's1', 's2' 51 ]; 52 53 // Generate the digits with the needed markup, 54 // and add them to the clock 55 56 var digit_holder = clock.find('.digits'); 57 58 jQuery.each(positions, function(){ 59 60 if(this == ':'){ 61 digit_holder.append('<div class="dots">'); 62 } 63 else{ 64 65 var pos = jQuery('<div>'); 66 67 for(var i=1; i<8; i++){ 68 pos.append('<span class="d' + i + '">'); 69 } 70 71 // Set the digits as key:value pairs in the digits object 72 digits[this] = pos; 73 74 // Add the digit elements to the page 75 digit_holder.append(pos); 76 } 77 78 }); 79 80 81 // Run a timer every second and update the clock 82 83 (function update_time(){ 84 85 // Use moment.js to output the current time as a string 86 // hh is for the hours in 12-hour format, 87 // mm - minutes, ss-seconds (all with leading zeroes), 88 // d is for day of week and A is for AM/PM 89 90 var now = moment(); 91 92 var timezone = getCookie("wc_timezone"); 93 if(timezone.length == 0 ) 94 timezone = moment.tz.guess(); 95 96 now = now.tz(timezone).format(wc_format); 97 98 99 digits.h1.attr('class', digit_to_name[now[0]]); 100 digits.h2.attr('class', digit_to_name[now[1]]); 101 digits.m1.attr('class', digit_to_name[now[2]]); 102 digits.m2.attr('class', digit_to_name[now[3]]); 103 digits.s1.attr('class', digit_to_name[now[4]]); 104 digits.s2.attr('class', digit_to_name[now[5]]); 105 106 // The library returns Sunday as the first day of the week. 107 // Stupid, I know. Lets shift all the days one position down, 108 // and make Sunday last 109 110 var dow = now[6]; 111 dow--; 112 113 // Sunday! 114 if(dow < 0){ 115 // Make it last 116 dow = 6; 117 } 118 119 // Set the am/pm text: 120 if(wc_format == "hhmmssdA") 121 jQuery('.ampm').text(now[7]+now[8]); 122 123 // Schedule this function to be run again in 1 sec 124 setTimeout(update_time, 1000); 125 126 })(); 127 128});
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.