Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- (function() {
- /**
- * Updates the date and sets refresh callback on the next day.
- * @private
- * @param {number} prevDay - date of the previous day
- */
- function showdate(){
- var date = new Date();
- var day = date.getDay();
- var name = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][day];
- document.getElementById("date").textContent = name;
- }
- showdate();
- /**
- * Updates the current time.
- * @private
- */
- function showTime(){
- var date = new Date();
- var h = date.getHours(); // 0 - 23
- var m = date.getMinutes(); // 0 - 59
- var s = date.getSeconds(); // 0 - 59
- var session = "AM";
- if(h === 0){
- h = 24;
- }
- /*if(h > 12){
- h = h - 12;
- session = "PM";
- }*/
- h = (h < 10) ? "0" + h : h;
- m = (m < 10) ? "0" + m : m;
- s = (s < 10) ? "0" + s : s;
- var time = h + ":" + m + ":" + s;
- /*var sess = session;*/
- document.getElementById("MyClockDisplay").innerText = time;
- document.getElementById("MyClockDisplay").textContent = time;
- /* document.getElementById("PM").textContent = sess;*/
- setTimeout(showTime, 1000);
- }
- showTime();
- var d = new Date();
- var hour = d.getHours();
- var min = d.getMinutes();
- var sec = d.getSeconds();
- var time = hour + ":" + min + ":" + sec;
- function day1to2() {
- if (time >= '09:00:00'&&time < '17:00:00')
- {
- var e;
- // remove showMe class from current image
- e = document.getElementById("day1");
- removeClass(e, "showMe");
- // compute next image
- /*curImage++;
- if (curImage > numImages - 1) {
- curImage = 0;
- }*/
- // add showMe class to next image
- e = document.getElementById("day2");
- addClass(e, "showMe");
- }
- function addClass(elem, name) {
- var c = elem.className;
- if (c){ c += " "; // if not blank, add a space separator
- c += name;
- elem.className = c;
- }
- }
- function removeClass(elem, name) {
- var c = elem.className;
- elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
- }
- setTimeout(day1to2, 1000);
- }
- day1to2();
- function day2to3() {
- if (time >= '17:01:00'&&time < '20:00:00')
- {
- var e;
- // remove showMe class from current image
- e = document.getElementById("day2");
- removeClass(e, "showMe");
- // compute next image
- /*curImage++;
- if (curImage > numImages - 1) {
- curImage = 0;
- }*/
- // add showMe class to next image
- e = document.getElementById("day3");
- addClass(e, "showMe");
- }
- function addClass(elem, name) {
- var c = elem.className;
- if (c){ c += " "; // if not blank, add a space separator
- c += name;
- elem.className = c;
- }
- }
- function removeClass(elem, name) {
- var c = elem.className;
- elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
- }
- setTimeout(day2to3, 1000);
- }
- day2to3();
- function day3tonight1() {
- if (time >= '20:01"00'&&time < '00:00:00')
- {
- var e;
- // remove showMe class from current image
- e = document.getElementById("day3");
- removeClass(e, "showMe");
- // compute next image
- /*curImage++;
- if (curImage > numImages - 1) {
- curImage = 0;
- }*/
- // add showMe class to next image
- e = document.getElementById("night1");
- addClass(e, "showMe");
- }
- function addClass(elem, name) {
- var c = elem.className;
- if (c){ c += " "; // if not blank, add a space separator
- c += name;
- elem.className = c;
- }
- }
- function removeClass(elem, name) {
- var c = elem.className;
- elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
- }
- setTimeout(day3tonight1, 1000);
- }
- day3tonight1();
- function night1To2() {
- if (time >= '00:01:00'&&time < '03:00:00')
- {
- var e;
- // remove showMe class from current image
- e = document.getElementById("night1");
- removeClass(e, "showMe");
- // compute next image
- /*curImage++;
- if (curImage > numImages - 1) {
- curImage = 0;
- }*/
- // add showMe class to next image
- e = document.getElementById("night2");
- addClass(e, "showMe");
- }
- function addClass(elem, name) {
- var c = elem.className;
- if (c){ c += " "; // if not blank, add a space separator
- c += name;
- elem.className = c;
- }
- }
- function removeClass(elem, name) {
- var c = elem.className;
- elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
- }
- setTimeout(night1To2, 1000);
- }
- night1To2();
- function night2to3() {
- if (time >= '03:01:00'&&time < '06:00:00')
- {
- var e;
- // remove showMe class from current image
- e = document.getElementById("night2");
- removeClass(e, "showMe");
- // compute next image
- /*curImage++;
- if (curImage > numImages - 1) {
- curImage = 0;
- }*/
- // add showMe class to next image
- e = document.getElementById("night3");
- addClass(e, "showMe");
- }
- function addClass(elem, name) {
- var c = elem.className;
- if (c){ c += " "; // if not blank, add a space separator
- c += name;
- elem.className = c;
- }
- }
- function removeClass(elem, name) {
- var c = elem.className;
- elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
- }
- setTimeout(night2to3, 1000);
- }
- night2to3();
- function night3toDay() {
- if (time >= '06:01:00'&&time < '09:00:00')
- {
- var e;
- // remove showMe class from current image
- e = document.getElementById("night3");
- removeClass(e, "showMe");
- // compute next image
- /*curImage++;
- if (curImage > numImages - 1) {
- curImage = 0;
- }*/
- // add showMe class to next image
- e = document.getElementById("day1");
- addClass(e, "showMe");
- }
- function addClass(elem, name) {
- var c = elem.className;
- if (c){ c += " "; // if not blank, add a space separator
- c += name;
- elem.className = c;
- }
- }
- function removeClass(elem, name) {
- var c = elem.className;
- elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
- }
- setTimeout(night3toDay, 1000);
- }
- night3toDay();
- /**
- * Sets to background image as BACKGROUND_URL,
- * and starts timer for normal digital watch mode.
- * @private
- */
- function initDigitalWatch() {
- // document.getElementById("digital-body").style.backgroundImage = BACKGROUND_URL;
- }
- /**
- * Clears timer and sets background image as none for ambient digital watch mode.
- * @private
- */
- function ambientDigitalWatch() {
- document.getElementById("digital-body").style.backgroundImage = "none";
- showTime();
- }
- /**
- * Gets battery state.
- * Updates battery level.
- * @private
- */
- /**
- * Updates watch screen. (time and date)
- * @private
- */
- function updateWatch() {
- showTime();
- showdate(0);
- day1to2();
- day2to3();
- day3tonight();
- night1To2();
- night2to3();
- night3toDay();
- }
- /**
- * Binds events.
- * @private
- */
- function bindEvents() {
- // add eventListener for battery state
- // add eventListener for timetick
- window.addEventListener("timetick", function() {
- ambientDigitalWatch();
- });
- // add eventListener for ambientmodechanged
- window.addEventListener("ambientmodechanged", function(e) {
- if (e.detail.ambientMode === true) {
- // rendering ambient mode case
- ambientDigitalWatch();
- } else {
- // rendering normal digital mode case
- initDigitalWatch();
- }
- });
- // add eventListener to update the screen immediately when the device wakes up.
- document.addEventListener("visibilitychange", function() {
- if (!document.hidden) {
- updateWatch();
- }
- });
- // add event listeners to update watch screen when the time zone is changed.
- tizen.time.setTimezoneChangeListener(function() {
- updateWatch();
- });
- }
- /**
- * Initializes date and time.
- * Sets to digital mode.
- * @private
- */
- function init() {
- initDigitalWatch();
- showdate(0);
- bindEvents();
- }
- window.onload = init();
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement