From 689e3485328babbdd371e8f2a8161e95ef243257 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Wed, 16 Jul 2014 15:58:50 +0200 Subject: [PATCH 01/12] added IDEA files to ignore list --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b25c15b..34662c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ *~ +.idea/ +*.iml +atlassian-ide-plugin.xml From 69a843fc298e487a29d1516d17e1862ef0b96f35 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Wed, 16 Jul 2014 16:21:23 +0200 Subject: [PATCH 02/12] added example of seconds layout --- uhr-seconds-de_CH_genau.js | 175 +++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 uhr-seconds-de_CH_genau.js diff --git a/uhr-seconds-de_CH_genau.js b/uhr-seconds-de_CH_genau.js new file mode 100644 index 0000000..b84e918 --- /dev/null +++ b/uhr-seconds-de_CH_genau.js @@ -0,0 +1,175 @@ +/* + * Copyright (C) Schweizerische Bundesbahnen SBB, 2014. + */ + +/* +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +/* +Hier Zahlenbeispiele + + ----------- + ----------- + --#-----#-- + -##----##-- + --#-----#-- + --#-----#-- + --#-----#-- + --#-----#-- + -###---###- + ----------- + + --#-- + -##-- + --#-- + --#-- + --#-- + --#-- + -###- + + -###- + #---# + ----# + ---#- + --#-- + -#--- + ##### + + ##### + ---#- + --#-- + ---#- + ----# + #---# + -###- + + ---#- + --##- + -#-#- + #--#- + ##### + ---#- + ---#- + + ##### + #---- + ####- + ----# + ----# + #---# + -###- + + --##- + -#--- + #---- + ####- + #---# + #---# + -###- + + ##### + ----# + ---#- + --#-- + -#--- + -#--- + -#--- + + -###- + #---# + #---# + -###- + #---# + #---# + -###- + + -###- + #---# + #---# + -#### + ----# + ---#- + -##-- + + -###- + #---# + #--## + #-#-# + ##--# + #---# + -###- + + + */ +var h = { + "_": {}, + "_es_isch": {1:[1,2,4,5,6,7]}, + "_genau": {3:[7,8,9,10,11]}, + "_ab": {4:[4,5]}, + "_vor": {4:[1,2,3]}, + "_haubi": {4:[7,8,9,10,11]}, + "_5": {1:[9,10,11]}, + "_10": {2:[9,10,11]}, + "_15": {2:[1,2,3,4,5,6]}, + "_20": {3:[1,2,3,4,5,6]} +}; +var layout = { + "version": 3, + "language": 'Bärndütschi Sekunde (genau)', + "letters": [ + 'ESKISCHAFÜF', + 'VIERTUBFZÄÄ', + 'ZWÄNZGGENAU', + 'VORABOHAUBI', + 'EISZWÖISDRÜ', + 'VIERIFÜFIQT', + 'SÄCHSISIBNI', + 'ACHTINÜNIEL', + 'ZÄNIERBEUFI', + 'ZWÖUFINAUHR' + ], + "seconds": { + "0": [] + }, + "permanent": h._es_isch, + "minutes": { + "0": h._genau, + "5,6,7,8,9": [h._5, h._ab], + "10,11,12,13,14": [h._10, h._ab], + "15,16,17,18,19": [h._15, h._ab], + "20,21,22,23,24": [h._20, h._ab], + "25,26,27,28,29": [h._5, h._vor, h._haubi], + "30,31,32,33,34": h._haubi, + "35,36,37,38,39": [h._5, h._ab, h._haubi], + "40,41,42,43,44": [h._20, h._vor], + "45,46,47,48,49": [h._15, h._vor], + "50,51,52,53,54": [h._10, h._vor], + "55,56,57,58,59": [h._5, h._vor] + }, + "hours": { + "0,12": {10:[1,2,3,4,5,6]}, + "1,13": {5:[1,2,3]}, + "2,14": {5:[4,5,6,7]}, + "3,15": {5:[9,10,11]}, + "4,16": {6:[1,2,3,4,5]}, + "5,17": {6:[6,7,8,9]}, + "6,18": {7:[1,2,3,4,5,6]}, + "7,19": {7:[7,8,9,10,11]}, + "8,20": {8:[1,2,3,4,5]}, + "9,21": {8:[6,7,8,9]}, + "10,22": {9:[1,2,3,4]}, + "11,23": {9:[8,9,10,11]} + } +}; +window,_uhr.register('de_CH_seconds', layout); From 8badcc549f0d8c1b2634112a148610fb6f13fd88 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Wed, 16 Jul 2014 16:39:37 +0200 Subject: [PATCH 03/12] added first second-thing --- uhr-seconds-de_CH_genau.js | 283 +++++++++++++++++++------------------ 1 file changed, 146 insertions(+), 137 deletions(-) diff --git a/uhr-seconds-de_CH_genau.js b/uhr-seconds-de_CH_genau.js index b84e918..3cedf1d 100644 --- a/uhr-seconds-de_CH_genau.js +++ b/uhr-seconds-de_CH_genau.js @@ -16,113 +16,151 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ -/* -Hier Zahlenbeispiele - - ----------- - ----------- - --#-----#-- - -##----##-- - --#-----#-- - --#-----#-- - --#-----#-- - --#-----#-- - -###---###- - ----------- - - --#-- - -##-- - --#-- - --#-- - --#-- - --#-- - -###- - - -###- - #---# - ----# - ---#- - --#-- - -#--- - ##### - - ##### - ---#- - --#-- - ---#- - ----# - #---# - -###- - - ---#- - --##- - -#-#- - #--#- - ##### - ---#- - ---#- - - ##### - #---- - ####- - ----# - ----# - #---# - -###- - - --##- - -#--- - #---- - ####- - #---# - #---# - -###- - - ##### - ----# - ---#- - --#-- - -#--- - -#--- - -#--- - - -###- - #---# - #---# - -###- - #---# - #---# - -###- - - -###- - #---# - #---# - -#### - ----# - ---#- - -##-- - - -###- - #---# - #--## - #-#-# - ##--# - #---# - -###- - - - */ var h = { - "_": {}, - "_es_isch": {1:[1,2,4,5,6,7]}, - "_genau": {3:[7,8,9,10,11]}, - "_ab": {4:[4,5]}, - "_vor": {4:[1,2,3]}, - "_haubi": {4:[7,8,9,10,11]}, - "_5": {1:[9,10,11]}, - "_10": {2:[9,10,11]}, - "_15": {2:[1,2,3,4,5,6]}, - "_20": {3:[1,2,3,4,5,6]} + "vorne0": { + 3:[2,3,4], + 4:[1,5], + 5:[1,4,5], + 6:[1,3,5], + 7:[1,2,5], + 8:[1,5], + 9:[2,3,4] + }, + "hinten0": { + 3:[8,9,10], + 4:[7,11], + 5:[7,10,11], + 6:[7,9,11], + 7:[7,8,11], + 8:[7,11], + 9:[8,9,10] + }, + "vorne1": { + 3:[3], + 4:[2,3], + 5:[3], + 6:[3], + 7:[3], + 8:[3], + 9:[2,3,4] + }, + "hinten1": { + 3:[9], + 4:[8,9], + 5:[9], + 6:[9], + 7:[9], + 8:[9], + 9:[8,9,10] + }, + "vorne2": { + 3:[2,3,4], + 4:[1,5], + 5:[5], + 6:[4], + 7:[3], + 8:[2], + 9:[1,2,3,4,5] + }, + "hinten2": { + 3:[8,9,10], + 4:[7,11], + 5:[11], + 6:[10], + 7:[9], + 8:[8], + 9:[7,8,9,10,11] + }, + "vorne3": { + 3:[1,2,3,4,5], + 4:[4], + 5:[3], + 6:[4], + 7:[5], + 8:[1,5], + 9:[2,3,4] + }, + "hinten3": { + 3:[7,8,9,10,11], + 4:[10], + 5:[9], + 6:[10], + 7:[11], + 8:[7,11], + 9:[8,9,10] + }, + "vorne4": { + 3:[4], + 4:[3,4], + 5:[2,4], + 6:[1,4], + 7:[1,2,3,4,5], + 8:[4], + 9:[4] + }, + "hinten4": { + 3:[10], + 4:[9,10], + 5:[8,10], + 6:[7,10], + 7:[7,8,9,10,11], + 8:[10], + 9:[10] + }, + "vorne5": { + 3:[1,2,3,4,5], + 4:[1], + 5:[1,2,3,4], + 6:[5], + 7:[5], + 8:[1,5], + 9:[2,3,4] + }, + "hinten5": { + 3:[7,8,9,10,11], + 4:[7], + 5:[7,8,9,10], + 6:[11], + 7:[11], + 8:[7,11], + 9:[8,9,10] + }, + "hinten6": { + 3:[9,10], + 4:[8], + 5:[7], + 6:[7,8,9,10], + 7:[7,11], + 8:[7,11], + 9:[8,9,10] + }, + "hinten7": { + 3:[7,8,9,10,11], + 4:[11], + 5:[10], + 6:[9], + 7:[8], + 8:[8], + 9:[8] + }, + "hinten8": { + 3:[8,9,10], + 4:[7,11], + 5:[7,11], + 6:[8,9,10], + 7:[7,11], + 8:[7,11], + 9:[8,9,10] + }, + "hinten9": { + 3:[8,9,10], + 4:[7,11], + 5:[7,11], + 6:[8,9,10,11], + 7:[11], + 8:[10], + 9:[8,9] + } }; var layout = { "version": 3, @@ -140,36 +178,7 @@ var layout = { 'ZWÖUFINAUHR' ], "seconds": { - "0": [] - }, - "permanent": h._es_isch, - "minutes": { - "0": h._genau, - "5,6,7,8,9": [h._5, h._ab], - "10,11,12,13,14": [h._10, h._ab], - "15,16,17,18,19": [h._15, h._ab], - "20,21,22,23,24": [h._20, h._ab], - "25,26,27,28,29": [h._5, h._vor, h._haubi], - "30,31,32,33,34": h._haubi, - "35,36,37,38,39": [h._5, h._ab, h._haubi], - "40,41,42,43,44": [h._20, h._vor], - "45,46,47,48,49": [h._15, h._vor], - "50,51,52,53,54": [h._10, h._vor], - "55,56,57,58,59": [h._5, h._vor] - }, - "hours": { - "0,12": {10:[1,2,3,4,5,6]}, - "1,13": {5:[1,2,3]}, - "2,14": {5:[4,5,6,7]}, - "3,15": {5:[9,10,11]}, - "4,16": {6:[1,2,3,4,5]}, - "5,17": {6:[6,7,8,9]}, - "6,18": {7:[1,2,3,4,5,6]}, - "7,19": {7:[7,8,9,10,11]}, - "8,20": {8:[1,2,3,4,5]}, - "9,21": {8:[6,7,8,9]}, - "10,22": {9:[1,2,3,4]}, - "11,23": {9:[8,9,10,11]} - } + "0": [h.vorne0, h.hinten0] + } }; window,_uhr.register('de_CH_seconds', layout); From a0e2588d912db38c290cecbfb6a084841f0cce48 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Wed, 16 Jul 2014 16:45:00 +0200 Subject: [PATCH 04/12] added definitions for seconds --- uhr-seconds-de_CH_genau.js | 61 +++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/uhr-seconds-de_CH_genau.js b/uhr-seconds-de_CH_genau.js index 3cedf1d..c15f525 100644 --- a/uhr-seconds-de_CH_genau.js +++ b/uhr-seconds-de_CH_genau.js @@ -178,7 +178,66 @@ var layout = { 'ZWÖUFINAUHR' ], "seconds": { - "0": [h.vorne0, h.hinten0] + "0": [h.vorne0, h.hinten0], + "1": [h.vorne0, h.hinten1], + "2": [h.vorne0, h.hinten2], + "3": [h.vorne0, h.hinten3], + "4": [h.vorne0, h.hinten4], + "5": [h.vorne0, h.hinten5], + "6": [h.vorne0, h.hinten6], + "7": [h.vorne0, h.hinten7], + "8": [h.vorne0, h.hinten8], + "9": [h.vorne0, h.hinten9], + "10": [h.vorne1, h.hinten0], + "11": [h.vorne1, h.hinten1], + "12": [h.vorne1, h.hinten2], + "13": [h.vorne1, h.hinten3], + "14": [h.vorne1, h.hinten4], + "15": [h.vorne1, h.hinten5], + "16": [h.vorne1, h.hinten6], + "17": [h.vorne1, h.hinten7], + "18": [h.vorne1, h.hinten8], + "19": [h.vorne1, h.hinten9], + "20": [h.vorne2, h.hinten0], + "21": [h.vorne2, h.hinten1], + "22": [h.vorne2, h.hinten2], + "23": [h.vorne2, h.hinten3], + "24": [h.vorne2, h.hinten4], + "25": [h.vorne2, h.hinten5], + "26": [h.vorne2, h.hinten6], + "27": [h.vorne2, h.hinten7], + "28": [h.vorne2, h.hinten8], + "29": [h.vorne2, h.hinten9], + "30": [h.vorne3, h.hinten0], + "31": [h.vorne3, h.hinten1], + "32": [h.vorne3, h.hinten2], + "33": [h.vorne3, h.hinten3], + "34": [h.vorne3, h.hinten4], + "35": [h.vorne3, h.hinten5], + "36": [h.vorne3, h.hinten6], + "37": [h.vorne3, h.hinten7], + "38": [h.vorne3, h.hinten8], + "39": [h.vorne3, h.hinten9], + "40": [h.vorne4, h.hinten0], + "41": [h.vorne4, h.hinten1], + "42": [h.vorne4, h.hinten2], + "43": [h.vorne4, h.hinten3], + "44": [h.vorne4, h.hinten4], + "45": [h.vorne4, h.hinten5], + "46": [h.vorne4, h.hinten6], + "47": [h.vorne4, h.hinten7], + "48": [h.vorne4, h.hinten8], + "49": [h.vorne4, h.hinten9], + "50": [h.vorne5, h.hinten0], + "51": [h.vorne5, h.hinten1], + "52": [h.vorne5, h.hinten2], + "53": [h.vorne5, h.hinten3], + "54": [h.vorne5, h.hinten4], + "55": [h.vorne5, h.hinten5], + "56": [h.vorne5, h.hinten6], + "57": [h.vorne5, h.hinten7], + "58": [h.vorne5, h.hinten8], + "59": [h.vorne5, h.hinten9] } }; window,_uhr.register('de_CH_seconds', layout); From c0af4a976f8e1ea9e40117e73a6455923d0d9db5 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Wed, 16 Jul 2014 17:08:10 +0200 Subject: [PATCH 05/12] rename seconds-file; add more failsafety (undefined-checks); override _getDotMinute for the second, so the dots don't show up. --- manifest.appcache | 3 +- showcase/index.html | 3 +- ...nds-de_CH_genau.js => uhr-de_CH-seconds.js | 27 +++--- uhr.js | 95 +++++++++++-------- 4 files changed, 75 insertions(+), 53 deletions(-) rename uhr-seconds-de_CH_genau.js => uhr-de_CH-seconds.js (93%) diff --git a/manifest.appcache b/manifest.appcache index 201ee99..ed2d9d3 100644 --- a/manifest.appcache +++ b/manifest.appcache @@ -1,5 +1,5 @@ CACHE MANIFEST -# 6.2.1 +# 6.3-alpha COPYING README.md @@ -13,6 +13,7 @@ uhr-black.css uhr-blue.css uhr-de.js uhr-de_CH.js +uhr-de_CH-seconds.js uhr-de_CH_genau.js uhr-en.js uhr-fr.js diff --git a/showcase/index.html b/showcase/index.html index c18666e..14e6bce 100644 --- a/showcase/index.html +++ b/showcase/index.html @@ -40,7 +40,8 @@ along with this program. If not, see .

Go back to the main page

- + + diff --git a/uhr-seconds-de_CH_genau.js b/uhr-de_CH-seconds.js similarity index 93% rename from uhr-seconds-de_CH_genau.js rename to uhr-de_CH-seconds.js index c15f525..09d1ff8 100644 --- a/uhr-seconds-de_CH_genau.js +++ b/uhr-de_CH-seconds.js @@ -163,19 +163,19 @@ var h = { } }; var layout = { - "version": 3, - "language": 'Bärndütschi Sekunde (genau)', + "version": 2, + "language": 'Bärndütschi Sekunde', "letters": [ - 'ESKISCHAFÜF', - 'VIERTUBFZÄÄ', - 'ZWÄNZGGENAU', - 'VORABOHAUBI', - 'EISZWÖISDRÜ', - 'VIERIFÜFIQT', - 'SÄCHSISIBNI', - 'ACHTINÜNIEL', - 'ZÄNIERBEUFI', - 'ZWÖUFINAUHR' + 'ESKISCHAFÜF', + 'VIERTUBFZÄÄ', + 'ZWÄNZGSIVOR', + 'ABOHAUBIEGE', + 'EISZWÖISDRÜ', + 'VIERIFÜFIQT', + 'SÄCHSISIBNI', + 'ACHTINÜNIEL', + 'ZÄNIERBEUFI', + 'ZWÖUFINAUHR' ], "seconds": { "0": [h.vorne0, h.hinten0], @@ -238,6 +238,9 @@ var layout = { "57": [h.vorne5, h.hinten7], "58": [h.vorne5, h.hinten8], "59": [h.vorne5, h.hinten9] + }, + "getDotMinute": function(time) { + return 0; } }; window,_uhr.register('de_CH_seconds', layout); diff --git a/uhr.js b/uhr.js index 21196a2..9df362a 100644 --- a/uhr.js +++ b/uhr.js @@ -131,10 +131,12 @@ along with this program. If not, see . _update: function() { if (this._isOn()) { var time = this.options.time; - if (time.getMinutes() == this._currentMinute) { - return; - } - this._currentMinute = time.getMinutes(); + if (!this._language().hasOwnProperty('seconds')) { + if (time.getMinutes() == this._currentMinute) { + return; + } + this._currentMinute = time.getMinutes(); + } this._show(time); } else { this._clear(); @@ -142,7 +144,8 @@ along with this program. If not, see . } }, _show: function(time) { - var dotMinute = this._getDotMinute(time); + var second = this._getSecond(time); + var dotMinute = this._getDotMinute(time); var hour = this._getHour(time); var coarseMinute = this._getCoarseMinute(time); this._clear(); @@ -150,7 +153,8 @@ along with this program. If not, see . for (var i = 1; i <= dotMinute; i++) { this._highlight('dot' + i); } - this._highlight('minute' + coarseMinute); + this._highlight('second' + second); + this._highlight('minute' + coarseMinute); this._highlight('hour' + hour); }, _language: function() { @@ -185,13 +189,19 @@ along with this program. If not, see . } return date.getMinutes(); }, - _getDotMinute: function(date) { - if (typeof this._language().getDotMinute === 'function') { - return this._language().getDotMinute(date); - } - var minutes = date.getMinutes(); - return minutes % 5; - }, + _getDotMinute: function(date) { + if (typeof this._language().getDotMinute === 'function') { + return this._language().getDotMinute(date); + } + var minutes = date.getMinutes(); + return minutes % 5; + }, + _getSecond: function(date) { + if (typeof this._language().getSecond === 'function') { + return this._language().getSecond(date); + } + return date.getSeconds(); + }, _create: function() { this._id = window._uhr.id++; var userTime = this.options.time; @@ -381,35 +391,41 @@ along with this program. If not, see . function _UhrRendererV2Delegate(layout) { this.layout = layout; this._parseArrayOrObject = function(letters, styleClass, input) { - if (Array.isArray(input)) { - for (var i = 0; i < input.length; i++) { - this._parseObject(letters, styleClass, input[i]); - } - } else { - this._parseObject(letters, styleClass, input); - } + if (typeof input !== 'undefined' && input !== null) { + if (Array.isArray(input)) { + for (var i = 0; i < input.length; i++) { + this._parseObject(letters, styleClass, input[i]); + } + } else { + this._parseObject(letters, styleClass, input); + } + } } this._parseObject = function(letters, styleClass, object) { - for (var line in object) { - if (object.hasOwnProperty(line)) { - var highlightLetters = object[line]; - for (var i = 0; i < highlightLetters.length; i++) { - var x = highlightLetters[i] - 1; - letters[line - 1][x].addStyle(styleClass); - } - } - } + if (typeof object !== 'undefined' && object !== null) { + for (var line in object) { + if (object.hasOwnProperty(line)) { + var highlightLetters = object[line]; + for (var i = 0; i < highlightLetters.length; i++) { + var x = highlightLetters[i] - 1; + letters[line - 1][x].addStyle(styleClass); + } + } + } + } } this._parseTimeDefinition = function(letters, styleClass, definition) { - for (var listString in definition) { - if (definition.hasOwnProperty(listString)) { - var array = listString.split(','); - var highlightLetters = definition[listString]; - for (var index = 0; index < array.length; index++) { - this._parseArrayOrObject(letters, styleClass + array[index], highlightLetters); - } - } - } + if (typeof definition !== 'undefined' && definition != null) { + for (var listString in definition) { + if (definition.hasOwnProperty(listString)) { + var array = listString.split(','); + var highlightLetters = definition[listString]; + for (var index = 0; index < array.length; index++) { + this._parseArrayOrObject(letters, styleClass + array[index], highlightLetters); + } + } + } + } } } _UhrRendererV2Delegate.prototype.parse = function() { @@ -424,7 +440,8 @@ along with this program. If not, see . letters.push(line); } this._parseArrayOrObject(letters, 'on', this.layout.permanent); - this._parseTimeDefinition(letters, 'minute', this.layout.minutes); + this._parseTimeDefinition(letters, 'second', this.layout.seconds); + this._parseTimeDefinition(letters, 'minute', this.layout.minutes); this._parseTimeDefinition(letters, 'hour', this.layout.hours); return letters; }; From 504e139bf2ebfb497a93ff613af8b53111f1fc70 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Mon, 11 Aug 2014 23:52:46 +0200 Subject: [PATCH 06/12] adapted the changes on the seconds branch to the refactored code --- index.html | 1 + js/uhr-de_CH-seconds.js | 247 ++++++++++++++++++++++++++++++++++++++++ js/uhr.js | 58 ++++++---- manifest.appcache | 3 +- showcase/index.html | 8 +- uhr-de_CH-seconds.js | 246 --------------------------------------- 6 files changed, 290 insertions(+), 273 deletions(-) create mode 100644 js/uhr-de_CH-seconds.js delete mode 100644 uhr-de_CH-seconds.js diff --git a/index.html b/index.html index 08049c1..320b743 100644 --- a/index.html +++ b/index.html @@ -37,6 +37,7 @@ along with this program. If not, see . + diff --git a/js/uhr-de_CH-seconds.js b/js/uhr-de_CH-seconds.js new file mode 100644 index 0000000..8732d2f --- /dev/null +++ b/js/uhr-de_CH-seconds.js @@ -0,0 +1,247 @@ +/* + * Copyright (C) Schweizerische Bundesbahnen SBB, 2014. + */ + +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +(function () { + 'use strict'; + var vorne0 = { + 3: [2, 3, 4], + 4: [1, 5], + 5: [1, 4, 5], + 6: [1, 3, 5], + 7: [1, 2, 5], + 8: [1, 5], + 9: [2, 3, 4] + }; + var hinten0 = { + 3: [8, 9, 10], + 4: [7, 11], + 5: [7, 10, 11], + 6: [7, 9, 11], + 7: [7, 8, 11], + 8: [7, 11], + 9: [8, 9, 10] + }; + var vorne1 = { + 3: [3], + 4: [2, 3], + 5: [3], + 6: [3], + 7: [3], + 8: [3], + 9: [2, 3, 4] + }; + var hinten1 = { + 3: [9], + 4: [8, 9], + 5: [9], + 6: [9], + 7: [9], + 8: [9], + 9: [8, 9, 10] + }; + var vorne2 = { + 3: [2, 3, 4], + 4: [1, 5], + 5: [5], + 6: [4], + 7: [3], + 8: [2], + 9: [1, 2, 3, 4, 5] + }; + var hinten2 = { + 3: [8, 9, 10], + 4: [7, 11], + 5: [11], + 6: [10], + 7: [9], + 8: [8], + 9: [7, 8, 9, 10, 11] + }; + var vorne3 = { + 3: [1, 2, 3, 4, 5], + 4: [4], + 5: [3], + 6: [4], + 7: [5], + 8: [1, 5], + 9: [2, 3, 4] + }; + var hinten3 = { + 3: [7, 8, 9, 10, 11], + 4: [10], + 5: [9], + 6: [10], + 7: [11], + 8: [7, 11], + 9: [8, 9, 10] + }; + var vorne4 = { + 3: [4], + 4: [3, 4], + 5: [2, 4], + 6: [1, 4], + 7: [1, 2, 3, 4, 5], + 8: [4], + 9: [4] + }; + var hinten4 = { + 3: [10], + 4: [9, 10], + 5: [8, 10], + 6: [7, 10], + 7: [7, 8, 9, 10, 11], + 8: [10], + 9: [10] + }; + var vorne5 = { + 3: [1, 2, 3, 4, 5], + 4: [1], + 5: [1, 2, 3, 4], + 6: [5], + 7: [5], + 8: [1, 5], + 9: [2, 3, 4] + }; + var hinten5 = { + 3: [7, 8, 9, 10, 11], + 4: [7], + 5: [7, 8, 9, 10], + 6: [11], + 7: [11], + 8: [7, 11], + 9: [8, 9, 10] + }; + var hinten6 = { + 3: [9, 10], + 4: [8], + 5: [7], + 6: [7, 8, 9, 10], + 7: [7, 11], + 8: [7, 11], + 9: [8, 9, 10] + }; + var hinten7 = { + 3: [7, 8, 9, 10, 11], + 4: [11], + 5: [10], + 6: [9], + 7: [8], + 8: [8], + 9: [8] + }; + var hinten8 = { + 3: [8, 9, 10], + 4: [7, 11], + 5: [7, 11], + 6: [8, 9, 10], + 7: [7, 11], + 8: [7, 11], + 9: [8, 9, 10] + }; + var hinten9 = { + 3: [8, 9, 10], + 4: [7, 11], + 5: [7, 11], + 6: [8, 9, 10, 11], + 7: [11], + 8: [10], + 9: [8, 9] + }; + var layout = { + "version": 2, + "language": 'Bärndütschi Sekunde', + "letters": [ + 'ESKISCHAFÜF', + 'VIERTUBFZÄÄ', + 'ZWÄNZGSIVOR', + 'ABOHAUBIEGE', + 'EISZWÖISDRÜ', + 'VIERIFÜFIQT', + 'SÄCHSISIBNI', + 'ACHTINÜNIEL', + 'ZÄNIERBEUFI', + 'ZWÖUFINAUHR' + ], + "seconds": { + "0": [vorne0, hinten0], + "1": [vorne0, hinten1], + "2": [vorne0, hinten2], + "3": [vorne0, hinten3], + "4": [vorne0, hinten4], + "5": [vorne0, hinten5], + "6": [vorne0, hinten6], + "7": [vorne0, hinten7], + "8": [vorne0, hinten8], + "9": [vorne0, hinten9], + "10": [vorne1, hinten0], + "11": [vorne1, hinten1], + "12": [vorne1, hinten2], + "13": [vorne1, hinten3], + "14": [vorne1, hinten4], + "15": [vorne1, hinten5], + "16": [vorne1, hinten6], + "17": [vorne1, hinten7], + "18": [vorne1, hinten8], + "19": [vorne1, hinten9], + "20": [vorne2, hinten0], + "21": [vorne2, hinten1], + "22": [vorne2, hinten2], + "23": [vorne2, hinten3], + "24": [vorne2, hinten4], + "25": [vorne2, hinten5], + "26": [vorne2, hinten6], + "27": [vorne2, hinten7], + "28": [vorne2, hinten8], + "29": [vorne2, hinten9], + "30": [vorne3, hinten0], + "31": [vorne3, hinten1], + "32": [vorne3, hinten2], + "33": [vorne3, hinten3], + "34": [vorne3, hinten4], + "35": [vorne3, hinten5], + "36": [vorne3, hinten6], + "37": [vorne3, hinten7], + "38": [vorne3, hinten8], + "39": [vorne3, hinten9], + "40": [vorne4, hinten0], + "41": [vorne4, hinten1], + "42": [vorne4, hinten2], + "43": [vorne4, hinten3], + "44": [vorne4, hinten4], + "45": [vorne4, hinten5], + "46": [vorne4, hinten6], + "47": [vorne4, hinten7], + "48": [vorne4, hinten8], + "49": [vorne4, hinten9], + "50": [vorne5, hinten0], + "51": [vorne5, hinten1], + "52": [vorne5, hinten2], + "53": [vorne5, hinten3], + "54": [vorne5, hinten4], + "55": [vorne5, hinten5], + "56": [vorne5, hinten6], + "57": [vorne5, hinten7], + "58": [vorne5, hinten8], + "59": [vorne5, hinten9] + }, + "getDotMinute": function (time) { + return 0; + } + }; + $.fritteli.uhr.register('de_CH_seconds', layout); +}()); diff --git a/js/uhr.js b/js/uhr.js index 4e59b06..11bcc62 100644 --- a/js/uhr.js +++ b/js/uhr.js @@ -116,7 +116,6 @@ e.height(realWidth); e.css('font-size', (realWidth / 40) + 'px'); }; - // private interface methods var create = function create() { this.id = uhrGlobals.id++; @@ -277,10 +276,12 @@ var update = function update() { if (isOn.bind(this)()) { var time = this.options.time; - if (time.getMinutes() === this.currentMinute) { - return; + if (!language.bind(this)().hasOwnProperty('seconds')) { + if (time.getMinutes() === this.currentMinute) { + return; + } + this.currentMinute = time.getMinutes(); } - this.currentMinute = time.getMinutes(); show.bind(this)(time); } else { clear.bind(this)(); @@ -288,6 +289,7 @@ } }; var show = function show(time) { + var second = getSecond.bind(this)(time); var dotMinute = getDotMinute.bind(this)(time); var hour = getHour.bind(this)(time); var coarseMinute = getCoarseMinute.bind(this)(time); @@ -296,6 +298,7 @@ for (var i = 1; i <= dotMinute; i++) { highlight.bind(this)('dot' + i); } + highlight.bind(this)('second' + second); highlight.bind(this)('minute' + coarseMinute); highlight.bind(this)('hour' + hour); }; @@ -305,6 +308,12 @@ var clear = function clear() { this.element.find('.item').removeClass('active'); }; + var getSecond = function getSecond(date) { + if (typeof language.bind(this)().getSeconds === 'function') { + return language.bind(this)().getSeconds(date); + } + return date.getSeconds(); + }; var getDotMinute = function getDotMinute(date) { if (typeof language.bind(this)().getDotMinute === 'function') { return language.bind(this)().getDotMinute(date); @@ -401,32 +410,38 @@ function UhrRendererV2Delegate(layout) { function parseArrayOrObject(letters, styleClass, input) { - if (Array.isArray(input)) { - input.forEach(function (item) { - parseObject(letters, styleClass, item); - }); - } else { - parseObject(letters, styleClass, input); + if (typeof input !== 'undefined' && input !== null) { + if (Array.isArray(input)) { + input.forEach(function (item) { + parseObject(letters, styleClass, item); + }); + } else { + parseObject(letters, styleClass, input); + } } } function parseObject(letters, styleClass, object) { - Object.keys(object).forEach(function (y) { - var highlightLetters = object[y]; - highlightLetters.forEach(function (x) { - letters[y - 1][x - 1].addStyle(styleClass); + if (typeof object !== 'undefined' && object !== null) { + Object.keys(object).forEach(function (y) { + var highlightLetters = object[y]; + highlightLetters.forEach(function (x) { + letters[y - 1][x - 1].addStyle(styleClass); + }); }); - }); + } } function parseTimeDefinition(letters, styleClass, definition) { - Object.keys(definition).forEach(function (listString) { - var array = listString.split(','); - var highlightLetters = definition[listString]; - array.forEach(function (item) { - parseArrayOrObject(letters, styleClass + item, highlightLetters); + if (typeof definition !== 'undefined' && definition !== null) { + Object.keys(definition).forEach(function (listString) { + var array = listString.split(','); + var highlightLetters = definition[listString]; + array.forEach(function (item) { + parseArrayOrObject(letters, styleClass + item, highlightLetters); + }); }); - }); + } } this.parse = function parse() { @@ -440,6 +455,7 @@ letters.push(line); }); parseArrayOrObject(letters, 'on', layout.permanent); + parseTimeDefinition(letters, 'second', layout.seconds); parseTimeDefinition(letters, 'minute', layout.minutes); parseTimeDefinition(letters, 'hour', layout.hours); return letters; diff --git a/manifest.appcache b/manifest.appcache index 8775b62..96cd2b5 100644 --- a/manifest.appcache +++ b/manifest.appcache @@ -14,8 +14,8 @@ info/info.css js/uhr.js js/uhr-de.js js/uhr-de_CH.js -uhr-de_CH-seconds.js js/uhr-de_CH_genau.js +js/uhr-de_CH-seconds.js js/uhr-en.js js/uhr-fr.js js/uhr-it.js @@ -31,4 +31,3 @@ showcase/index.html COPYING README.md index.html -uhr-de_CH.js diff --git a/showcase/index.html b/showcase/index.html index 35d181d..b995e98 100644 --- a/showcase/index.html +++ b/showcase/index.html @@ -29,8 +29,8 @@ along with this program. If not, see . - - + + @@ -41,7 +41,7 @@ along with this program. If not, see .

Go back to the main page

- + @@ -50,7 +50,7 @@ along with this program. If not, see . (function($) { var width = $(window).width(); var height = $(window).height() - 150; - var size = width < height ? width : height; + var size = Math.min(width, height); if (size < 200) { size = 200; } diff --git a/uhr-de_CH-seconds.js b/uhr-de_CH-seconds.js deleted file mode 100644 index 09d1ff8..0000000 --- a/uhr-de_CH-seconds.js +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (C) Schweizerische Bundesbahnen SBB, 2014. - */ - -/* -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ -var h = { - "vorne0": { - 3:[2,3,4], - 4:[1,5], - 5:[1,4,5], - 6:[1,3,5], - 7:[1,2,5], - 8:[1,5], - 9:[2,3,4] - }, - "hinten0": { - 3:[8,9,10], - 4:[7,11], - 5:[7,10,11], - 6:[7,9,11], - 7:[7,8,11], - 8:[7,11], - 9:[8,9,10] - }, - "vorne1": { - 3:[3], - 4:[2,3], - 5:[3], - 6:[3], - 7:[3], - 8:[3], - 9:[2,3,4] - }, - "hinten1": { - 3:[9], - 4:[8,9], - 5:[9], - 6:[9], - 7:[9], - 8:[9], - 9:[8,9,10] - }, - "vorne2": { - 3:[2,3,4], - 4:[1,5], - 5:[5], - 6:[4], - 7:[3], - 8:[2], - 9:[1,2,3,4,5] - }, - "hinten2": { - 3:[8,9,10], - 4:[7,11], - 5:[11], - 6:[10], - 7:[9], - 8:[8], - 9:[7,8,9,10,11] - }, - "vorne3": { - 3:[1,2,3,4,5], - 4:[4], - 5:[3], - 6:[4], - 7:[5], - 8:[1,5], - 9:[2,3,4] - }, - "hinten3": { - 3:[7,8,9,10,11], - 4:[10], - 5:[9], - 6:[10], - 7:[11], - 8:[7,11], - 9:[8,9,10] - }, - "vorne4": { - 3:[4], - 4:[3,4], - 5:[2,4], - 6:[1,4], - 7:[1,2,3,4,5], - 8:[4], - 9:[4] - }, - "hinten4": { - 3:[10], - 4:[9,10], - 5:[8,10], - 6:[7,10], - 7:[7,8,9,10,11], - 8:[10], - 9:[10] - }, - "vorne5": { - 3:[1,2,3,4,5], - 4:[1], - 5:[1,2,3,4], - 6:[5], - 7:[5], - 8:[1,5], - 9:[2,3,4] - }, - "hinten5": { - 3:[7,8,9,10,11], - 4:[7], - 5:[7,8,9,10], - 6:[11], - 7:[11], - 8:[7,11], - 9:[8,9,10] - }, - "hinten6": { - 3:[9,10], - 4:[8], - 5:[7], - 6:[7,8,9,10], - 7:[7,11], - 8:[7,11], - 9:[8,9,10] - }, - "hinten7": { - 3:[7,8,9,10,11], - 4:[11], - 5:[10], - 6:[9], - 7:[8], - 8:[8], - 9:[8] - }, - "hinten8": { - 3:[8,9,10], - 4:[7,11], - 5:[7,11], - 6:[8,9,10], - 7:[7,11], - 8:[7,11], - 9:[8,9,10] - }, - "hinten9": { - 3:[8,9,10], - 4:[7,11], - 5:[7,11], - 6:[8,9,10,11], - 7:[11], - 8:[10], - 9:[8,9] - } -}; -var layout = { - "version": 2, - "language": 'Bärndütschi Sekunde', - "letters": [ - 'ESKISCHAFÜF', - 'VIERTUBFZÄÄ', - 'ZWÄNZGSIVOR', - 'ABOHAUBIEGE', - 'EISZWÖISDRÜ', - 'VIERIFÜFIQT', - 'SÄCHSISIBNI', - 'ACHTINÜNIEL', - 'ZÄNIERBEUFI', - 'ZWÖUFINAUHR' - ], - "seconds": { - "0": [h.vorne0, h.hinten0], - "1": [h.vorne0, h.hinten1], - "2": [h.vorne0, h.hinten2], - "3": [h.vorne0, h.hinten3], - "4": [h.vorne0, h.hinten4], - "5": [h.vorne0, h.hinten5], - "6": [h.vorne0, h.hinten6], - "7": [h.vorne0, h.hinten7], - "8": [h.vorne0, h.hinten8], - "9": [h.vorne0, h.hinten9], - "10": [h.vorne1, h.hinten0], - "11": [h.vorne1, h.hinten1], - "12": [h.vorne1, h.hinten2], - "13": [h.vorne1, h.hinten3], - "14": [h.vorne1, h.hinten4], - "15": [h.vorne1, h.hinten5], - "16": [h.vorne1, h.hinten6], - "17": [h.vorne1, h.hinten7], - "18": [h.vorne1, h.hinten8], - "19": [h.vorne1, h.hinten9], - "20": [h.vorne2, h.hinten0], - "21": [h.vorne2, h.hinten1], - "22": [h.vorne2, h.hinten2], - "23": [h.vorne2, h.hinten3], - "24": [h.vorne2, h.hinten4], - "25": [h.vorne2, h.hinten5], - "26": [h.vorne2, h.hinten6], - "27": [h.vorne2, h.hinten7], - "28": [h.vorne2, h.hinten8], - "29": [h.vorne2, h.hinten9], - "30": [h.vorne3, h.hinten0], - "31": [h.vorne3, h.hinten1], - "32": [h.vorne3, h.hinten2], - "33": [h.vorne3, h.hinten3], - "34": [h.vorne3, h.hinten4], - "35": [h.vorne3, h.hinten5], - "36": [h.vorne3, h.hinten6], - "37": [h.vorne3, h.hinten7], - "38": [h.vorne3, h.hinten8], - "39": [h.vorne3, h.hinten9], - "40": [h.vorne4, h.hinten0], - "41": [h.vorne4, h.hinten1], - "42": [h.vorne4, h.hinten2], - "43": [h.vorne4, h.hinten3], - "44": [h.vorne4, h.hinten4], - "45": [h.vorne4, h.hinten5], - "46": [h.vorne4, h.hinten6], - "47": [h.vorne4, h.hinten7], - "48": [h.vorne4, h.hinten8], - "49": [h.vorne4, h.hinten9], - "50": [h.vorne5, h.hinten0], - "51": [h.vorne5, h.hinten1], - "52": [h.vorne5, h.hinten2], - "53": [h.vorne5, h.hinten3], - "54": [h.vorne5, h.hinten4], - "55": [h.vorne5, h.hinten5], - "56": [h.vorne5, h.hinten6], - "57": [h.vorne5, h.hinten7], - "58": [h.vorne5, h.hinten8], - "59": [h.vorne5, h.hinten9] - }, - "getDotMinute": function(time) { - return 0; - } -}; -window,_uhr.register('de_CH_seconds', layout); From 79430a6821bc57c09afec0adba78a5d09fab79b6 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Tue, 12 Aug 2014 00:39:13 +0200 Subject: [PATCH 07/12] old file, it's now at js/uhr.js --- uhr.js | 473 --------------------------------------------------------- 1 file changed, 473 deletions(-) delete mode 100644 uhr.js diff --git a/uhr.js b/uhr.js deleted file mode 100644 index 9df362a..0000000 --- a/uhr.js +++ /dev/null @@ -1,473 +0,0 @@ -/* -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ -(function($) { - 'use strict'; - - if (window._uhr !== undefined) { - return; - } - - window._uhr = { - id: 0, - languages: [], - themes: [], - register: function(code, language) { - for (var i = 0; i < this.languages.length; i++) { - if (code == this.languages[i].code) { - console.error('Error: Language code ' + code + ' cannot be registered for language "' + language.language + '" because it is already registered for language "' + this.languages[i].language + '"!'); - return false; - } - } - language.code = code; - this.languages.push(language); - } - }; - // auto-detect themes - var styleSheets = $('link[rel=stylesheet]'); - for (var i = 0; i < styleSheets.length; i++) { - var styleSheet = $(styleSheets[i]); - var styleClass = styleSheet.attr('data-class'); - if (styleClass !== undefined) { - var name = styleSheet.attr('data-name'); - if (name === undefined) { - name = styleClass; - } - window._uhr.themes.push({'styleClass': styleClass, 'name': name}); - } - } - // fall-back if no theme was included - if (window._uhr.themes.length == 0) { - window._uhr.themes.push({}); - } - $.widget("fritteli.uhr", { - options: { - width: '100%', - status: 'on', - language: 'de_CH', - theme: window._uhr.themes[0].styleClass, - force: false, - controls: true - }, - start: function() { - if (!this._isOn()) { - var uhr = this; - this._timer = window.setInterval(function() { - uhr.options.time = new Date(); - uhr._update(); - }, 1000); - this._update(); - this._setCookie('uhr-status', 'on'); - } else { - } - }, - stop: function() { - if(this._isOn()) { - window.clearInterval(this._timer); - this._timer = null; - this._update(); - this._setCookie('uhr-status', 'off'); - } - }, - toggle: function() { - if(this._isOn()) { - this.stop(); - } else { - this.start(); - } - }, - language: function(languageKey) { - if (languageKey !== this.options.language) { - this.options.language = languageKey; - var renderer = new UhrRenderer(this._language(), this.element.find('.letterarea')); - var uhr = this; - renderer.render(this, function() { - uhr._currentMinute = -1; - uhr._update(); - }); - this._setCookie('uhr-language', languageKey); - this._update(); - } - }, - theme: function(theme) { - if (theme != this.options.theme) { - this.element.removeClass(this.options.theme).addClass(theme); - $('#uhr-onoffswitch' + this._id).removeClass(this.options.theme).addClass(theme); - this.options.theme = theme; - this._setCookie('uhr-theme', theme); - } - }, - time: function(time) { - this._currentMinute = -1; - if (time == null) { - this.options.time = new Date(); - } else { - if (this._timer != null) { - window.clearInterval(this._timer); - } - this.options.time = time; - } - this._update(); - }, - // private variables - _id: -1, - _timer: null, - _currentMinute: -1, - // private methods - _isOn: function() { - return this._timer !== null; - }, - _update: function() { - if (this._isOn()) { - var time = this.options.time; - if (!this._language().hasOwnProperty('seconds')) { - if (time.getMinutes() == this._currentMinute) { - return; - } - this._currentMinute = time.getMinutes(); - } - this._show(time); - } else { - this._clear(); - this._currentMinute = -1; - } - }, - _show: function(time) { - var second = this._getSecond(time); - var dotMinute = this._getDotMinute(time); - var hour = this._getHour(time); - var coarseMinute = this._getCoarseMinute(time); - this._clear(); - this._highlight('on'); - for (var i = 1; i <= dotMinute; i++) { - this._highlight('dot' + i); - } - this._highlight('second' + second); - this._highlight('minute' + coarseMinute); - this._highlight('hour' + hour); - }, - _language: function() { - for (var i = 0; i < window._uhr.languages.length; i++) { - var language = window._uhr.languages[i]; - if (language.code == this.options.language) { - return language; - } - } - // fallback: return empty object - return {}; - }, - _highlight: function(itemClass) { - this.element.find('.item.' + itemClass).addClass('active'); - }, - _clear: function() { - this.element.find('.item').removeClass('active'); - }, - _getHour: function(date) { - if (typeof this._language().getHour === 'function') { - return this._language().getHour(date); - } - var hour = date.getHours(); - if (date.getMinutes() >= 25) { - return (hour + 1) % 24; - } - return hour; - }, - _getCoarseMinute: function(date) { - if (typeof this._language().getCoarseMinute === 'function') { - return this._language().getCoarseMinute(date); - } - return date.getMinutes(); - }, - _getDotMinute: function(date) { - if (typeof this._language().getDotMinute === 'function') { - return this._language().getDotMinute(date); - } - var minutes = date.getMinutes(); - return minutes % 5; - }, - _getSecond: function(date) { - if (typeof this._language().getSecond === 'function') { - return this._language().getSecond(date); - } - return date.getSeconds(); - }, - _create: function() { - this._id = window._uhr.id++; - var userTime = this.options.time; - if (this.options.time === undefined) { - this.options.time = new Date(); - } - this._setupHTML(); - this._wireFunctionality(); - if (userTime !== undefined) { - this.time(userTime); - } - }, - _setupHTML: function() { - var e = this.element; - // Base clock area - e.addClass('uhr'); - e.empty(); - e.append(''); - e.append(''); - e.append(''); - e.append(''); - e.append('
'); - e.append('
'); - e.css('width', this.options.width); - var realWidth = e.width(); - e.width(realWidth); - e.height(realWidth); - e.css('font-size', (realWidth / 40) + 'px'); - - if (this.options.controls) { - // on/off switch - var toggleSwitch = $('
'); - toggleSwitch.append(''); - toggleSwitch.append(''); - e.after(toggleSwitch); - - // language chooser - if (window._uhr.languages.length > 1) { - var languageChooser = $(''); - for (var i = 0; i < window._uhr.languages.length; i++) { - var language = window._uhr.languages[i]; - languageChooser.append(''); - } - e.after(languageChooser); - } - - // theme chooser - if (window._uhr.themes.length > 1) { - var themeChooser = $(''); - for (var i = 0; i < window._uhr.themes.length; i++) { - var theme = window._uhr.themes[i]; - themeChooser.append(''); - } - e.after(themeChooser); - } - } - }, - _wireFunctionality: function() { - var uhr = this; - - // on/off switch - var toggleSwitch = $('#uhr-onoffswitch-checkbox' + this._id); - toggleSwitch.on('click', function() { - uhr.toggle(); - }); - var status = $.cookie('uhr-status' + this._id); - if (status == undefined || this.options.force) { - status = this.options.status; - } - toggleSwitch.prop('checked', status == 'on'); - if (status == 'on') { - this.start(); - } else { - this.stop(); - } - - // language chooser - var languageChooser = $('#uhr-languagechooser' + this._id); - languageChooser.on('change', function() { - uhr.language(this.value); - }); - var selectedLanguage = $.cookie('uhr-language' + this._id); - if (selectedLanguage == undefined || this.options.force) { - selectedLanguage = this.options.language; - } - var found = false; - for (var i = 0; i < window._uhr.languages.length; i++) { - var code = window._uhr.languages[i].code; - if (selectedLanguage == code) { - found = true; - break; - } - } - if (!found) { - var fallback; - if (window._uhr.languages.length > 0) { - fallback = window._uhr.languages[0].code; - } else { - fallback = ''; - } - console.warn("Language " + selectedLanguage + " not found! Using fallback: " + fallback); - selectedLanguage = fallback; - } - languageChooser.val(selectedLanguage); - this.options.language = ""; - this.language(selectedLanguage); - - // theme chooser - var themeChooser = $('#uhr-themechooser' + this._id); - themeChooser.on('change', function() { - uhr.theme(this.value); - }); - var selectedTheme = $.cookie('uhr-theme' + this._id); - if (selectedTheme == undefined || this.options.force) { - selectedTheme = this.options.theme; - } - found = false; - for (var i = 0; i < window._uhr.themes.length; i++) { - var styleClass = window._uhr.themes[i].styleClass; - if (selectedTheme == styleClass) { - found = true; - break; - } - } - if (!found) { - var fallback = window._uhr.themes[0].styleClass; - console.warn("Theme " + selectedTheme + " not found! Using fallback: " + fallback); - selectedTheme = fallback; - } - themeChooser.val(selectedTheme); - this.options.theme = ""; - this.theme(selectedTheme); - }, - _setCookie: function(cookieName, cookieValue) { - var options = {}; - if (this.options.cookiePath !== undefined) { - options = {expires: 365, path: this.options.cookiePath}; - } else { - options = {expires: 365}; - } - $.cookie(cookieName + this._id, cookieValue, options); - } - }); - /** - * Hilfsklasse zum Rendern der Uhr. - * @param layout Layout-Objekt, das gerendert werden soll. - * @param renderarea Das jQuery-gewrappte HTML-Element, auf dem gerendert werden soll. - */ - function UhrRenderer(layout, renderarea) { - this.layout = layout; - this.renderarea = renderarea; - } - UhrRenderer.prototype.render = function(uhr, beforeshow) { - var renderer = this; - if (this.layout._parsed === undefined) { - switch (this.layout.version) { - case 2: - var delegate = new _UhrRendererV2Delegate(this.layout); - this.layout._parsed = delegate.parse(); - break; - default: - console.warn("Unknown layout version: '" + this.layout.version + "'"); - return; - } - } - var letters = this.layout._parsed; - this.renderarea.fadeOut('fast', function() { - renderer.renderarea.empty(); - for (var y = 0; y < letters.length; y++) { - for (var x = 0; x < letters[y].length; x++) { - var letter = letters[y][x]; - renderer.renderarea.append(letter.toString()); - } - if (y < letters.length - 1) { - renderer.renderarea.append('
'); - } - } - if (typeof beforeshow === 'function') { - beforeshow(); - } - renderer.renderarea.fadeIn('fast'); - }); - }; - function _UhrRendererV2Delegate(layout) { - this.layout = layout; - this._parseArrayOrObject = function(letters, styleClass, input) { - if (typeof input !== 'undefined' && input !== null) { - if (Array.isArray(input)) { - for (var i = 0; i < input.length; i++) { - this._parseObject(letters, styleClass, input[i]); - } - } else { - this._parseObject(letters, styleClass, input); - } - } - } - this._parseObject = function(letters, styleClass, object) { - if (typeof object !== 'undefined' && object !== null) { - for (var line in object) { - if (object.hasOwnProperty(line)) { - var highlightLetters = object[line]; - for (var i = 0; i < highlightLetters.length; i++) { - var x = highlightLetters[i] - 1; - letters[line - 1][x].addStyle(styleClass); - } - } - } - } - } - this._parseTimeDefinition = function(letters, styleClass, definition) { - if (typeof definition !== 'undefined' && definition != null) { - for (var listString in definition) { - if (definition.hasOwnProperty(listString)) { - var array = listString.split(','); - var highlightLetters = definition[listString]; - for (var index = 0; index < array.length; index++) { - this._parseArrayOrObject(letters, styleClass + array[index], highlightLetters); - } - } - } - } - } - } - _UhrRendererV2Delegate.prototype.parse = function() { - var letters = []; - for (var i = 0; i < this.layout.letters.length; i++) { - var line = []; - var string = this.layout.letters[i]; - for (var c = 0; c < string.length; c++) { - var character = new Letter(string[c]); - line.push(character); - } - letters.push(line); - } - this._parseArrayOrObject(letters, 'on', this.layout.permanent); - this._parseTimeDefinition(letters, 'second', this.layout.seconds); - this._parseTimeDefinition(letters, 'minute', this.layout.minutes); - this._parseTimeDefinition(letters, 'hour', this.layout.hours); - return letters; - }; - /** - * Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays. - * @param value Der Buchstabe, der Dargestellt werden soll. - * @param style Die CSS-Styleklassen des Buchstabens. - */ - function Letter(value, style) { - this.value = value; - this.style = style || ''; - this.getStyle = function() { - return 'item letter ' + this.style; - }; - this.getValue = function() { - return value; - } - this.addStyle = function(style) { - if (this.style == '') { - this.style = style; - } else { - this.style += ' ' + style; - } - } - } - Letter.prototype.toString = function letterToString() { - return '' + this.getValue() + ''; - }; -})(jQuery); From dbbfae83b301977e3d5e2c6ed3c64f2a6b826f70 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Tue, 12 Aug 2014 00:41:26 +0200 Subject: [PATCH 08/12] don't add trailing slash --- .gitignore | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 34662c8..38adccb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -*~ -.idea/ -*.iml -atlassian-ide-plugin.xml +*~ +.idea +*.iml +atlassian-ide-plugin.xml From a3dce2322b3f69aa240dbaef4fed20612ddf5d33 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Tue, 12 Aug 2014 00:44:29 +0200 Subject: [PATCH 09/12] don't remove blank line --- js/uhr.js | 967 +++++++++++++++++++++++++++--------------------------- 1 file changed, 484 insertions(+), 483 deletions(-) diff --git a/js/uhr.js b/js/uhr.js index 11bcc62..413f57b 100644 --- a/js/uhr.js +++ b/js/uhr.js @@ -1,484 +1,485 @@ -/* - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ -(function ($) { - 'use strict'; - var uhrGlobals = { - "id": 0, - "languages": [], - "themes": [], - registerLanguage: function registerLanguage(code, language) { - var alreadyExists = uhrGlobals.languages.some(function (element) { - if (code === element.code) { - console.error("Error: Language code '" + code + "' cannot be registered for language '" + language.language + "' because it is already registered for language '" + element.language + "'!"); - return true; - } - return false; - }); - if (!alreadyExists) { - language.code = code; - uhrGlobals.languages.push(language); - } - } - }; - - // auto-detect themes - $('link[rel=stylesheet]').each(function (index, item) { - var styleSheet = $(item); - var styleClass = styleSheet.attr('data-class'); - if (styleClass !== undefined) { - var name = styleSheet.attr('data-name'); - if (name === undefined) { - name = styleClass; - } - uhrGlobals.themes.push({'styleClass': styleClass, 'name': name}); - } - }); - // fall-back if no theme was included - if (uhrGlobals.themes.length === 0) { - uhrGlobals.themes.push({}); - } - - // public interface methods (exported later) - var start = function start() { - if (!isOn.bind(this)()) { - this.timer = window.setInterval(function () { - this.options.time = new Date(); - update.bind(this)(); - }.bind(this), 1000); - update.bind(this)(); - setCookie.bind(this)('uhr-status', 'on'); - } - }; - var stop = function stop() { - if (isOn.bind(this)()) { - window.clearInterval(this.timer); - this.timer = null; - update.bind(this)(); - setCookie.bind(this)('uhr-status', 'off'); - } - }; - var toggle = function toggle() { - if (isOn.bind(this)()) { - this.stop(); - } else { - this.start(); - } - }; - var setLanguage = function setLanugage(languageKey) { - if (languageKey !== this.options.language) { - this.options.language = languageKey; - var renderer = new UhrRenderer(language.bind(this)(), this.element.find('.letterarea')); - renderer.render.bind(this)(function () { - this.currentMinute = -1; - update.bind(this)(); - }.bind(this)); - setCookie.bind(this)('uhr-language', languageKey); - update.bind(this)(); - } - }; - var setTheme = function setTheme(theme) { - if (theme !== this.options.theme) { - this.element.removeClass(this.options.theme).addClass(theme); - $('#uhr-onoffswitch' + this.id).removeClass(this.options.theme).addClass(theme); - this.options.theme = theme; - setCookie.bind(this)('uhr-theme', theme); - } - }; - var setTime = function setTime(time) { - this.currentMinute = -1; - if (time === null) { - this.options.time = new Date(); - } else { - if (this.timer !== null) { - window.clearInterval(this.timer); - } - this.options.time = time; - } - update.bind(this)(); - }; - var setWidth = function setWidth(width) { - var e = this.element; - e.css('width', width); - var realWidth = e.width(); - e.width(realWidth); - e.height(realWidth); - e.css('font-size', (realWidth / 40) + 'px'); - }; - // private interface methods - var create = function create() { - this.id = uhrGlobals.id++; - this.timer = null; - this.currentMinute = -1; - var userTime = this.options.time; - if (this.options.time === undefined) { - this.options.time = new Date(); - } - setupHTML.bind(this)(); - wireFunctionality.bind(this)(); - if (userTime !== undefined) { - this.time(userTime); - } - }; - // private helper methods (not exported) - var showConfigScreen = function showConfigScreen() { - $('#uhr-controlpanel' + this.id).show(); - }; - // set up - var setupHTML = function setupHTML() { - var e = this.element; - // Base clock area - e.addClass('uhr'); - e.empty(); - e.append(''); - e.append(''); - e.append(''); - e.append(''); - e.append('
'); - e.append('
'); - setWidth.bind(this)(this.options.width); - - if (this.options.controls) { - var configlink = $(''); - configlink.on('click', function () { - showConfigScreen.bind(this)(); - }.bind(this)); - e.after(configlink); - var controlpanel = $('
'); - var content = $('
'); - controlpanel.append(content); - // on/off switch - var toggleSwitch = $('
'); - toggleSwitch.append(''); - toggleSwitch.append(''); - content.append(toggleSwitch); - - // language chooser - if (uhrGlobals.languages.length > 1) { - var languageChooser = $(''); - uhrGlobals.languages.forEach(function (item) { - languageChooser.append(''); - }); - content.append(languageChooser); - } - - // theme chooser - if (uhrGlobals.themes.length > 1) { - var themeChooser = $(''); - uhrGlobals.themes.forEach(function (item) { - themeChooser.append(''); - }); - content.append(themeChooser); - } - var closebutton = $(''); - closebutton.on('click', function () { - $('#uhr-controlpanel' + this.id).hide(); - }.bind(this)); - content.append(closebutton); - e.after(controlpanel); - controlpanel.hide(); - } - }; - var wireFunctionality = function wireFunctionality() { - // on/off switch - var toggleSwitch = $('#uhr-onoffswitch-checkbox' + this.id); - toggleSwitch.on('click', function () { - this.toggle(); - }.bind(this)); - var status = $.cookie('uhr-status' + this.id); - if (status === undefined || this.options.force) { - status = this.options.status; - } - toggleSwitch.prop('checked', status === 'on'); - if (status === 'on') { - this.start(); - } else { - this.stop(); - } - - // language chooser - var languageChooser = $('#uhr-languagechooser' + this.id); - languageChooser.on('change', function () { - var languageKey = $('#uhr-languagechooser' + this.id).val(); - this.language(languageKey); - }.bind(this)); - var selectedLanguage = $.cookie('uhr-language' + this.id); - if (selectedLanguage === undefined || this.options.force) { - selectedLanguage = this.options.language; - } - var found = uhrGlobals.languages.some(function (item) { - return selectedLanguage === item.code; - }); - if (!found) { - var fallbackLanguage; - if (uhrGlobals.languages.length > 0) { - fallbackLanguage = uhrGlobals.languages[0].code; - } else { - fallbackLanguage = ''; - } - console.warn("Language '" + selectedLanguage + "' not found! Using fallback '" + fallbackLanguage + "'"); - selectedLanguage = fallbackLanguage; - } - languageChooser.val(selectedLanguage); - this.options.language = ""; - this.language(selectedLanguage); - - // theme chooser - var themeChooser = $('#uhr-themechooser' + this.id); - themeChooser.on('change', function () { - var themeKey = $('#uhr-themechooser' + this.id).val(); - this.theme(themeKey); - }.bind(this)); - var selectedTheme = $.cookie('uhr-theme' + this.id); - if (selectedTheme === undefined || this.options.force) { - selectedTheme = this.options.theme; - } - found = uhrGlobals.themes.some(function (item) { - return selectedTheme === item.styleClass; - }); - if (!found) { - var fallbackTheme = uhrGlobals.themes[0].styleClass; - console.warn("Theme '" + selectedTheme + "' not found! Using fallback '" + fallbackTheme + "'"); - selectedTheme = fallbackTheme; - } - themeChooser.val(selectedTheme); - this.options.theme = ""; - this.theme(selectedTheme); - }; - var setCookie = function setCookie(cookieName, cookieValue) { - var options = {}; - if (this.options.cookiePath !== undefined) { - options = {expires: 365, path: this.options.cookiePath}; - } else { - options = {expires: 365}; - } - $.cookie(cookieName + this.id, cookieValue, options); - }; - - // business logic - var isOn = function isOn() { - return this.timer !== null; - }; - var update = function update() { - if (isOn.bind(this)()) { - var time = this.options.time; - if (!language.bind(this)().hasOwnProperty('seconds')) { - if (time.getMinutes() === this.currentMinute) { - return; - } - this.currentMinute = time.getMinutes(); - } - show.bind(this)(time); - } else { - clear.bind(this)(); - this.currentMinute = -1; - } - }; - var show = function show(time) { - var second = getSecond.bind(this)(time); - var dotMinute = getDotMinute.bind(this)(time); - var hour = getHour.bind(this)(time); - var coarseMinute = getCoarseMinute.bind(this)(time); - clear.bind(this)(); - highlight.bind(this)('on'); - for (var i = 1; i <= dotMinute; i++) { - highlight.bind(this)('dot' + i); - } - highlight.bind(this)('second' + second); - highlight.bind(this)('minute' + coarseMinute); - highlight.bind(this)('hour' + hour); - }; - var highlight = function highlight(itemClass) { - this.element.find('.item.' + itemClass).addClass('active'); - }; - var clear = function clear() { - this.element.find('.item').removeClass('active'); - }; - var getSecond = function getSecond(date) { - if (typeof language.bind(this)().getSeconds === 'function') { - return language.bind(this)().getSeconds(date); - } - return date.getSeconds(); - }; - var getDotMinute = function getDotMinute(date) { - if (typeof language.bind(this)().getDotMinute === 'function') { - return language.bind(this)().getDotMinute(date); - } - var minutes = date.getMinutes(); - return minutes % 5; - }; - var getCoarseMinute = function getCoarseMinute(date) { - if (typeof language.bind(this)().getCoarseMinute === 'function') { - return language.bind(this)().getCoarseMinute(date); - } - return date.getMinutes(); - }; - var getHour = function getHour(date) { - if (typeof language.bind(this)().getHour === 'function') { - return language.bind(this)().getHour(date); - } - var hour = date.getHours(); - if (date.getMinutes() >= 25) { - return (hour + 1) % 24; - } - return hour; - }; - - var language = function language() { - var matchingLanguages = uhrGlobals.languages.filter(function (element) { - return (element.code === this.options.language); - }, this); - if (matchingLanguages.length > 0) { - return matchingLanguages[0]; - } - // fallback: return empty object - return {}; - }; - - $.widget("fritteli.uhr", { - "options": { - width: '100%', - status: 'on', - language: 'de_CH', - theme: uhrGlobals.themes[0].styleClass, - force: false, - controls: true, - cookiePath: undefined - }, - "start": start, - "stop": stop, - "toggle": toggle, - "language": setLanguage, - "theme": setTheme, - "time": setTime, - "width": setWidth, - // constructor method - "_create": create - }); - $.fritteli.uhr.register = uhrGlobals.registerLanguage; - /** - * Hilfsklasse zum Rendern der Uhr. - * @param layout Layout-Objekt, das gerendert werden soll. - * @param renderarea Das jQuery-gewrappte HTML-Element, auf dem gerendert werden soll. - */ - function UhrRenderer(layout, renderarea) { - this.render = function render(beforeshow) { - if (layout.parsed === undefined) { - switch (layout.version) { - case 2: - var delegate = new UhrRendererV2Delegate(layout); - var parsedLayout = delegate.parse(); - Object.defineProperty(layout, "parsed", {"value": parsedLayout, "writable": false, "configurable": false}); - break; - default: - console.warn("Unknown layout version: '" + layout.version + "'"); - return; - } - } - var letters = layout.parsed; - renderarea.fadeOut('fast', function () { - renderarea.empty(); - letters.forEach(function (line, index, array) { - line.forEach(function (letter) { - renderarea.append(letter.toString()); - }); - if (index < array.length - 1) { - renderarea.append('
'); - } - }); - if (typeof beforeshow === 'function') { - beforeshow(); - } - renderarea.fadeIn('fast'); - }); - }; - } - - function UhrRendererV2Delegate(layout) { - function parseArrayOrObject(letters, styleClass, input) { - if (typeof input !== 'undefined' && input !== null) { - if (Array.isArray(input)) { - input.forEach(function (item) { - parseObject(letters, styleClass, item); - }); - } else { - parseObject(letters, styleClass, input); - } - } - } - - function parseObject(letters, styleClass, object) { - if (typeof object !== 'undefined' && object !== null) { - Object.keys(object).forEach(function (y) { - var highlightLetters = object[y]; - highlightLetters.forEach(function (x) { - letters[y - 1][x - 1].addStyle(styleClass); - }); - }); - } - } - - function parseTimeDefinition(letters, styleClass, definition) { - if (typeof definition !== 'undefined' && definition !== null) { - Object.keys(definition).forEach(function (listString) { - var array = listString.split(','); - var highlightLetters = definition[listString]; - array.forEach(function (item) { - parseArrayOrObject(letters, styleClass + item, highlightLetters); - }); - }); - } - } - - this.parse = function parse() { - var letters = []; - layout.letters.forEach(function (string) { - var line = []; - for (var c = 0; c < string.length; c++) { - var character = new Letter(string[c]); - line.push(character); - } - letters.push(line); - }); - parseArrayOrObject(letters, 'on', layout.permanent); - parseTimeDefinition(letters, 'second', layout.seconds); - parseTimeDefinition(letters, 'minute', layout.minutes); - parseTimeDefinition(letters, 'hour', layout.hours); - return letters; - }; - } - - /** - * Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays. - * @param value Der Buchstabe, der Dargestellt werden soll. - * @param style Die CSS-Styleklassen des Buchstabens. - */ - function Letter(value, style) { - var myValue = value; - var myStyle = style || ''; - this.addStyle = function (style) { - if (myStyle === '') { - myStyle = style; - } else { - myStyle += ' ' + style; - } - }; - this.toString = function () { - return '' + myValue + ''; - }; - } +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +(function ($) { + 'use strict'; + var uhrGlobals = { + "id": 0, + "languages": [], + "themes": [], + registerLanguage: function registerLanguage(code, language) { + var alreadyExists = uhrGlobals.languages.some(function (element) { + if (code === element.code) { + console.error("Error: Language code '" + code + "' cannot be registered for language '" + language.language + "' because it is already registered for language '" + element.language + "'!"); + return true; + } + return false; + }); + if (!alreadyExists) { + language.code = code; + uhrGlobals.languages.push(language); + } + } + }; + + // auto-detect themes + $('link[rel=stylesheet]').each(function (index, item) { + var styleSheet = $(item); + var styleClass = styleSheet.attr('data-class'); + if (styleClass !== undefined) { + var name = styleSheet.attr('data-name'); + if (name === undefined) { + name = styleClass; + } + uhrGlobals.themes.push({'styleClass': styleClass, 'name': name}); + } + }); + // fall-back if no theme was included + if (uhrGlobals.themes.length === 0) { + uhrGlobals.themes.push({}); + } + + // public interface methods (exported later) + var start = function start() { + if (!isOn.bind(this)()) { + this.timer = window.setInterval(function () { + this.options.time = new Date(); + update.bind(this)(); + }.bind(this), 1000); + update.bind(this)(); + setCookie.bind(this)('uhr-status', 'on'); + } + }; + var stop = function stop() { + if (isOn.bind(this)()) { + window.clearInterval(this.timer); + this.timer = null; + update.bind(this)(); + setCookie.bind(this)('uhr-status', 'off'); + } + }; + var toggle = function toggle() { + if (isOn.bind(this)()) { + this.stop(); + } else { + this.start(); + } + }; + var setLanguage = function setLanugage(languageKey) { + if (languageKey !== this.options.language) { + this.options.language = languageKey; + var renderer = new UhrRenderer(language.bind(this)(), this.element.find('.letterarea')); + renderer.render.bind(this)(function () { + this.currentMinute = -1; + update.bind(this)(); + }.bind(this)); + setCookie.bind(this)('uhr-language', languageKey); + update.bind(this)(); + } + }; + var setTheme = function setTheme(theme) { + if (theme !== this.options.theme) { + this.element.removeClass(this.options.theme).addClass(theme); + $('#uhr-onoffswitch' + this.id).removeClass(this.options.theme).addClass(theme); + this.options.theme = theme; + setCookie.bind(this)('uhr-theme', theme); + } + }; + var setTime = function setTime(time) { + this.currentMinute = -1; + if (time === null) { + this.options.time = new Date(); + } else { + if (this.timer !== null) { + window.clearInterval(this.timer); + } + this.options.time = time; + } + update.bind(this)(); + }; + var setWidth = function setWidth(width) { + var e = this.element; + e.css('width', width); + var realWidth = e.width(); + e.width(realWidth); + e.height(realWidth); + e.css('font-size', (realWidth / 40) + 'px'); + }; + + // private interface methods + var create = function create() { + this.id = uhrGlobals.id++; + this.timer = null; + this.currentMinute = -1; + var userTime = this.options.time; + if (this.options.time === undefined) { + this.options.time = new Date(); + } + setupHTML.bind(this)(); + wireFunctionality.bind(this)(); + if (userTime !== undefined) { + this.time(userTime); + } + }; + // private helper methods (not exported) + var showConfigScreen = function showConfigScreen() { + $('#uhr-controlpanel' + this.id).show(); + }; + // set up + var setupHTML = function setupHTML() { + var e = this.element; + // Base clock area + e.addClass('uhr'); + e.empty(); + e.append(''); + e.append(''); + e.append(''); + e.append(''); + e.append('
'); + e.append('
'); + setWidth.bind(this)(this.options.width); + + if (this.options.controls) { + var configlink = $(''); + configlink.on('click', function () { + showConfigScreen.bind(this)(); + }.bind(this)); + e.after(configlink); + var controlpanel = $('
'); + var content = $('
'); + controlpanel.append(content); + // on/off switch + var toggleSwitch = $('
'); + toggleSwitch.append(''); + toggleSwitch.append(''); + content.append(toggleSwitch); + + // language chooser + if (uhrGlobals.languages.length > 1) { + var languageChooser = $(''); + uhrGlobals.languages.forEach(function (item) { + languageChooser.append(''); + }); + content.append(languageChooser); + } + + // theme chooser + if (uhrGlobals.themes.length > 1) { + var themeChooser = $(''); + uhrGlobals.themes.forEach(function (item) { + themeChooser.append(''); + }); + content.append(themeChooser); + } + var closebutton = $(''); + closebutton.on('click', function () { + $('#uhr-controlpanel' + this.id).hide(); + }.bind(this)); + content.append(closebutton); + e.after(controlpanel); + controlpanel.hide(); + } + }; + var wireFunctionality = function wireFunctionality() { + // on/off switch + var toggleSwitch = $('#uhr-onoffswitch-checkbox' + this.id); + toggleSwitch.on('click', function () { + this.toggle(); + }.bind(this)); + var status = $.cookie('uhr-status' + this.id); + if (status === undefined || this.options.force) { + status = this.options.status; + } + toggleSwitch.prop('checked', status === 'on'); + if (status === 'on') { + this.start(); + } else { + this.stop(); + } + + // language chooser + var languageChooser = $('#uhr-languagechooser' + this.id); + languageChooser.on('change', function () { + var languageKey = $('#uhr-languagechooser' + this.id).val(); + this.language(languageKey); + }.bind(this)); + var selectedLanguage = $.cookie('uhr-language' + this.id); + if (selectedLanguage === undefined || this.options.force) { + selectedLanguage = this.options.language; + } + var found = uhrGlobals.languages.some(function (item) { + return selectedLanguage === item.code; + }); + if (!found) { + var fallbackLanguage; + if (uhrGlobals.languages.length > 0) { + fallbackLanguage = uhrGlobals.languages[0].code; + } else { + fallbackLanguage = ''; + } + console.warn("Language '" + selectedLanguage + "' not found! Using fallback '" + fallbackLanguage + "'"); + selectedLanguage = fallbackLanguage; + } + languageChooser.val(selectedLanguage); + this.options.language = ""; + this.language(selectedLanguage); + + // theme chooser + var themeChooser = $('#uhr-themechooser' + this.id); + themeChooser.on('change', function () { + var themeKey = $('#uhr-themechooser' + this.id).val(); + this.theme(themeKey); + }.bind(this)); + var selectedTheme = $.cookie('uhr-theme' + this.id); + if (selectedTheme === undefined || this.options.force) { + selectedTheme = this.options.theme; + } + found = uhrGlobals.themes.some(function (item) { + return selectedTheme === item.styleClass; + }); + if (!found) { + var fallbackTheme = uhrGlobals.themes[0].styleClass; + console.warn("Theme '" + selectedTheme + "' not found! Using fallback '" + fallbackTheme + "'"); + selectedTheme = fallbackTheme; + } + themeChooser.val(selectedTheme); + this.options.theme = ""; + this.theme(selectedTheme); + }; + var setCookie = function setCookie(cookieName, cookieValue) { + var options = {}; + if (this.options.cookiePath !== undefined) { + options = {expires: 365, path: this.options.cookiePath}; + } else { + options = {expires: 365}; + } + $.cookie(cookieName + this.id, cookieValue, options); + }; + + // business logic + var isOn = function isOn() { + return this.timer !== null; + }; + var update = function update() { + if (isOn.bind(this)()) { + var time = this.options.time; + if (!language.bind(this)().hasOwnProperty('seconds')) { + if (time.getMinutes() === this.currentMinute) { + return; + } + this.currentMinute = time.getMinutes(); + } + show.bind(this)(time); + } else { + clear.bind(this)(); + this.currentMinute = -1; + } + }; + var show = function show(time) { + var second = getSecond.bind(this)(time); + var dotMinute = getDotMinute.bind(this)(time); + var hour = getHour.bind(this)(time); + var coarseMinute = getCoarseMinute.bind(this)(time); + clear.bind(this)(); + highlight.bind(this)('on'); + for (var i = 1; i <= dotMinute; i++) { + highlight.bind(this)('dot' + i); + } + highlight.bind(this)('second' + second); + highlight.bind(this)('minute' + coarseMinute); + highlight.bind(this)('hour' + hour); + }; + var highlight = function highlight(itemClass) { + this.element.find('.item.' + itemClass).addClass('active'); + }; + var clear = function clear() { + this.element.find('.item').removeClass('active'); + }; + var getSecond = function getSecond(date) { + if (typeof language.bind(this)().getSeconds === 'function') { + return language.bind(this)().getSeconds(date); + } + return date.getSeconds(); + }; + var getDotMinute = function getDotMinute(date) { + if (typeof language.bind(this)().getDotMinute === 'function') { + return language.bind(this)().getDotMinute(date); + } + var minutes = date.getMinutes(); + return minutes % 5; + }; + var getCoarseMinute = function getCoarseMinute(date) { + if (typeof language.bind(this)().getCoarseMinute === 'function') { + return language.bind(this)().getCoarseMinute(date); + } + return date.getMinutes(); + }; + var getHour = function getHour(date) { + if (typeof language.bind(this)().getHour === 'function') { + return language.bind(this)().getHour(date); + } + var hour = date.getHours(); + if (date.getMinutes() >= 25) { + return (hour + 1) % 24; + } + return hour; + }; + + var language = function language() { + var matchingLanguages = uhrGlobals.languages.filter(function (element) { + return (element.code === this.options.language); + }, this); + if (matchingLanguages.length > 0) { + return matchingLanguages[0]; + } + // fallback: return empty object + return {}; + }; + + $.widget("fritteli.uhr", { + "options": { + width: '100%', + status: 'on', + language: 'de_CH', + theme: uhrGlobals.themes[0].styleClass, + force: false, + controls: true, + cookiePath: undefined + }, + "start": start, + "stop": stop, + "toggle": toggle, + "language": setLanguage, + "theme": setTheme, + "time": setTime, + "width": setWidth, + // constructor method + "_create": create + }); + $.fritteli.uhr.register = uhrGlobals.registerLanguage; + /** + * Hilfsklasse zum Rendern der Uhr. + * @param layout Layout-Objekt, das gerendert werden soll. + * @param renderarea Das jQuery-gewrappte HTML-Element, auf dem gerendert werden soll. + */ + function UhrRenderer(layout, renderarea) { + this.render = function render(beforeshow) { + if (layout.parsed === undefined) { + switch (layout.version) { + case 2: + var delegate = new UhrRendererV2Delegate(layout); + var parsedLayout = delegate.parse(); + Object.defineProperty(layout, "parsed", {"value": parsedLayout, "writable": false, "configurable": false}); + break; + default: + console.warn("Unknown layout version: '" + layout.version + "'"); + return; + } + } + var letters = layout.parsed; + renderarea.fadeOut('fast', function () { + renderarea.empty(); + letters.forEach(function (line, index, array) { + line.forEach(function (letter) { + renderarea.append(letter.toString()); + }); + if (index < array.length - 1) { + renderarea.append('
'); + } + }); + if (typeof beforeshow === 'function') { + beforeshow(); + } + renderarea.fadeIn('fast'); + }); + }; + } + + function UhrRendererV2Delegate(layout) { + function parseArrayOrObject(letters, styleClass, input) { + if (typeof input !== 'undefined' && input !== null) { + if (Array.isArray(input)) { + input.forEach(function (item) { + parseObject(letters, styleClass, item); + }); + } else { + parseObject(letters, styleClass, input); + } + } + } + + function parseObject(letters, styleClass, object) { + if (typeof object !== 'undefined' && object !== null) { + Object.keys(object).forEach(function (y) { + var highlightLetters = object[y]; + highlightLetters.forEach(function (x) { + letters[y - 1][x - 1].addStyle(styleClass); + }); + }); + } + } + + function parseTimeDefinition(letters, styleClass, definition) { + if (typeof definition !== 'undefined' && definition !== null) { + Object.keys(definition).forEach(function (listString) { + var array = listString.split(','); + var highlightLetters = definition[listString]; + array.forEach(function (item) { + parseArrayOrObject(letters, styleClass + item, highlightLetters); + }); + }); + } + } + + this.parse = function parse() { + var letters = []; + layout.letters.forEach(function (string) { + var line = []; + for (var c = 0; c < string.length; c++) { + var character = new Letter(string[c]); + line.push(character); + } + letters.push(line); + }); + parseArrayOrObject(letters, 'on', layout.permanent); + parseTimeDefinition(letters, 'second', layout.seconds); + parseTimeDefinition(letters, 'minute', layout.minutes); + parseTimeDefinition(letters, 'hour', layout.hours); + return letters; + }; + } + + /** + * Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays. + * @param value Der Buchstabe, der Dargestellt werden soll. + * @param style Die CSS-Styleklassen des Buchstabens. + */ + function Letter(value, style) { + var myValue = value; + var myStyle = style || ''; + this.addStyle = function (style) { + if (myStyle === '') { + myStyle = style; + } else { + myStyle += ' ' + style; + } + }; + this.toString = function () { + return '' + myValue + ''; + }; + } })(jQuery); \ No newline at end of file From fcfdaaa2cd3df308ecaddf44a88949a8566c988b Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Tue, 12 Aug 2014 11:55:34 +0200 Subject: [PATCH 10/12] fade controls in and out --- js/uhr.js | 970 +++++++++++++++++++++++++++--------------------------- 1 file changed, 485 insertions(+), 485 deletions(-) diff --git a/js/uhr.js b/js/uhr.js index 413f57b..0e85f0b 100644 --- a/js/uhr.js +++ b/js/uhr.js @@ -1,485 +1,485 @@ -/* - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ -(function ($) { - 'use strict'; - var uhrGlobals = { - "id": 0, - "languages": [], - "themes": [], - registerLanguage: function registerLanguage(code, language) { - var alreadyExists = uhrGlobals.languages.some(function (element) { - if (code === element.code) { - console.error("Error: Language code '" + code + "' cannot be registered for language '" + language.language + "' because it is already registered for language '" + element.language + "'!"); - return true; - } - return false; - }); - if (!alreadyExists) { - language.code = code; - uhrGlobals.languages.push(language); - } - } - }; - - // auto-detect themes - $('link[rel=stylesheet]').each(function (index, item) { - var styleSheet = $(item); - var styleClass = styleSheet.attr('data-class'); - if (styleClass !== undefined) { - var name = styleSheet.attr('data-name'); - if (name === undefined) { - name = styleClass; - } - uhrGlobals.themes.push({'styleClass': styleClass, 'name': name}); - } - }); - // fall-back if no theme was included - if (uhrGlobals.themes.length === 0) { - uhrGlobals.themes.push({}); - } - - // public interface methods (exported later) - var start = function start() { - if (!isOn.bind(this)()) { - this.timer = window.setInterval(function () { - this.options.time = new Date(); - update.bind(this)(); - }.bind(this), 1000); - update.bind(this)(); - setCookie.bind(this)('uhr-status', 'on'); - } - }; - var stop = function stop() { - if (isOn.bind(this)()) { - window.clearInterval(this.timer); - this.timer = null; - update.bind(this)(); - setCookie.bind(this)('uhr-status', 'off'); - } - }; - var toggle = function toggle() { - if (isOn.bind(this)()) { - this.stop(); - } else { - this.start(); - } - }; - var setLanguage = function setLanugage(languageKey) { - if (languageKey !== this.options.language) { - this.options.language = languageKey; - var renderer = new UhrRenderer(language.bind(this)(), this.element.find('.letterarea')); - renderer.render.bind(this)(function () { - this.currentMinute = -1; - update.bind(this)(); - }.bind(this)); - setCookie.bind(this)('uhr-language', languageKey); - update.bind(this)(); - } - }; - var setTheme = function setTheme(theme) { - if (theme !== this.options.theme) { - this.element.removeClass(this.options.theme).addClass(theme); - $('#uhr-onoffswitch' + this.id).removeClass(this.options.theme).addClass(theme); - this.options.theme = theme; - setCookie.bind(this)('uhr-theme', theme); - } - }; - var setTime = function setTime(time) { - this.currentMinute = -1; - if (time === null) { - this.options.time = new Date(); - } else { - if (this.timer !== null) { - window.clearInterval(this.timer); - } - this.options.time = time; - } - update.bind(this)(); - }; - var setWidth = function setWidth(width) { - var e = this.element; - e.css('width', width); - var realWidth = e.width(); - e.width(realWidth); - e.height(realWidth); - e.css('font-size', (realWidth / 40) + 'px'); - }; - - // private interface methods - var create = function create() { - this.id = uhrGlobals.id++; - this.timer = null; - this.currentMinute = -1; - var userTime = this.options.time; - if (this.options.time === undefined) { - this.options.time = new Date(); - } - setupHTML.bind(this)(); - wireFunctionality.bind(this)(); - if (userTime !== undefined) { - this.time(userTime); - } - }; - // private helper methods (not exported) - var showConfigScreen = function showConfigScreen() { - $('#uhr-controlpanel' + this.id).show(); - }; - // set up - var setupHTML = function setupHTML() { - var e = this.element; - // Base clock area - e.addClass('uhr'); - e.empty(); - e.append(''); - e.append(''); - e.append(''); - e.append(''); - e.append('
'); - e.append('
'); - setWidth.bind(this)(this.options.width); - - if (this.options.controls) { - var configlink = $(''); - configlink.on('click', function () { - showConfigScreen.bind(this)(); - }.bind(this)); - e.after(configlink); - var controlpanel = $('
'); - var content = $('
'); - controlpanel.append(content); - // on/off switch - var toggleSwitch = $('
'); - toggleSwitch.append(''); - toggleSwitch.append(''); - content.append(toggleSwitch); - - // language chooser - if (uhrGlobals.languages.length > 1) { - var languageChooser = $(''); - uhrGlobals.languages.forEach(function (item) { - languageChooser.append(''); - }); - content.append(languageChooser); - } - - // theme chooser - if (uhrGlobals.themes.length > 1) { - var themeChooser = $(''); - uhrGlobals.themes.forEach(function (item) { - themeChooser.append(''); - }); - content.append(themeChooser); - } - var closebutton = $(''); - closebutton.on('click', function () { - $('#uhr-controlpanel' + this.id).hide(); - }.bind(this)); - content.append(closebutton); - e.after(controlpanel); - controlpanel.hide(); - } - }; - var wireFunctionality = function wireFunctionality() { - // on/off switch - var toggleSwitch = $('#uhr-onoffswitch-checkbox' + this.id); - toggleSwitch.on('click', function () { - this.toggle(); - }.bind(this)); - var status = $.cookie('uhr-status' + this.id); - if (status === undefined || this.options.force) { - status = this.options.status; - } - toggleSwitch.prop('checked', status === 'on'); - if (status === 'on') { - this.start(); - } else { - this.stop(); - } - - // language chooser - var languageChooser = $('#uhr-languagechooser' + this.id); - languageChooser.on('change', function () { - var languageKey = $('#uhr-languagechooser' + this.id).val(); - this.language(languageKey); - }.bind(this)); - var selectedLanguage = $.cookie('uhr-language' + this.id); - if (selectedLanguage === undefined || this.options.force) { - selectedLanguage = this.options.language; - } - var found = uhrGlobals.languages.some(function (item) { - return selectedLanguage === item.code; - }); - if (!found) { - var fallbackLanguage; - if (uhrGlobals.languages.length > 0) { - fallbackLanguage = uhrGlobals.languages[0].code; - } else { - fallbackLanguage = ''; - } - console.warn("Language '" + selectedLanguage + "' not found! Using fallback '" + fallbackLanguage + "'"); - selectedLanguage = fallbackLanguage; - } - languageChooser.val(selectedLanguage); - this.options.language = ""; - this.language(selectedLanguage); - - // theme chooser - var themeChooser = $('#uhr-themechooser' + this.id); - themeChooser.on('change', function () { - var themeKey = $('#uhr-themechooser' + this.id).val(); - this.theme(themeKey); - }.bind(this)); - var selectedTheme = $.cookie('uhr-theme' + this.id); - if (selectedTheme === undefined || this.options.force) { - selectedTheme = this.options.theme; - } - found = uhrGlobals.themes.some(function (item) { - return selectedTheme === item.styleClass; - }); - if (!found) { - var fallbackTheme = uhrGlobals.themes[0].styleClass; - console.warn("Theme '" + selectedTheme + "' not found! Using fallback '" + fallbackTheme + "'"); - selectedTheme = fallbackTheme; - } - themeChooser.val(selectedTheme); - this.options.theme = ""; - this.theme(selectedTheme); - }; - var setCookie = function setCookie(cookieName, cookieValue) { - var options = {}; - if (this.options.cookiePath !== undefined) { - options = {expires: 365, path: this.options.cookiePath}; - } else { - options = {expires: 365}; - } - $.cookie(cookieName + this.id, cookieValue, options); - }; - - // business logic - var isOn = function isOn() { - return this.timer !== null; - }; - var update = function update() { - if (isOn.bind(this)()) { - var time = this.options.time; - if (!language.bind(this)().hasOwnProperty('seconds')) { - if (time.getMinutes() === this.currentMinute) { - return; - } - this.currentMinute = time.getMinutes(); - } - show.bind(this)(time); - } else { - clear.bind(this)(); - this.currentMinute = -1; - } - }; - var show = function show(time) { - var second = getSecond.bind(this)(time); - var dotMinute = getDotMinute.bind(this)(time); - var hour = getHour.bind(this)(time); - var coarseMinute = getCoarseMinute.bind(this)(time); - clear.bind(this)(); - highlight.bind(this)('on'); - for (var i = 1; i <= dotMinute; i++) { - highlight.bind(this)('dot' + i); - } - highlight.bind(this)('second' + second); - highlight.bind(this)('minute' + coarseMinute); - highlight.bind(this)('hour' + hour); - }; - var highlight = function highlight(itemClass) { - this.element.find('.item.' + itemClass).addClass('active'); - }; - var clear = function clear() { - this.element.find('.item').removeClass('active'); - }; - var getSecond = function getSecond(date) { - if (typeof language.bind(this)().getSeconds === 'function') { - return language.bind(this)().getSeconds(date); - } - return date.getSeconds(); - }; - var getDotMinute = function getDotMinute(date) { - if (typeof language.bind(this)().getDotMinute === 'function') { - return language.bind(this)().getDotMinute(date); - } - var minutes = date.getMinutes(); - return minutes % 5; - }; - var getCoarseMinute = function getCoarseMinute(date) { - if (typeof language.bind(this)().getCoarseMinute === 'function') { - return language.bind(this)().getCoarseMinute(date); - } - return date.getMinutes(); - }; - var getHour = function getHour(date) { - if (typeof language.bind(this)().getHour === 'function') { - return language.bind(this)().getHour(date); - } - var hour = date.getHours(); - if (date.getMinutes() >= 25) { - return (hour + 1) % 24; - } - return hour; - }; - - var language = function language() { - var matchingLanguages = uhrGlobals.languages.filter(function (element) { - return (element.code === this.options.language); - }, this); - if (matchingLanguages.length > 0) { - return matchingLanguages[0]; - } - // fallback: return empty object - return {}; - }; - - $.widget("fritteli.uhr", { - "options": { - width: '100%', - status: 'on', - language: 'de_CH', - theme: uhrGlobals.themes[0].styleClass, - force: false, - controls: true, - cookiePath: undefined - }, - "start": start, - "stop": stop, - "toggle": toggle, - "language": setLanguage, - "theme": setTheme, - "time": setTime, - "width": setWidth, - // constructor method - "_create": create - }); - $.fritteli.uhr.register = uhrGlobals.registerLanguage; - /** - * Hilfsklasse zum Rendern der Uhr. - * @param layout Layout-Objekt, das gerendert werden soll. - * @param renderarea Das jQuery-gewrappte HTML-Element, auf dem gerendert werden soll. - */ - function UhrRenderer(layout, renderarea) { - this.render = function render(beforeshow) { - if (layout.parsed === undefined) { - switch (layout.version) { - case 2: - var delegate = new UhrRendererV2Delegate(layout); - var parsedLayout = delegate.parse(); - Object.defineProperty(layout, "parsed", {"value": parsedLayout, "writable": false, "configurable": false}); - break; - default: - console.warn("Unknown layout version: '" + layout.version + "'"); - return; - } - } - var letters = layout.parsed; - renderarea.fadeOut('fast', function () { - renderarea.empty(); - letters.forEach(function (line, index, array) { - line.forEach(function (letter) { - renderarea.append(letter.toString()); - }); - if (index < array.length - 1) { - renderarea.append('
'); - } - }); - if (typeof beforeshow === 'function') { - beforeshow(); - } - renderarea.fadeIn('fast'); - }); - }; - } - - function UhrRendererV2Delegate(layout) { - function parseArrayOrObject(letters, styleClass, input) { - if (typeof input !== 'undefined' && input !== null) { - if (Array.isArray(input)) { - input.forEach(function (item) { - parseObject(letters, styleClass, item); - }); - } else { - parseObject(letters, styleClass, input); - } - } - } - - function parseObject(letters, styleClass, object) { - if (typeof object !== 'undefined' && object !== null) { - Object.keys(object).forEach(function (y) { - var highlightLetters = object[y]; - highlightLetters.forEach(function (x) { - letters[y - 1][x - 1].addStyle(styleClass); - }); - }); - } - } - - function parseTimeDefinition(letters, styleClass, definition) { - if (typeof definition !== 'undefined' && definition !== null) { - Object.keys(definition).forEach(function (listString) { - var array = listString.split(','); - var highlightLetters = definition[listString]; - array.forEach(function (item) { - parseArrayOrObject(letters, styleClass + item, highlightLetters); - }); - }); - } - } - - this.parse = function parse() { - var letters = []; - layout.letters.forEach(function (string) { - var line = []; - for (var c = 0; c < string.length; c++) { - var character = new Letter(string[c]); - line.push(character); - } - letters.push(line); - }); - parseArrayOrObject(letters, 'on', layout.permanent); - parseTimeDefinition(letters, 'second', layout.seconds); - parseTimeDefinition(letters, 'minute', layout.minutes); - parseTimeDefinition(letters, 'hour', layout.hours); - return letters; - }; - } - - /** - * Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays. - * @param value Der Buchstabe, der Dargestellt werden soll. - * @param style Die CSS-Styleklassen des Buchstabens. - */ - function Letter(value, style) { - var myValue = value; - var myStyle = style || ''; - this.addStyle = function (style) { - if (myStyle === '') { - myStyle = style; - } else { - myStyle += ' ' + style; - } - }; - this.toString = function () { - return '' + myValue + ''; - }; - } -})(jQuery); \ No newline at end of file +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +(function ($) { + 'use strict'; + var uhrGlobals = { + "id": 0, + "languages": [], + "themes": [], + registerLanguage: function registerLanguage(code, language) { + var alreadyExists = uhrGlobals.languages.some(function (element) { + if (code === element.code) { + console.error("Error: Language code '" + code + "' cannot be registered for language '" + language.language + "' because it is already registered for language '" + element.language + "'!"); + return true; + } + return false; + }); + if (!alreadyExists) { + language.code = code; + uhrGlobals.languages.push(language); + } + } + }; + + // auto-detect themes + $('link[rel=stylesheet]').each(function (index, item) { + var styleSheet = $(item); + var styleClass = styleSheet.attr('data-class'); + if (styleClass !== undefined) { + var name = styleSheet.attr('data-name'); + if (name === undefined) { + name = styleClass; + } + uhrGlobals.themes.push({'styleClass': styleClass, 'name': name}); + } + }); + // fall-back if no theme was included + if (uhrGlobals.themes.length === 0) { + uhrGlobals.themes.push({}); + } + + // public interface methods (exported later) + var start = function start() { + if (!isOn.bind(this)()) { + this.timer = window.setInterval(function () { + this.options.time = new Date(); + update.bind(this)(); + }.bind(this), 1000); + update.bind(this)(); + setCookie.bind(this)('uhr-status', 'on'); + } + }; + var stop = function stop() { + if (isOn.bind(this)()) { + window.clearInterval(this.timer); + this.timer = null; + update.bind(this)(); + setCookie.bind(this)('uhr-status', 'off'); + } + }; + var toggle = function toggle() { + if (isOn.bind(this)()) { + this.stop(); + } else { + this.start(); + } + }; + var setLanguage = function setLanugage(languageKey) { + if (languageKey !== this.options.language) { + this.options.language = languageKey; + var renderer = new UhrRenderer(language.bind(this)(), this.element.find('.letterarea')); + renderer.render.bind(this)(function () { + this.currentMinute = -1; + update.bind(this)(); + }.bind(this)); + setCookie.bind(this)('uhr-language', languageKey); + update.bind(this)(); + } + }; + var setTheme = function setTheme(theme) { + if (theme !== this.options.theme) { + this.element.removeClass(this.options.theme).addClass(theme); + $('#uhr-onoffswitch' + this.id).removeClass(this.options.theme).addClass(theme); + this.options.theme = theme; + setCookie.bind(this)('uhr-theme', theme); + } + }; + var setTime = function setTime(time) { + this.currentMinute = -1; + if (time === null) { + this.options.time = new Date(); + } else { + if (this.timer !== null) { + window.clearInterval(this.timer); + } + this.options.time = time; + } + update.bind(this)(); + }; + var setWidth = function setWidth(width) { + var e = this.element; + e.css('width', width); + var realWidth = e.width(); + e.width(realWidth); + e.height(realWidth); + e.css('font-size', (realWidth / 40) + 'px'); + }; + + // private interface methods + var create = function create() { + this.id = uhrGlobals.id++; + this.timer = null; + this.currentMinute = -1; + var userTime = this.options.time; + if (this.options.time === undefined) { + this.options.time = new Date(); + } + setupHTML.bind(this)(); + wireFunctionality.bind(this)(); + if (userTime !== undefined) { + this.time(userTime); + } + }; + // private helper methods (not exported) + var showConfigScreen = function showConfigScreen() { + $('#uhr-controlpanel' + this.id).fadeIn('fast'); + }; + // set up + var setupHTML = function setupHTML() { + var e = this.element; + // Base clock area + e.addClass('uhr'); + e.empty(); + e.append(''); + e.append(''); + e.append(''); + e.append(''); + e.append('
'); + e.append('
'); + setWidth.bind(this)(this.options.width); + + if (this.options.controls) { + var configlink = $(''); + configlink.on('click', function () { + showConfigScreen.bind(this)(); + }.bind(this)); + e.after(configlink); + var controlpanel = $('
'); + var content = $('
'); + controlpanel.append(content); + // on/off switch + var toggleSwitch = $('
'); + toggleSwitch.append(''); + toggleSwitch.append(''); + content.append(toggleSwitch); + + // language chooser + if (uhrGlobals.languages.length > 1) { + var languageChooser = $(''); + uhrGlobals.languages.forEach(function (item) { + languageChooser.append(''); + }); + content.append(languageChooser); + } + + // theme chooser + if (uhrGlobals.themes.length > 1) { + var themeChooser = $(''); + uhrGlobals.themes.forEach(function (item) { + themeChooser.append(''); + }); + content.append(themeChooser); + } + var closebutton = $(''); + closebutton.on('click', function () { + $('#uhr-controlpanel' + this.id).fadeOut('fast'); + }.bind(this)); + content.append(closebutton); + e.after(controlpanel); + controlpanel.hide(); + } + }; + var wireFunctionality = function wireFunctionality() { + // on/off switch + var toggleSwitch = $('#uhr-onoffswitch-checkbox' + this.id); + toggleSwitch.on('click', function () { + this.toggle(); + }.bind(this)); + var status = $.cookie('uhr-status' + this.id); + if (status === undefined || this.options.force) { + status = this.options.status; + } + toggleSwitch.prop('checked', status === 'on'); + if (status === 'on') { + this.start(); + } else { + this.stop(); + } + + // language chooser + var languageChooser = $('#uhr-languagechooser' + this.id); + languageChooser.on('change', function () { + var languageKey = $('#uhr-languagechooser' + this.id).val(); + this.language(languageKey); + }.bind(this)); + var selectedLanguage = $.cookie('uhr-language' + this.id); + if (selectedLanguage === undefined || this.options.force) { + selectedLanguage = this.options.language; + } + var found = uhrGlobals.languages.some(function (item) { + return selectedLanguage === item.code; + }); + if (!found) { + var fallbackLanguage; + if (uhrGlobals.languages.length > 0) { + fallbackLanguage = uhrGlobals.languages[0].code; + } else { + fallbackLanguage = ''; + } + console.warn("Language '" + selectedLanguage + "' not found! Using fallback '" + fallbackLanguage + "'"); + selectedLanguage = fallbackLanguage; + } + languageChooser.val(selectedLanguage); + this.options.language = ""; + this.language(selectedLanguage); + + // theme chooser + var themeChooser = $('#uhr-themechooser' + this.id); + themeChooser.on('change', function () { + var themeKey = $('#uhr-themechooser' + this.id).val(); + this.theme(themeKey); + }.bind(this)); + var selectedTheme = $.cookie('uhr-theme' + this.id); + if (selectedTheme === undefined || this.options.force) { + selectedTheme = this.options.theme; + } + found = uhrGlobals.themes.some(function (item) { + return selectedTheme === item.styleClass; + }); + if (!found) { + var fallbackTheme = uhrGlobals.themes[0].styleClass; + console.warn("Theme '" + selectedTheme + "' not found! Using fallback '" + fallbackTheme + "'"); + selectedTheme = fallbackTheme; + } + themeChooser.val(selectedTheme); + this.options.theme = ""; + this.theme(selectedTheme); + }; + var setCookie = function setCookie(cookieName, cookieValue) { + var options = {}; + if (this.options.cookiePath !== undefined) { + options = {expires: 365, path: this.options.cookiePath}; + } else { + options = {expires: 365}; + } + $.cookie(cookieName + this.id, cookieValue, options); + }; + + // business logic + var isOn = function isOn() { + return this.timer !== null; + }; + var update = function update() { + if (isOn.bind(this)()) { + var time = this.options.time; + if (!language.bind(this)().hasOwnProperty('seconds')) { + if (time.getMinutes() === this.currentMinute) { + return; + } + this.currentMinute = time.getMinutes(); + } + show.bind(this)(time); + } else { + clear.bind(this)(); + this.currentMinute = -1; + } + }; + var show = function show(time) { + var second = getSecond.bind(this)(time); + var dotMinute = getDotMinute.bind(this)(time); + var hour = getHour.bind(this)(time); + var coarseMinute = getCoarseMinute.bind(this)(time); + clear.bind(this)(); + highlight.bind(this)('on'); + for (var i = 1; i <= dotMinute; i++) { + highlight.bind(this)('dot' + i); + } + highlight.bind(this)('second' + second); + highlight.bind(this)('minute' + coarseMinute); + highlight.bind(this)('hour' + hour); + }; + var highlight = function highlight(itemClass) { + this.element.find('.item.' + itemClass).addClass('active'); + }; + var clear = function clear() { + this.element.find('.item').removeClass('active'); + }; + var getSecond = function getSecond(date) { + if (typeof language.bind(this)().getSeconds === 'function') { + return language.bind(this)().getSeconds(date); + } + return date.getSeconds(); + }; + var getDotMinute = function getDotMinute(date) { + if (typeof language.bind(this)().getDotMinute === 'function') { + return language.bind(this)().getDotMinute(date); + } + var minutes = date.getMinutes(); + return minutes % 5; + }; + var getCoarseMinute = function getCoarseMinute(date) { + if (typeof language.bind(this)().getCoarseMinute === 'function') { + return language.bind(this)().getCoarseMinute(date); + } + return date.getMinutes(); + }; + var getHour = function getHour(date) { + if (typeof language.bind(this)().getHour === 'function') { + return language.bind(this)().getHour(date); + } + var hour = date.getHours(); + if (date.getMinutes() >= 25) { + return (hour + 1) % 24; + } + return hour; + }; + + var language = function language() { + var matchingLanguages = uhrGlobals.languages.filter(function (element) { + return (element.code === this.options.language); + }, this); + if (matchingLanguages.length > 0) { + return matchingLanguages[0]; + } + // fallback: return empty object + return {}; + }; + + $.widget("fritteli.uhr", { + "options": { + width: '100%', + status: 'on', + language: 'de_CH', + theme: uhrGlobals.themes[0].styleClass, + force: false, + controls: true, + cookiePath: undefined + }, + "start": start, + "stop": stop, + "toggle": toggle, + "language": setLanguage, + "theme": setTheme, + "time": setTime, + "width": setWidth, + // constructor method + "_create": create + }); + $.fritteli.uhr.register = uhrGlobals.registerLanguage; + /** + * Hilfsklasse zum Rendern der Uhr. + * @param layout Layout-Objekt, das gerendert werden soll. + * @param renderarea Das jQuery-gewrappte HTML-Element, auf dem gerendert werden soll. + */ + function UhrRenderer(layout, renderarea) { + this.render = function render(beforeshow) { + if (layout.parsed === undefined) { + switch (layout.version) { + case 2: + var delegate = new UhrRendererV2Delegate(layout); + var parsedLayout = delegate.parse(); + Object.defineProperty(layout, "parsed", {"value": parsedLayout, "writable": false, "configurable": false}); + break; + default: + console.warn("Unknown layout version: '" + layout.version + "'"); + return; + } + } + var letters = layout.parsed; + renderarea.fadeOut('fast', function () { + renderarea.empty(); + letters.forEach(function (line, index, array) { + line.forEach(function (letter) { + renderarea.append(letter.toString()); + }); + if (index < array.length - 1) { + renderarea.append('
'); + } + }); + if (typeof beforeshow === 'function') { + beforeshow(); + } + renderarea.fadeIn('fast'); + }); + }; + } + + function UhrRendererV2Delegate(layout) { + function parseArrayOrObject(letters, styleClass, input) { + if (typeof input !== 'undefined' && input !== null) { + if (Array.isArray(input)) { + input.forEach(function (item) { + parseObject(letters, styleClass, item); + }); + } else { + parseObject(letters, styleClass, input); + } + } + } + + function parseObject(letters, styleClass, object) { + if (typeof object !== 'undefined' && object !== null) { + Object.keys(object).forEach(function (y) { + var highlightLetters = object[y]; + highlightLetters.forEach(function (x) { + letters[y - 1][x - 1].addStyle(styleClass); + }); + }); + } + } + + function parseTimeDefinition(letters, styleClass, definition) { + if (typeof definition !== 'undefined' && definition !== null) { + Object.keys(definition).forEach(function (listString) { + var array = listString.split(','); + var highlightLetters = definition[listString]; + array.forEach(function (item) { + parseArrayOrObject(letters, styleClass + item, highlightLetters); + }); + }); + } + } + + this.parse = function parse() { + var letters = []; + layout.letters.forEach(function (string) { + var line = []; + for (var c = 0; c < string.length; c++) { + var character = new Letter(string[c]); + line.push(character); + } + letters.push(line); + }); + parseArrayOrObject(letters, 'on', layout.permanent); + parseTimeDefinition(letters, 'second', layout.seconds); + parseTimeDefinition(letters, 'minute', layout.minutes); + parseTimeDefinition(letters, 'hour', layout.hours); + return letters; + }; + } + + /** + * Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays. + * @param value Der Buchstabe, der Dargestellt werden soll. + * @param style Die CSS-Styleklassen des Buchstabens. + */ + function Letter(value, style) { + var myValue = value; + var myStyle = style || ''; + this.addStyle = function (style) { + if (myStyle === '') { + myStyle = style; + } else { + myStyle += ' ' + style; + } + }; + this.toString = function () { + return '' + myValue + ''; + }; + } +})(jQuery); From be1e1cf89b486572a852a457ab6eb931a1a4e875 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Tue, 12 Aug 2014 11:59:06 +0200 Subject: [PATCH 11/12] fixed line-endings in .gitignore --- .gitignore | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 38adccb..fbb44f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -*~ -.idea -*.iml -atlassian-ide-plugin.xml +*~ +.idea +*.iml +atlassian-ide-plugin.xml From 3f6a315208dd4282fb36c81a1dcf692141144d39 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Tue, 12 Aug 2014 18:20:45 +0200 Subject: [PATCH 12/12] tried to add newline let's see what happens --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fbb44f0..07be4ff 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .idea *.iml atlassian-ide-plugin.xml +