1: //namespace declaration
2: var CountUp = function ()
3: { } //end of name space
4:
5: // Class Declaration
6: CountUp.Class = function () {
7: //private references
8: var currentTime=new Date()
9: var startingdate;
10: var timesup=false
11: var baseunit;
12: var result;
13: //private method:
14: var PrintResults = function(){
15: var strresults = " ";
16: //Display the result
17: strresults += '<div style="width:300px; background-color:#383838; text-align:center; color:white; margin-bottom:15px; margin-top:5px;">'
18: strresults += '<div style="width:300px; font-size:120%; text-align:center; background-color: #5E3A3A; color:white;"> Number of Days Without WOW </div>'; //opend
19: strresults += result.days + ' :Days ';
20: strresults += result.hours +' :Hours ' ;
21: strresults += result.minutes + ' :Minutes ';
22: strresults += result.seconds + ' :Seconds ';
23: strresults += "</div>" //close
24: document.getElementById("ClockDiv").innerHTML = strresults;
25: } //end function
26: return { //the returned object here
27: //public declarations (declare as below)
28: ExampleProperty: 1, // note need comma after
29:
30: //init function
31: init: function (time,baseunit) {
32: startingdate=new Date(time)
33: baseunit=baseunit
34: //Add call Function to the SetInterval
35: setInterval(CountUp.Class.showTime,3000);
36: //accessing private variable
37: //abc ="jfk"
38: },
39: //Public Functio
40: showTime: function() {
41: currentTime.setSeconds(currentTime.getSeconds()+1);
42: var timediff=(currentTime - startingdate) /1000; //difference btw target date and current date, in seconds
43: var oneMinute=60; //minute unit in seconds
44: var oneHour=60*60; //hour unit in seconds
45: var oneDay=60*60*24; //day unit in seconds
46: var dayfield=Math.floor(timediff/oneDay);
47: var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour);
48: var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute);
49: var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute));
50: if (baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
51: hourfield=dayfield*24+hourfield;
52: dayfield="n/a";
53: }
54: else if (baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
55: minutefield=dayfield*24*60+hourfield*60+minutefield;
56: dayfield=hourfield="n/a";
57: }
58: else if (baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
59: var secondfield=timediff;
60: dayfield=hourfield=minutefield="n/a";
61: }
62: result={days: dayfield, hours:hourfield, minutes:minutefield, seconds:secondfield};
63: // call print method
64: PrintResults();
65: } //, (remove comment syntax if more than one function)
66:
67: };
68: }(); // the parens here cause the anonymous function to execute and return
69:
70: //initilize the object
71: CountUp.Class.init("January 5,2008, 17:15:00","days");