home *** CD-ROM | disk | FTP | other *** search
- /* ======================================================================
- OBJECT: com_netobjects_DigitalClock
-
- PLATFORMS: Netscape Navigator 4.01 or higher,
- Microsoft Internet Explorer 4.02 or higher
-
- DESCRIPTION: This object displays a digital clock. The clock digits are
- represented as individual graphics which the object updates.
- Image names referenced for individual digits are:
-
- Digits 0-9: digitx.gif, where x is 0-9
- "AM" graphic: digitam.gif
- "PM" graphic: digitpm.gif
- Colon image: colon.gif, used for separating hours and minutes, e.g. hh:mm
- Digit placeholder: digit_.gif, where this graphic has the same background
- and is the same size as the other digit images. This image
- is used as a placeholder for the first hour digit when
- the hour is only a single digit, e.g. 1:30.
-
- To change the graphics used by the clock, simply replace each of the
- 14 graphics mentioned in the list above - USE THE SAME FILE NAMES.
-
- The clock can display 12 or 24 hour time. For 12 hour time, an am/pm
- graphic is added. Note that changing the mode of the clock requires a
- reload of the page before 12/24 hour time or displaying/hiding seconds
- can be changed on the page itself.
- ====================================================================== */
- function com_netobjects_DigitalClock(params) {
-
- // Public Properties
- this.name = (params.name != null) ? params.name : "";
- this.testMode = (params.testMode != null) ? params.testMode : "off";
-
- this.is12hours = (params.is12hours == "24 Hour") ? false : true;
-
- // Private Properties
- this.colonImagePrefix = "colon";
- this.imagePrefix = "digit";
- this.imageExt = ".gif";
- this.imageArray = new Array();
- this.timerID = null;
- this.rotateNo = 0;
- this.hh1 = 0;
- this.hh2 = 0;
- this.mm1 = 0;
- this.mm2 = 0;
- this.ampm = "am";
-
- // Public Methods
- this.render = _digitalclock_render;
- this.start = _digitalclock_start;
- this.stop = _digitalclock_stop;
-
- // Private Methods
- this.validateProperties = _digitalclock_validateProperties;
- this.getDigits = _digitalclock_getDigits;
-
- // Public Events
- this.onError = _digitalclock_onError;
- this.onAbort = _digitalclock_onAbort;
- this.onLoad = _digitalclock_onLoad;
- this.onRender = _digitalclock_onRender;
- this.onStart = _digitalclock_onStart;
- this.onStop = _digitalclock_onStop;
- this.onRotateImage = _digitalclock_onRotateImage;
-
- // Private Events (internal event driven functionality)
-
- // Validate object properties when test mode is on
- this.validateProperties();
-
-
- // Public Methods ----------------------------------------
-
- /* ======================================================================
-
- METHOD: _digitalclock_render. Renders the clock in HTML.
-
- ====================================================================== */
- function _digitalclock_render() {
- // Initialize Variables
- sBorder = "";
- eError = "";
- eAbort = "";
- eLoad = "";
-
- // Set Variables
- sBorder = " BORDER=0";
-
- // Build Nav & IE shared Image events
- eError = " onerror=\"" + this.name + ".onError();\""
- eAbort = " onabort=\"" + this.name + ".onAbort();\""
- eLoad = " onload=\"" + this.name + ".onLoad();\""
- eImgEvents = eError + eAbort + eLoad;
-
- // Set the hours, minutes properties
- this.getDigits(true);
-
- // Write IMG tags
- document.writeln("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR>");
- document.writeln("<TD><IMG NAME='Img_hh1' SRC='" + this.imagePrefix + this.hh1 + this.imageExt + "' " + sBorder + eImgEvents + "></TD>");
- document.writeln("<TD><IMG NAME='Img_hh2' SRC='" + this.imagePrefix + this.hh2 + this.imageExt + "' " + sBorder + eImgEvents + "></TD>");
- document.writeln("<TD><IMG SRC='" + this.colonImagePrefix + this.imageExt + "'></TD>"); // write out a colon every 2 digits, e.g. hh:mm:ss
- document.writeln("<TD><IMG NAME='Img_mm1' SRC='" + this.imagePrefix + this.mm1 + this.imageExt + "' " + sBorder + eImgEvents + "></TD>");
- document.writeln("<TD><IMG NAME='Img_mm2' SRC='" + this.imagePrefix + this.mm2 + this.imageExt + "' " + sBorder + eImgEvents + "></TD>");
-
- // For 12-hour mode, write out the AM or PM graphic
- if (this.is12hours)
- document.writeln("<TD><IMG NAME='Img_ampm' SRC='" + this.imagePrefix + this.ampm + this.imageExt + "' " + sBorder + eImgEvents + "></TD>");
- document.writeln("</TABLE>");
-
- // Start animation
- this.start();
-
- // Fire public events
- this.onRender();
- } // END _digitalclock_render
-
- /* ======================================================================
-
- METHOD: _popupwindow_start. Starts the timed updates of the clock. The
- clock is checked to see if it needs to be updated every second.
- The clock graphics are updated every minute.
-
- ====================================================================== */
- function _digitalclock_start(refresh) {
- var rotated = false;
- this.rotateNo++;
- if (refresh+"" == "undefined" || refresh == null)
- refresh = false;
-
- oldmm2 = this.mm2;
- // Update clock images every minute, which is whenever the current minute, this.mm2, has changed from its previous value
- this.getDigits(refresh);
- if (refresh || (this.mm2 != oldmm2)) {
- eval("window.document.Img_hh1.src=\"" + this.imagePrefix + this.hh1 + this.imageExt + "\"");
- eval("window.document.Img_hh2.src=\"" + this.imagePrefix + this.hh2 + this.imageExt + "\"");
- eval("window.document.Img_mm1.src=\"" + this.imagePrefix + this.mm1 + this.imageExt + "\"");
- eval("window.document.Img_mm2.src=\"" + this.imagePrefix + this.mm2 + this.imageExt + "\"");
- if (this.is12hours)
- eval("window.document.Img_ampm.src=\"" + this.imagePrefix + this.ampm + this.imageExt + "\"");
- rotated = true;
- }
-
- window.clearTimeout(this.timerID);
- // Set the JavaScript timer to re-execute this function every second
- this.timerID = window.setTimeout(this.name + ".start()", 1000);
-
- // Fire public events
- if (this.rotateNo == 1)
- this.onStart();
- if (rotated)
- this.onRotateImage();
- } // END _digitalclock_start
-
- /* ======================================================================
-
- METHOD: _digitalclock_start. Stops the JavaScript timer, and therefore
- will stop the clock. Note that when the clock is restarted, it will always
- reload the current, correct time.
-
- ====================================================================== */
- function _digitalclock_stop() {
- window.clearTimeout(this.timerID);
- this.rotateNo = 0;
-
- // Fire public events
- this.onStop();
- } // END _digitalclock_stop
-
-
- // Private Methods ----------------------------------------
-
- /* ======================================================================
-
- METHOD: _digitalclock_validateProperties. Used only in test mode. Writes out
- error and warning messages if some property values are set with bad
- values.
-
- ====================================================================== */
- function _digitalclock_validateProperties() {
- if ((this.testMode.toLowerCase() == "text") || (this.testMode.toLowerCase() == "alerts")) {
- var errors = new Array();
- iIndex = 0;
-
- // Check for errors
- if (this.name == "")
- errors[iIndex++] = "Name is a required property.";
-
- // Display errors
- for (var i=0; i<errors.length; i++) {
- if (this.testMode.toLowerCase() == "text")
- document.write( "<BR><HR><B><FONT COLOR=RED>TEST MODE, com_netobjects_DigitalClock, '" + this.name + "' : </FONT> " + errors[i] + "</B><HR>\n");
- else
- alert("TEST MODE, com_netobjects_DigitalClock, '" + this.name + "' : " + errors[i]);
- }
- }
- } // END _digitalclock_validateProperties
-
-
- /* ======================================================================
-
- METHOD: _digitalclock_getDigits. Gets the current time and parses out the
- individual digits for the hours and seconds. Sets object properties to store
- the parsed digits.
-
- ====================================================================== */
- function _digitalclock_getDigits(init) {
- rightNow = new Date();
- hh = rightNow.getHours();
- mm = rightNow.getMinutes()+"";
- seconds = rightNow.getSeconds();
-
- // Only update properties every minute, or if this is the first
- // time the function is called, as flagged by the init parameter.
- if (seconds == 0 || init) {
- this.ampm = "am";
- // If hours == 12, it's noon so set PM
- if (hh == 12)
- this.ampm = "pm";
- // if hours == 0, it's midnight so set to 12 hours for string parsing below
- if (this.is12hours && (hh == 0))
- hh = 12;
- // Convert 24-hour time to 12-hour am/pm time
- if (this.is12hours && (hh / 12 > 1)) {
- hh = (hh % 12);
- this.ampm = "pm";
- }
- hh += ""; // convert to string
- this.hh1 = (hh.length == 1) ? "_" : hh.charAt(0);
- this.hh2 = (hh.length == 1) ? hh.charAt(0) : hh.charAt(1);
- this.mm1 = (mm.length == 1) ? "0" : mm.charAt(0);
- this.mm2 = (mm.length == 1) ? mm.charAt(0) : mm.charAt(1);
- } // end if
- } // END _digitalclock_getDigits
-
-
- // Public Event Handlers ----------------------------------------
-
- // Default handlers for each event, which can be overridden in the calling page.
- function _digitalclock_onError() {
- }
- function _digitalclock_onAbort() {
- }
- function _digitalclock_onLoad() {
- }
- function _digitalclock_onRender() {
- }
- function _digitalclock_onStart() {
- }
- function _digitalclock_onStop() {
- }
- function _digitalclock_onRotateImage() {
- }
-
- } // END CONSTRUCTOR com_netobjects_DigitalClock
-
-
-