1/** 2 * @file 3 * @brief Javascript for the Clock Plugin 4 */ 5 6// id of the clock face. DONT CHANGE THIS UNLESS YOU KNOW WHAT YOU ARE DOING! 7var jsclock_id= "dw_clock_object"; 8 9if(!document.getElementById("dw__editform")) { 10 var dwClockTimer; // timer object 11 var dwClockDOMObject; // DOM container 12 var dwPar; 13} 14 15function dwclock_adjustTZ(date, tzString, localeString) { 16 return new Date((typeof date === "string" ? new Date(date) : date).toLocaleString(localeString, {timeZone: tzString})); 17} 18 19// 20class dwClock { 21 time_; 22 23 constructor() { 24 this.time_= new Date(); 25 } 26 27 get time() { return this.time_; } 28 get h() { return this.time_.getHours(); } 29 get m() { return this.time_.getMinutes(); } 30 get s() { return this.time_.getSeconds(); } 31 32 tick () { 33 this.time_= new Date(); 34 } 35 36 format (fmt) { 37 return time_.toLocaleString(fmt); 38 } 39 40 formatArgs (fmt, args) { 41 return time_.toLocaleString(fmt, args); 42 } 43}; 44 45class dwClock_Text extends dwClock { 46 update ( obj ) { 47 super.tick(); 48 var cT= this.time; 49 var Ahh= cT.getHours(); 50 var Amm= cT.getMinutes(); 51 var Ass= cT.getSeconds(); 52 // format it as ISO 8601 text 53 if (Ahh<=9 && Ahh>=0) Ahh= "0" + Ahh; 54 if (Amm<=9 && Amm>=0) Amm= "0" + Amm; 55 if (Ass<=9 && Ass>=0) Ass= "0" + Ass; 56 var timetext= " " + Ahh + ":" + Amm + ":" + Ass + " "; 57 // assign text to element with id as 'jsclock_id' variable 58 obj.innerHTML= timetext; 59 } 60}; 61 62 63function dwclock_tick () { 64 dwClockTimer.update(dwClockDOMObject); 65 setTimeout(dwclock_tick, 500); 66} 67 68jQuery( function() { 69if(document.getElementById("dw__editform")) { return; } 70 dwClockDOMObject = document.getElementById(jsclock_id); 71 dwPar= dwClockDOMObject.parentElement; 72 dwClockTimer= new dwClock_Text(); 73} ); 74 75jQuery( function() { 76 if(document.getElementById("dw__editform")) { return; } 77 dwclock_tick(); 78} ); 79 80// end of clock/script.js 81