/////////////////////////////////////////////////////////// // Avoid PHP code here. So we can use this very intelligent // script outside of Joomla! framework with a minimum of // effort. /** The id of clock 'div'. */ var CLOCK_DIV_ID = "clock"; /** The clock number width (in em). */ var CLOCK_NUMBER_WIDTH = "1.7em"; /////////////////////////////////////////////////////////// // The following parameters are user specific. /** Font family used by the clock. */ var fontFamily = "verdana, helvetica, arial, sans-serif"; /** Font size used by the clock. */ var fontSize = "10px"; /** Colour of clock numbers. */ var colnumbers = "#000000"; /** Colour of hour watch hand. */ var colhours = "#000000"; /** Colour of minute watch hand. */ var colminutes = "#000000"; /** Colour of second watch hand. */ var colseconds = "#000000"; /** The clock width. In the current implementation it equals the height. */ var width = 80; /** * The numbers style chosen for this clock. * This is an index in clocknum array object. */ var numstyle = 0; // /////////////////////////////////////////////////////////// /** * Common or default clock style. *

* Do not forget to close this with a semicolon ';'. *

*/ var comstyle = "position:absolute;top:0px;left:0px;visibility:hidden;"; /** Length of second hand. */ var secln = width / 2; /** Length of minute hand. */ var minln = width / 2; /** * Length of hour hand. *

* Just a bit smaller than second resp. minute hand. *

*/ var hourln = width / 3; /** The clock numbers style. '·' stands for 'middle dot'. */ var clocknum = [ ['','1','2','3','4','5','6','7','8','9','10','11','12'], ['','I','II','III','IIII','V','VI','VII','VIII','IX','X','XI','XII'], ['','·','·','-','·','·','|','·','·','-','·','·','||'] ]; /** Convenience variable which contains MATH.PI. */ var pi = Math.PI; /** Convenience variable which contains MATH.PI / 2. */ var pi2 = pi / 2; /** * The offset is computed on-the-fly. This a clock number box width divided by 2. *

* As the clock number box width is given in em, we let the navigator to make * the conversion in px. *

*/ var offset; /** The clock y-coordinate offset. By default, this value is zero. */ var dy = 0; /** The clock x-coordinate offset. By default, this value is zero. */ var dx = 0; /** * Sets current width. * By doing so, udpates minln, hourln and secln * as well. */ function setWidth(width) { this.width = width; secln = minln = width / 2; hourln = width / 3; } /** * Returns a suitable time for given Date. Returned array has following * format: [hour, minute, second]. */ function getTime(time) { var second = time.getSeconds(); var minute = time.getMinutes(); var hour = time.getHours(); return [hour, minute, second]; } /** * Creates 12 'div' elements inside the element 'datehour' for the clock numbers. *

* Created elements have an index of z-index of 1000 (the bigger the number is, the more ahead the element lies). *

*/ function createClockNumbers() { var clockDiv = document.getElementById(CLOCK_DIV_ID); var innerHTML = ''; for (var i = 1; i < 13; i++) { innerHTML += '
' + clocknum[numstyle][i] + '<\/div>'; } clockDiv.innerHTML += innerHTML; } /** Whether the given value is empty. */ function isEmpty(value) { return value == null || (value + "").replace(/^\s+|\s+$/, '') == ''; } /** * Displays the clock numbers by positioning their layer and making it visible. */ function displayClock() { for (var i = 1; i < 13; i++) { var element = document.getElementById("cnum" + i); if (isEmpty(offset)) { offset = [element.offsetWidth, element.offsetHeight]; } var halfWidth = width / 2; element.style.top = dy + halfWidth * (1 + Math.sin(i * pi / 6 - pi2)) + "px"; element.style.left = dx + halfWidth * (1 + Math.cos(i * pi / 6 - pi2)) + "px"; element.style.visibility = "visible"; } } /** * Create watch hands (minute, hour and second). */ function createWatchHands() { var datehour = document.getElementById(CLOCK_DIV_ID); var innerHTML = ''; for (var i = 0; i < hourln; i++) { innerHTML += '
<\/div>'; } for (var i = 0; i < minln; i++) { innerHTML += '
<\/div>'; } for (var i = 0; i < secln; i++) { innerHTML += '
<\/div>'; } datehour.innerHTML += innerHTML; } /** * Updates watch hands. */ function updateClock(time) { var theTime = getTime(time); var hour = theTime[0]; if (hour > 11) { hour -= 12; } var aSecond = pi * theTime[2] / 30 - pi2; var aMinute = pi * theTime[1] / 30 - pi2; var aHour = pi * theTime[0] / 6 + pi * parseInt(theTime[1]) / 360 - pi2; var halfWidth = width / 2; var offsetHalfWidth = offset[0] / 2; var offsetHalfHeight = offset[1] / 2; for (var i = 0; i < secln; i++) { var element = document.getElementById("csec" + i); element.style.top = dy + halfWidth + offsetHalfHeight + i * Math.sin(aSecond) + "px"; element.style.left = dx + halfWidth + offsetHalfWidth + i * Math.cos(aSecond) + "px"; element.style.visibility = "visible"; } for (var i = 0; i < minln; i++) { var element = document.getElementById("cmin" + i); element.style.top = dy + halfWidth + offsetHalfHeight + i * Math.sin(aMinute) + "px"; element.style.left = dx + halfWidth + offsetHalfWidth + i * Math.cos(aMinute) + "px"; element.style.visibility = "visible"; } for (var i = 0; i < hourln; i++) { var element = document.getElementById("chour" + i); element.style.top = dy + halfWidth + offsetHalfHeight + i * Math.sin(aHour) + "px"; element.style.left = dx + halfWidth + offsetHalfWidth + i * Math.cos(aHour) + "px"; element.style.visibility = "visible"; } } /** Sets dimension (width and height) of CLOCK_DIV_ID. */ function setParentDimension() { var clockDiv = document.getElementById(CLOCK_DIV_ID); clockDiv.style.width = width + offset[0] + "px"; clockDiv.style.height = width + offset[1] + "px"; } /** * This is the main method. Creates the clock but does not update it. *

* To do so, you have to call updateClock(). *

*/ function createClock() { offset = null; createClockNumbers(); createWatchHands(); // Sets offset. displayClock(); setParentDimension(); }