Advertisement
Guest User

js

a guest
Mar 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.49 KB | None | 0 0
  1. /*
  2. * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16.  
  17. (function() {
  18. /**
  19. * Updates the date and sets refresh callback on the next day.
  20. * @private
  21. * @param {number} prevDay - date of the previous day
  22. */
  23. function showdate(){
  24.  
  25. var date = new Date();
  26. var day = date.getDay();
  27.  
  28. var name = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][day];
  29.  
  30. document.getElementById("date").textContent = name;
  31.  
  32.  
  33. }
  34.  
  35. showdate();
  36.  
  37.  
  38.  
  39. /**
  40. * Updates the current time.
  41. * @private
  42. */
  43. function showTime(){
  44. var date = new Date();
  45. var h = date.getHours(); // 0 - 23
  46. var m = date.getMinutes(); // 0 - 59
  47. var s = date.getSeconds(); // 0 - 59
  48. var session = "AM";
  49.  
  50. if(h === 0){
  51. h = 24;
  52. }
  53.  
  54. /*if(h > 12){
  55. h = h - 12;
  56. session = "PM";
  57. }*/
  58.  
  59. h = (h < 10) ? "0" + h : h;
  60. m = (m < 10) ? "0" + m : m;
  61. s = (s < 10) ? "0" + s : s;
  62.  
  63. var time = h + ":" + m + ":" + s;
  64. /*var sess = session;*/
  65. document.getElementById("MyClockDisplay").innerText = time;
  66. document.getElementById("MyClockDisplay").textContent = time;
  67. /* document.getElementById("PM").textContent = sess;*/
  68.  
  69. setTimeout(showTime, 1000);
  70. }
  71.  
  72. showTime();
  73.  
  74.  
  75.  
  76.  
  77. var d = new Date();
  78. var hour = d.getHours();
  79. var min = d.getMinutes();
  80. var sec = d.getSeconds();
  81. var time = hour + ":" + min + ":" + sec;
  82.  
  83. function day1to2() {
  84. if (time >= '09:00:00'&&time < '17:00:00')
  85. {
  86. var e;
  87. // remove showMe class from current image
  88. e = document.getElementById("day1");
  89. removeClass(e, "showMe");
  90.  
  91. // compute next image
  92. /*curImage++;
  93. if (curImage > numImages - 1) {
  94. curImage = 0;
  95. }*/
  96.  
  97.  
  98. // add showMe class to next image
  99. e = document.getElementById("day2");
  100. addClass(e, "showMe");
  101.  
  102. }
  103.  
  104. function addClass(elem, name) {
  105. var c = elem.className;
  106. if (c){ c += " "; // if not blank, add a space separator
  107. c += name;
  108. elem.className = c;
  109. }
  110. }
  111.  
  112. function removeClass(elem, name) {
  113. var c = elem.className;
  114. elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
  115. }
  116. setTimeout(day1to2, 1000);
  117. }
  118.  
  119. day1to2();
  120.  
  121.  
  122. function day2to3() {
  123. if (time >= '17:01:00'&&time < '20:00:00')
  124. {
  125. var e;
  126. // remove showMe class from current image
  127. e = document.getElementById("day2");
  128. removeClass(e, "showMe");
  129.  
  130. // compute next image
  131. /*curImage++;
  132. if (curImage > numImages - 1) {
  133. curImage = 0;
  134. }*/
  135.  
  136.  
  137. // add showMe class to next image
  138. e = document.getElementById("day3");
  139. addClass(e, "showMe");
  140.  
  141. }
  142.  
  143. function addClass(elem, name) {
  144. var c = elem.className;
  145. if (c){ c += " "; // if not blank, add a space separator
  146. c += name;
  147. elem.className = c;
  148. }
  149. }
  150.  
  151. function removeClass(elem, name) {
  152. var c = elem.className;
  153. elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
  154. }
  155. setTimeout(day2to3, 1000);
  156. }
  157.  
  158. day2to3();
  159.  
  160.  
  161.  
  162. function day3tonight1() {
  163. if (time >= '20:01"00'&&time < '00:00:00')
  164. {
  165. var e;
  166. // remove showMe class from current image
  167. e = document.getElementById("day3");
  168. removeClass(e, "showMe");
  169.  
  170. // compute next image
  171. /*curImage++;
  172. if (curImage > numImages - 1) {
  173. curImage = 0;
  174. }*/
  175.  
  176.  
  177. // add showMe class to next image
  178. e = document.getElementById("night1");
  179. addClass(e, "showMe");
  180.  
  181. }
  182.  
  183. function addClass(elem, name) {
  184. var c = elem.className;
  185. if (c){ c += " "; // if not blank, add a space separator
  186. c += name;
  187. elem.className = c;
  188. }
  189. }
  190.  
  191. function removeClass(elem, name) {
  192. var c = elem.className;
  193. elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
  194. }
  195. setTimeout(day3tonight1, 1000);
  196. }
  197.  
  198. day3tonight1();
  199.  
  200.  
  201.  
  202.  
  203. function night1To2() {
  204. if (time >= '00:01:00'&&time < '03:00:00')
  205. {
  206. var e;
  207. // remove showMe class from current image
  208. e = document.getElementById("night1");
  209. removeClass(e, "showMe");
  210.  
  211. // compute next image
  212. /*curImage++;
  213. if (curImage > numImages - 1) {
  214. curImage = 0;
  215. }*/
  216.  
  217.  
  218. // add showMe class to next image
  219. e = document.getElementById("night2");
  220. addClass(e, "showMe");
  221.  
  222. }
  223.  
  224. function addClass(elem, name) {
  225. var c = elem.className;
  226. if (c){ c += " "; // if not blank, add a space separator
  227. c += name;
  228. elem.className = c;
  229. }
  230. }
  231.  
  232. function removeClass(elem, name) {
  233. var c = elem.className;
  234. elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
  235. }
  236. setTimeout(night1To2, 1000);
  237. }
  238.  
  239. night1To2();
  240.  
  241.  
  242.  
  243. function night2to3() {
  244. if (time >= '03:01:00'&&time < '06:00:00')
  245. {
  246. var e;
  247. // remove showMe class from current image
  248. e = document.getElementById("night2");
  249. removeClass(e, "showMe");
  250.  
  251. // compute next image
  252. /*curImage++;
  253. if (curImage > numImages - 1) {
  254. curImage = 0;
  255. }*/
  256.  
  257.  
  258. // add showMe class to next image
  259. e = document.getElementById("night3");
  260. addClass(e, "showMe");
  261.  
  262. }
  263.  
  264. function addClass(elem, name) {
  265. var c = elem.className;
  266. if (c){ c += " "; // if not blank, add a space separator
  267. c += name;
  268. elem.className = c;
  269. }
  270. }
  271.  
  272. function removeClass(elem, name) {
  273. var c = elem.className;
  274. elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
  275. }
  276. setTimeout(night2to3, 1000);
  277. }
  278.  
  279. night2to3();
  280.  
  281.  
  282. function night3toDay() {
  283. if (time >= '06:01:00'&&time < '09:00:00')
  284. {
  285. var e;
  286. // remove showMe class from current image
  287. e = document.getElementById("night3");
  288. removeClass(e, "showMe");
  289.  
  290. // compute next image
  291. /*curImage++;
  292. if (curImage > numImages - 1) {
  293. curImage = 0;
  294. }*/
  295.  
  296.  
  297. // add showMe class to next image
  298. e = document.getElementById("day1");
  299. addClass(e, "showMe");
  300.  
  301. }
  302.  
  303. function addClass(elem, name) {
  304. var c = elem.className;
  305. if (c){ c += " "; // if not blank, add a space separator
  306. c += name;
  307. elem.className = c;
  308. }
  309. }
  310.  
  311. function removeClass(elem, name) {
  312. var c = elem.className;
  313. elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
  314. }
  315. setTimeout(night3toDay, 1000);
  316. }
  317.  
  318. night3toDay();
  319.  
  320.  
  321.  
  322. /**
  323. * Sets to background image as BACKGROUND_URL,
  324. * and starts timer for normal digital watch mode.
  325. * @private
  326. */
  327. function initDigitalWatch() {
  328.  
  329. // document.getElementById("digital-body").style.backgroundImage = BACKGROUND_URL;
  330.  
  331. }
  332.  
  333. /**
  334. * Clears timer and sets background image as none for ambient digital watch mode.
  335. * @private
  336. */
  337. function ambientDigitalWatch() {
  338.  
  339.  
  340. document.getElementById("digital-body").style.backgroundImage = "none";
  341. showTime();
  342. }
  343.  
  344. /**
  345. * Gets battery state.
  346. * Updates battery level.
  347. * @private
  348. */
  349.  
  350. /**
  351. * Updates watch screen. (time and date)
  352. * @private
  353. */
  354. function updateWatch() {
  355. showTime();
  356. showdate(0);
  357. day1to2();
  358. day2to3();
  359. day3tonight();
  360. night1To2();
  361. night2to3();
  362. night3toDay();
  363. }
  364.  
  365. /**
  366. * Binds events.
  367. * @private
  368. */
  369. function bindEvents() {
  370. // add eventListener for battery state
  371.  
  372.  
  373.  
  374.  
  375. // add eventListener for timetick
  376. window.addEventListener("timetick", function() {
  377. ambientDigitalWatch();
  378. });
  379.  
  380. // add eventListener for ambientmodechanged
  381. window.addEventListener("ambientmodechanged", function(e) {
  382. if (e.detail.ambientMode === true) {
  383. // rendering ambient mode case
  384. ambientDigitalWatch();
  385.  
  386. } else {
  387. // rendering normal digital mode case
  388. initDigitalWatch();
  389. }
  390. });
  391.  
  392. // add eventListener to update the screen immediately when the device wakes up.
  393. document.addEventListener("visibilitychange", function() {
  394. if (!document.hidden) {
  395. updateWatch();
  396. }
  397. });
  398.  
  399. // add event listeners to update watch screen when the time zone is changed.
  400. tizen.time.setTimezoneChangeListener(function() {
  401. updateWatch();
  402. });
  403. }
  404.  
  405. /**
  406. * Initializes date and time.
  407. * Sets to digital mode.
  408. * @private
  409. */
  410. function init() {
  411. initDigitalWatch();
  412. showdate(0);
  413.  
  414. bindEvents();
  415. }
  416.  
  417. window.onload = init();
  418. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement