From d7c461f39ae96647c0797fd6d123c39e05336002 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Wed, 25 Jun 2014 12:52:32 +0200 Subject: [PATCH 01/34] added new layout and first handling of it in the parser --- uhr-de_CH.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ uhr.js | 28 ++++++++++++++++++++++---- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/uhr-de_CH.js b/uhr-de_CH.js index 874ae1c..5dc89d1 100644 --- a/uhr-de_CH.js +++ b/uhr-de_CH.js @@ -28,3 +28,59 @@ var layout = { ] }; window._uhr.languages['de_CH'] = layout; +var newLayout = { + version: 2, + _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]}, + language: 'Bärndütsch (nöi)', + letters: [ + 'ESKISCHAFÜF', + 'VIERTUBFZÄÄ', + 'ZWÄNZGGENAU', + 'VORABOHAUBI', + 'EISZWÖISFRÜ', + 'VIERIFÜFIQT', + 'SÄCHSISIBNI', + 'ACHTINÜNIEL', + 'ZÄNIERBEUFI', + 'ZWÜUFINAUHR' + ], + permanent: this._es_isch, + minutes: { + 0: this._genau, + 1: {}, + 5: [this._5, this._ab], + 10: [this._10, this._ab], + 15: [this._15, this._ab], + 20: [this._20, this._ab], + 25: [this._5, this._vor, this._haubi], + 30: [this._haubi], + 35: [this._5, this._ab, this._haubi], + 40: [this._20, this._vor], + 45: [this._15, this._vor], + 50: [this._10, this._vor], + 55: [this._5, this._vor] + }, + hours: { + 0: {10:[1,2,3,4,5,6]}, + 1: {5:[1,2,3]}, + 2: {5:[4,5,6,7]}, + 3: {5:[9,10,11]}, + 4: {6:[1,2,3,4,5]}, + 5: {6:[6,7,8,9]}, + 6: {7:[1,2,3,4,5,6]}, + 7: {7:[7,8,9,10,11]}, + 8: {8:[1,2,3,4,5]}, + 9: {8:[6,7,8,9]}, + 10: {9:[1,2,3,4]}, + 11: {9:[8,9,10,11]} + } +}; +window._uhr.languages['de_CH2'] = newLayout; diff --git a/uhr.js b/uhr.js index 74f0213..33ebe98 100644 --- a/uhr.js +++ b/uhr.js @@ -286,17 +286,37 @@ along with this program. If not, see . function UhrRenderer(layout, renderarea) { this.layout = layout; this.renderarea = renderarea; + this._parseLayoutV2 = function() { + console.log("attempting to parse layout v2"); + var letters = [['a'], ['b', 'c',]]; + return letters; + } } UhrRenderer.prototype.render = function(uhr, beforeshow) { var renderer = this; + var letters; + if (this.layout.version !== undefined) { + switch (this.layout.version) { + case 2: + letters = this._parseLayoutV2(); + break; + default: + if (console !== undefined && typeof console.log == 'function') { + console.log("Unknown layout version: " + this.layout.version); + } + return; + } + } else { + letters = renderer.layout.values; + } this.renderarea.fadeOut('fast', function() { renderer.renderarea.empty(); - for (var y = 0; y < renderer.layout.values.length; y++) { - for (var x = 0; x < renderer.layout.values[y].length; x++) { - var letter = renderer.layout.values[y][x]; + 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 < renderer.layout.values.length - 1) { + if (y < letters.length - 1) { renderer.renderarea.append('
'); } } From b4f2a466b727ce773c5b8eacaa997ba4d818e9e4 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Wed, 25 Jun 2014 13:12:58 +0200 Subject: [PATCH 02/34] some debug output --- uhr.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/uhr.js b/uhr.js index 33ebe98..703b0af 100644 --- a/uhr.js +++ b/uhr.js @@ -286,9 +286,18 @@ along with this program. If not, see . function UhrRenderer(layout, renderarea) { this.layout = layout; this.renderarea = renderarea; + this._debug = true; this._parseLayoutV2 = function() { - console.log("attempting to parse layout v2"); - var letters = [['a'], ['b', 'c',]]; + if (this._debug) console.log("attempting to parse layout v2"); + var letters = []; + console.log("lett:"+typeof this.layout.letters); + console.log(this.layout.letters); + console.log("perm:"+typeof this.layout.permanent); + console.log(this.layout.permanent); + console.log("mins:"+typeof this.layout.minutes); + console.log(this.layout.minutes); + console.log("hour:"+typeof this.layout.hours); + console.log(this.layout.hours); return letters; } } From 0d90b3dd76511061b3d91f6c76d6a0cb4c12c77e Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 08:00:15 +0200 Subject: [PATCH 03/34] moved testing stuff to ownfiles. --- uhr-de_CH.js | 60 ++-------------------------------------- uhr-de_CH_TEST.js | 21 ++++++++++++++ uhr-de_CH_new.js | 70 +++++++++++++++++++++++++++++++++++++++++++++++ uhr.js | 12 ++------ 4 files changed, 95 insertions(+), 68 deletions(-) create mode 100644 uhr-de_CH_TEST.js create mode 100644 uhr-de_CH_new.js diff --git a/uhr-de_CH.js b/uhr-de_CH.js index 5dc89d1..5e6cedb 100644 --- a/uhr-de_CH.js +++ b/uhr-de_CH.js @@ -13,8 +13,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ var layout = { - language: 'Bärndütsch', - values: [ + "language": 'Bärndütsch', + "values": [ [l('E', 'on'), l('S', 'on'),l('K'),l('I', 'on'),l('S', 'on'),l('C', 'on'),l('H', 'on'),l('A'),m('F', 5, 25, 35, 55),m('Ü', 5, 25, 35, 55),m('F', 5, 25, 35, 55)], [m('V', 15, 45), m('I', 15, 45),m('E', 15, 45),m('R', 15, 45),m('T', 15, 45),m('U', 15, 45),l('B'),l('F'),m('Z', 10, 50),m('Ä', 10, 50),m('Ä', 10, 50)], [m('Z', 20, 40), m('W', 20, 40),m('Ä', 20, 40),m('N', 20, 40),m('Z', 20, 40),m('G', 20, 40),l('S'),l('I'),m('V', 25, 40, 45, 50, 55),m('O', 25, 40, 45, 50, 55),m('R', 25, 40, 45, 50, 55)], @@ -28,59 +28,3 @@ var layout = { ] }; window._uhr.languages['de_CH'] = layout; -var newLayout = { - version: 2, - _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]}, - language: 'Bärndütsch (nöi)', - letters: [ - 'ESKISCHAFÜF', - 'VIERTUBFZÄÄ', - 'ZWÄNZGGENAU', - 'VORABOHAUBI', - 'EISZWÖISFRÜ', - 'VIERIFÜFIQT', - 'SÄCHSISIBNI', - 'ACHTINÜNIEL', - 'ZÄNIERBEUFI', - 'ZWÜUFINAUHR' - ], - permanent: this._es_isch, - minutes: { - 0: this._genau, - 1: {}, - 5: [this._5, this._ab], - 10: [this._10, this._ab], - 15: [this._15, this._ab], - 20: [this._20, this._ab], - 25: [this._5, this._vor, this._haubi], - 30: [this._haubi], - 35: [this._5, this._ab, this._haubi], - 40: [this._20, this._vor], - 45: [this._15, this._vor], - 50: [this._10, this._vor], - 55: [this._5, this._vor] - }, - hours: { - 0: {10:[1,2,3,4,5,6]}, - 1: {5:[1,2,3]}, - 2: {5:[4,5,6,7]}, - 3: {5:[9,10,11]}, - 4: {6:[1,2,3,4,5]}, - 5: {6:[6,7,8,9]}, - 6: {7:[1,2,3,4,5,6]}, - 7: {7:[7,8,9,10,11]}, - 8: {8:[1,2,3,4,5]}, - 9: {8:[6,7,8,9]}, - 10: {9:[1,2,3,4]}, - 11: {9:[8,9,10,11]} - } -}; -window._uhr.languages['de_CH2'] = newLayout; diff --git a/uhr-de_CH_TEST.js b/uhr-de_CH_TEST.js new file mode 100644 index 0000000..b48f260 --- /dev/null +++ b/uhr-de_CH_TEST.js @@ -0,0 +1,21 @@ +/* +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 layout = { + "version": 2, + "helper": {1:[1,2,4,5,6,7]}, + "language": 'Bärndütsch (test)', + "permanent": this.helper, +}; +window._uhr.languages['de_CH_TEST'] = layout; diff --git a/uhr-de_CH_new.js b/uhr-de_CH_new.js new file mode 100644 index 0000000..5ca9dda --- /dev/null +++ b/uhr-de_CH_new.js @@ -0,0 +1,70 @@ +/* +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 layout = { + "version": 2, + "_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]}, + "language": 'Bärndütsch (nöi)', + "letters": [ + 'ESKISCHAFÜF', + 'VIERTUBFZÄÄ', + 'ZWÄNZGGENAU', + 'VORABOHAUBI', + 'EISZWÖISFRÜ', + 'VIERIFÜFIQT', + 'SÄCHSISIBNI', + 'ACHTINÜNIEL', + 'ZÄNIERBEUFI', + 'ZWÜUFINAUHR' + ], + "permanent": this._es_isch, + "minutes": { + "0": this._genau, + "1": {}, + "5": [this._5, this._ab], + "10": [this._10, this._ab], + "15": [this._15, this._ab], + "20": [this._20, this._ab], + "25": [this._5, this._vor, this._haubi], + "30": [this._haubi], + "35": [this._5, this._ab, this._haubi], + "40": [this._20, this._vor], + "45": [this._15, this._vor], + "50": [this._10, this._vor], + "55": [this._5, this._vor] + }, + "hours": { + "0": {10:[1,2,3,4,5,6]}, + "1": {5:[1,2,3]}, + "2": {5:[4,5,6,7]}, + "3": {5:[9,10,11]}, + "4": {6:[1,2,3,4,5]}, + "5": {6:[6,7,8,9]}, + "6": {7:[1,2,3,4,5,6]}, + "7": {7:[7,8,9,10,11]}, + "8": {8:[1,2,3,4,5]}, + "9": {8:[6,7,8,9]}, + "10": {9:[1,2,3,4]}, + "11": {9:[8,9,10,11]} + } +}; +window._uhr.languages['de_CH_new'] = layout; diff --git a/uhr.js b/uhr.js index 703b0af..f7efbba 100644 --- a/uhr.js +++ b/uhr.js @@ -286,18 +286,10 @@ along with this program. If not, see . function UhrRenderer(layout, renderarea) { this.layout = layout; this.renderarea = renderarea; - this._debug = true; this._parseLayoutV2 = function() { - if (this._debug) console.log("attempting to parse layout v2"); + console.log("attempting to parse layout v2"); var letters = []; - console.log("lett:"+typeof this.layout.letters); - console.log(this.layout.letters); - console.log("perm:"+typeof this.layout.permanent); - console.log(this.layout.permanent); - console.log("mins:"+typeof this.layout.minutes); - console.log(this.layout.minutes); - console.log("hour:"+typeof this.layout.hours); - console.log(this.layout.hours); + console.log(this.layout); return letters; } } From 10c07a05cfc22b47ae633bc2d2361628748a23be Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 08:08:06 +0200 Subject: [PATCH 04/34] using a helper object works, as object properties cannot be accesses before the object has been initialized. --- uhr-de_CH_TEST.js | 7 +++++-- uhr-de_CH_new.js | 32 +++++++++++++++++--------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/uhr-de_CH_TEST.js b/uhr-de_CH_TEST.js index b48f260..df62791 100644 --- a/uhr-de_CH_TEST.js +++ b/uhr-de_CH_TEST.js @@ -12,10 +12,13 @@ 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 helper = { + "es_isch": {1:[1,2,4,5,6,7]} +}; var layout = { "version": 2, - "helper": {1:[1,2,4,5,6,7]}, "language": 'Bärndütsch (test)', - "permanent": this.helper, + "permanent": helper.es_isch, }; +helper = undefined; window._uhr.languages['de_CH_TEST'] = layout; diff --git a/uhr-de_CH_new.js b/uhr-de_CH_new.js index 5ca9dda..d78869c 100644 --- a/uhr-de_CH_new.js +++ b/uhr-de_CH_new.js @@ -12,8 +12,7 @@ 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 layout = { - "version": 2, +var h = { "_es_isch": {1:[1,2,4,5,6,7]}, "_genau": {3:[7,8,9,10,11]}, "_ab": {4:[4,5]}, @@ -23,6 +22,9 @@ var layout = { "_10": {2:[9,10,11]}, "_15": {2:[1,2,3,4,5,6]}, "_20": {3:[1,2,3,4,5,6]}, +}; +var layout = { + "version": 2, "language": 'Bärndütsch (nöi)', "letters": [ 'ESKISCHAFÜF', @@ -36,21 +38,21 @@ var layout = { 'ZÄNIERBEUFI', 'ZWÜUFINAUHR' ], - "permanent": this._es_isch, + "permanent": h._es_isch, "minutes": { - "0": this._genau, + "0": h._genau, "1": {}, - "5": [this._5, this._ab], - "10": [this._10, this._ab], - "15": [this._15, this._ab], - "20": [this._20, this._ab], - "25": [this._5, this._vor, this._haubi], - "30": [this._haubi], - "35": [this._5, this._ab, this._haubi], - "40": [this._20, this._vor], - "45": [this._15, this._vor], - "50": [this._10, this._vor], - "55": [this._5, this._vor] + "5": [h._5, h._ab], + "10": [h._10, h._ab], + "15": [h._15, h._ab], + "20": [h._20, h._ab], + "25": [h._5, h._vor, h._haubi], + "30": [h._haubi], + "35": [h._5, h._ab, h._haubi], + "40": [h._20, h._vor], + "45": [h._15, h._vor], + "50": [h._10, h._vor], + "55": [h._5, h._vor] }, "hours": { "0": {10:[1,2,3,4,5,6]}, From 9a1160f66ec3ab6ffe73dced85a5a5a559b62a77 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 10:43:15 +0200 Subject: [PATCH 05/34] deletes _TEST-file, working with the _new-file from now on. --- uhr-de_CH_TEST.js | 24 ------------------------ uhr-de_CH_new.js | 2 +- 2 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 uhr-de_CH_TEST.js diff --git a/uhr-de_CH_TEST.js b/uhr-de_CH_TEST.js deleted file mode 100644 index df62791..0000000 --- a/uhr-de_CH_TEST.js +++ /dev/null @@ -1,24 +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 . -*/ -var helper = { - "es_isch": {1:[1,2,4,5,6,7]} -}; -var layout = { - "version": 2, - "language": 'Bärndütsch (test)', - "permanent": helper.es_isch, -}; -helper = undefined; -window._uhr.languages['de_CH_TEST'] = layout; diff --git a/uhr-de_CH_new.js b/uhr-de_CH_new.js index d78869c..c269d47 100644 --- a/uhr-de_CH_new.js +++ b/uhr-de_CH_new.js @@ -21,7 +21,7 @@ var h = { "_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]}, + "_20": {3:[1,2,3,4,5,6]} }; var layout = { "version": 2, From eff9700864b57ed600449fae3b617a1516e4f5f1 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 13:46:10 +0200 Subject: [PATCH 06/34] first working version with some bugfixes! refactoring ensues ... --- uhr-de_CH_new.js | 6 ++--- uhr.js | 66 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/uhr-de_CH_new.js b/uhr-de_CH_new.js index c269d47..5cabe64 100644 --- a/uhr-de_CH_new.js +++ b/uhr-de_CH_new.js @@ -36,7 +36,7 @@ var layout = { 'SÄCHSISIBNI', 'ACHTINÜNIEL', 'ZÄNIERBEUFI', - 'ZWÜUFINAUHR' + 'ZWÖUFINAUHR' ], "permanent": h._es_isch, "minutes": { @@ -55,7 +55,6 @@ var layout = { "55": [h._5, h._vor] }, "hours": { - "0": {10:[1,2,3,4,5,6]}, "1": {5:[1,2,3]}, "2": {5:[4,5,6,7]}, "3": {5:[9,10,11]}, @@ -66,7 +65,8 @@ var layout = { "8": {8:[1,2,3,4,5]}, "9": {8:[6,7,8,9]}, "10": {9:[1,2,3,4]}, - "11": {9:[8,9,10,11]} + "11": {9:[8,9,10,11]}, + "12": {10:[1,2,3,4,5,6]} } }; window._uhr.languages['de_CH_new'] = layout; diff --git a/uhr.js b/uhr.js index f7efbba..1e0bb84 100644 --- a/uhr.js +++ b/uhr.js @@ -287,11 +287,63 @@ function UhrRenderer(layout, renderarea) { this.layout = layout; this.renderarea = renderarea; this._parseLayoutV2 = function() { - console.log("attempting to parse layout v2"); var letters = []; - console.log(this.layout); + 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); + } + var permanent = this.layout.permanent; + if (Array.isArray(permanent)) { + for (var i = 0; i < permanent.length; i++) { + this._parseObject(letters, 'on', permanent[i]); + } + } else { + this._parseObject(letters, 'on', permanent); + } + var minutes = this.layout.minutes; + for (minute in minutes) { + if (minutes.hasOwnProperty(minute)) { + var highlightLetters = minutes[minute]; + if (Array.isArray(highlightLetters)) { + for (var i = 0; i < highlightLetters.length; i++) { + this._parseObject(letters, 'minute' + minute, highlightLetters[i]); + } + } else { + this._parseObject(letters, 'minute' + minute, highlightLetters); + } + } + } + var hours = this.layout.hours; + for (hour in hours) { + if (hours.hasOwnProperty(hour)) { + var highlightLetters = hours[hour]; + if (Array.isArray(highlightLetters)) { + for (var i = 0; i < highlightLetters.length; i++) { + this._parseObject(letters, 'hour' + hour, highlightLetters[i]); + } + } else { + this._parseObject(letters, 'hour' + hour, highlightLetters); + } + } + } return letters; } + this._parseObject = function(letters, styleClass, object) { + for (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); + } + } + } + } } UhrRenderer.prototype.render = function(uhr, beforeshow) { var renderer = this; @@ -336,11 +388,19 @@ function Letter(value, style) { this.value = value; this.style = style || ''; this.getStyle = function() { - return 'item letter ' + style; + return 'item letter ' + this.style; }; this.getValue = function() { return value; } + this.addStyle = function(style) { + if (this.style == '') { + this.style = style; + } else { + this.style += ' ' + style; + } + console.log(this.getStyle()); + } } Letter.prototype.toString = function letterToString() { return '' + this.getValue() + ''; From 3e8252fa132910b2c6c6c3dc326f2c2f12bd403a Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 14:07:31 +0200 Subject: [PATCH 07/34] fixed a typo --- uhr-de_CH_new.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uhr-de_CH_new.js b/uhr-de_CH_new.js index 5cabe64..6283f2d 100644 --- a/uhr-de_CH_new.js +++ b/uhr-de_CH_new.js @@ -31,7 +31,7 @@ var layout = { 'VIERTUBFZÄÄ', 'ZWÄNZGGENAU', 'VORABOHAUBI', - 'EISZWÖISFRÜ', + 'EISZWÖISDRÜ', 'VIERIFÜFIQT', 'SÄCHSISIBNI', 'ACHTINÜNIEL', From f9b6acf8b672ebd43b521d6f0af97b944686e5f3 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 14:13:21 +0200 Subject: [PATCH 08/34] improved handling of explicit time()-setting: no re-rendering, just update the time and call _update(). that avoids flashing of the letters. --- uhr.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/uhr.js b/uhr.js index 1e0bb84..75849af 100644 --- a/uhr.js +++ b/uhr.js @@ -30,12 +30,14 @@ along with this program. If not, see . language: 'de_CH', theme: 'black', force: false, - controls: true + controls: true, + time: new Date() }, start: function() { if (!this._isOn()) { var uhr = this; this._timer = window.setInterval(function() { + uhr.options.time = new Date(); uhr._update(); }, 1000); this._update(); @@ -80,21 +82,16 @@ along with this program. If not, see . } }, time: function(time) { - this.options.time = time; if (time == null) { this._currentMinute = -1; - this._update(); + this.options.time = new Date(); } else { if (this._timer != null) { window.clearInterval(this._timer); } - var renderer = new UhrRenderer(this._language(), this.element.find('.letterarea')); - var uhr = this; - renderer.render(this, function() { - uhr._show(time); - }); - + this.options.time = time; } + this._update(); }, // private variables _id: -1, @@ -106,7 +103,7 @@ along with this program. If not, see . }, _update: function() { if (this._isOn()) { - var time = new Date(); + var time = this.options.time; if (time.getMinutes() == this._currentMinute) { return; } @@ -355,7 +352,7 @@ UhrRenderer.prototype.render = function(uhr, beforeshow) { break; default: if (console !== undefined && typeof console.log == 'function') { - console.log("Unknown layout version: " + this.layout.version); + console.error("Unknown layout version: " + this.layout.version); } return; } @@ -399,7 +396,6 @@ function Letter(value, style) { } else { this.style += ' ' + style; } - console.log(this.getStyle()); } } Letter.prototype.toString = function letterToString() { From 6d588aa08ba50581eaec6f017571dfb09a127fc4 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 14:41:56 +0200 Subject: [PATCH 09/34] bugfix for update in relation to fixed time; slight change in format of layout definition. --- uhr-de_CH_new.js | 24 ++++++++++++------------ uhr.js | 31 +++++++++++++++++++------------ 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/uhr-de_CH_new.js b/uhr-de_CH_new.js index 6283f2d..f755aec 100644 --- a/uhr-de_CH_new.js +++ b/uhr-de_CH_new.js @@ -41,18 +41,18 @@ var layout = { "permanent": h._es_isch, "minutes": { "0": h._genau, - "1": {}, - "5": [h._5, h._ab], - "10": [h._10, h._ab], - "15": [h._15, h._ab], - "20": [h._20, h._ab], - "25": [h._5, h._vor, h._haubi], - "30": [h._haubi], - "35": [h._5, h._ab, h._haubi], - "40": [h._20, h._vor], - "45": [h._15, h._vor], - "50": [h._10, h._vor], - "55": [h._5, h._vor] + "1,2,3,4": {}, + "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,48": [h._15, h._vor], + "50,51,52,53,54": [h._10, h._vor], + "55,56,57,58,59": [h._5, h._vor] }, "hours": { "1": {5:[1,2,3]}, diff --git a/uhr.js b/uhr.js index 75849af..fa0d70e 100644 --- a/uhr.js +++ b/uhr.js @@ -30,8 +30,7 @@ along with this program. If not, see . language: 'de_CH', theme: 'black', force: false, - controls: true, - time: new Date() + controls: true }, start: function() { if (!this._isOn()) { @@ -153,8 +152,7 @@ along with this program. If not, see . if (typeof this._language().getCoarseMinute === 'function') { return this._language().getCoarseMinute(date); } - var minutes = date.getMinutes(); - return minutes - this._getDotMinute(date); + return date.getMinutes(); }, _getDotMinute: function(date) { if (typeof this._language().getDotMinute === 'function') { @@ -174,10 +172,14 @@ along with this program. If not, see . }, _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 (this.options.time !== undefined) { - this.time(this.options.time); + if (userTime !== undefined) { + this.time(userTime); } }, _setupHTML: function() { @@ -302,16 +304,21 @@ function UhrRenderer(layout, renderarea) { } else { this._parseObject(letters, 'on', permanent); } - var minutes = this.layout.minutes; - for (minute in minutes) { - if (minutes.hasOwnProperty(minute)) { - var highlightLetters = minutes[minute]; + var minuteDefinitions = this.layout.minutes; + for (minutes in minuteDefinitions) { + if (minuteDefinitions.hasOwnProperty(minutes)) { + var highlightLetters = minuteDefinitions[minutes]; + var minuteArray = minutes.split(','); if (Array.isArray(highlightLetters)) { for (var i = 0; i < highlightLetters.length; i++) { - this._parseObject(letters, 'minute' + minute, highlightLetters[i]); + for (var j = 0; j < minuteArray.length; j++) { + this._parseObject(letters, 'minute' + minuteArray[j], highlightLetters[i]); + } } } else { - this._parseObject(letters, 'minute' + minute, highlightLetters); + for (var i = 0; i < minuteArray.length; i++) { + this._parseObject(letters, 'minute' + minuteArray[i], highlightLetters); + } } } } From b9473f405f5aa841857c8e56bef1435352d89a83 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 15:52:08 +0200 Subject: [PATCH 10/34] moved parsing of v2-layouts to own class --- uhr.js | 121 +++++++++++++++++++++++++-------------------------------- 1 file changed, 54 insertions(+), 67 deletions(-) diff --git a/uhr.js b/uhr.js index fa0d70e..743e73c 100644 --- a/uhr.js +++ b/uhr.js @@ -285,69 +285,6 @@ along with this program. If not, see . function UhrRenderer(layout, renderarea) { this.layout = layout; this.renderarea = renderarea; - this._parseLayoutV2 = 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); - } - var permanent = this.layout.permanent; - if (Array.isArray(permanent)) { - for (var i = 0; i < permanent.length; i++) { - this._parseObject(letters, 'on', permanent[i]); - } - } else { - this._parseObject(letters, 'on', permanent); - } - var minuteDefinitions = this.layout.minutes; - for (minutes in minuteDefinitions) { - if (minuteDefinitions.hasOwnProperty(minutes)) { - var highlightLetters = minuteDefinitions[minutes]; - var minuteArray = minutes.split(','); - if (Array.isArray(highlightLetters)) { - for (var i = 0; i < highlightLetters.length; i++) { - for (var j = 0; j < minuteArray.length; j++) { - this._parseObject(letters, 'minute' + minuteArray[j], highlightLetters[i]); - } - } - } else { - for (var i = 0; i < minuteArray.length; i++) { - this._parseObject(letters, 'minute' + minuteArray[i], highlightLetters); - } - } - } - } - var hours = this.layout.hours; - for (hour in hours) { - if (hours.hasOwnProperty(hour)) { - var highlightLetters = hours[hour]; - if (Array.isArray(highlightLetters)) { - for (var i = 0; i < highlightLetters.length; i++) { - this._parseObject(letters, 'hour' + hour, highlightLetters[i]); - } - } else { - this._parseObject(letters, 'hour' + hour, highlightLetters); - } - } - } - return letters; - } - this._parseObject = function(letters, styleClass, object) { - for (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); - } - } - } - } } UhrRenderer.prototype.render = function(uhr, beforeshow) { var renderer = this; @@ -355,12 +292,11 @@ UhrRenderer.prototype.render = function(uhr, beforeshow) { if (this.layout.version !== undefined) { switch (this.layout.version) { case 2: - letters = this._parseLayoutV2(); + var delegate = new UhrRendererV2Delegate(this.layout); + letters = delegate.parse(); break; default: - if (console !== undefined && typeof console.log == 'function') { - console.error("Unknown layout version: " + this.layout.version); - } + console.error("Unknown layout version: " + this.layout.version); return; } } else { @@ -383,6 +319,57 @@ UhrRenderer.prototype.render = function(uhr, beforeshow) { renderer.renderarea.fadeIn('fast'); }); }; + +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); + } + } + this._parseObject = function(letters, styleClass, object) { + for (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._definitionHelper = function(letters, styleClass, definition) { + for (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._definitionHelper(letters, 'minute', this.layout.minutes); + this._definitionHelper(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. From 8234d4f3ea05ca6c2bd3daa7bd35fe9fb6fd2da4 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 16:01:25 +0200 Subject: [PATCH 11/34] deleted unnecessary line --- uhr-de_CH_new.js | 1 - 1 file changed, 1 deletion(-) diff --git a/uhr-de_CH_new.js b/uhr-de_CH_new.js index f755aec..55ca83e 100644 --- a/uhr-de_CH_new.js +++ b/uhr-de_CH_new.js @@ -41,7 +41,6 @@ var layout = { "permanent": h._es_isch, "minutes": { "0": h._genau, - "1,2,3,4": {}, "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], From 57556987acb929e0e7f6b3cc93a3cbb37a476bce Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 16:01:42 +0200 Subject: [PATCH 12/34] renamed the helper renderer to _..., as per private naming convention --- uhr.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/uhr.js b/uhr.js index 743e73c..dde0858 100644 --- a/uhr.js +++ b/uhr.js @@ -292,7 +292,7 @@ UhrRenderer.prototype.render = function(uhr, beforeshow) { if (this.layout.version !== undefined) { switch (this.layout.version) { case 2: - var delegate = new UhrRendererV2Delegate(this.layout); + var delegate = new _UhrRendererV2Delegate(this.layout); letters = delegate.parse(); break; default: @@ -320,7 +320,7 @@ UhrRenderer.prototype.render = function(uhr, beforeshow) { }); }; -function UhrRendererV2Delegate(layout) { +function _UhrRendererV2Delegate(layout) { this.layout = layout; this._parseArrayOrObject = function(letters, styleClass, input) { if (Array.isArray(input)) { @@ -354,7 +354,7 @@ function UhrRendererV2Delegate(layout) { } } } -UhrRendererV2Delegate.prototype.parse = function() { +_UhrRendererV2Delegate.prototype.parse = function() { var letters = []; for (var i = 0; i < this.layout.letters.length; i++) { var line = []; From 8f609294ff747d04b8f10837ef6bf0b976506294 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 16:06:23 +0200 Subject: [PATCH 13/34] renamed _new to _genau --- uhr-de_CH_new.js => uhr-de_CH_genau.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename uhr-de_CH_new.js => uhr-de_CH_genau.js (95%) diff --git a/uhr-de_CH_new.js b/uhr-de_CH_genau.js similarity index 95% rename from uhr-de_CH_new.js rename to uhr-de_CH_genau.js index 55ca83e..bb0df3c 100644 --- a/uhr-de_CH_new.js +++ b/uhr-de_CH_genau.js @@ -25,7 +25,7 @@ var h = { }; var layout = { "version": 2, - "language": 'Bärndütsch (nöi)', + "language": 'Bärndütsch (genau)', "letters": [ 'ESKISCHAFÜF', 'VIERTUBFZÄÄ', @@ -68,4 +68,4 @@ var layout = { "12": {10:[1,2,3,4,5,6]} } }; -window._uhr.languages['de_CH_new'] = layout; +window._uhr.languages['de_CH_genau'] = layout; From 428074b1f86329b96b75bcc9a557cea1a36d84c5 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 16:19:18 +0200 Subject: [PATCH 14/34] added missing semicolon --- uhr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uhr.js b/uhr.js index dde0858..8ed1906 100644 --- a/uhr.js +++ b/uhr.js @@ -369,7 +369,7 @@ _UhrRendererV2Delegate.prototype.parse = function() { this._definitionHelper(letters, 'minute', this.layout.minutes); this._definitionHelper(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. From 77ccc95b93196533b9cabb627691b5453a40beaf Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 16:19:56 +0200 Subject: [PATCH 15/34] migrated normal de_CH layout to v2 --- uhr-de_CH.js | 63 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/uhr-de_CH.js b/uhr-de_CH.js index 5e6cedb..edccee3 100644 --- a/uhr-de_CH.js +++ b/uhr-de_CH.js @@ -12,19 +12,58 @@ 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 = { + "_es_isch": {1:[1,2,4,5,6,7]}, + "_ab": {4:[1,2]}, + "_vor": {3:[9,10,11]}, + "_haubi": {4:[4,5,6,7,8]}, + "_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": 2, "language": 'Bärndütsch', - "values": [ - [l('E', 'on'), l('S', 'on'),l('K'),l('I', 'on'),l('S', 'on'),l('C', 'on'),l('H', 'on'),l('A'),m('F', 5, 25, 35, 55),m('Ü', 5, 25, 35, 55),m('F', 5, 25, 35, 55)], - [m('V', 15, 45), m('I', 15, 45),m('E', 15, 45),m('R', 15, 45),m('T', 15, 45),m('U', 15, 45),l('B'),l('F'),m('Z', 10, 50),m('Ä', 10, 50),m('Ä', 10, 50)], - [m('Z', 20, 40), m('W', 20, 40),m('Ä', 20, 40),m('N', 20, 40),m('Z', 20, 40),m('G', 20, 40),l('S'),l('I'),m('V', 25, 40, 45, 50, 55),m('O', 25, 40, 45, 50, 55),m('R', 25, 40, 45, 50, 55)], - [m('A', 5, 10, 15, 20, 35), m('B', 5, 10, 15, 20, 35),l('O'),m('H', 25, 30, 35),m('A', 25, 30, 35),m('U', 25, 30, 35),m('B', 25, 30, 35),m('I', 25, 30, 35),l('E'),l('G'),l('E')], - [h('E', 1), h('I', 1),h('S', 1),h('Z', 2),h('W', 2),h('Ö', 2),h('I', 2),l('S'),h('D', 3),h('R', 3),h('Ü', 3)], - [h('V', 4), h('I', 4),h('E', 4),h('R', 4),h('I', 4),h('F', 5),h('Ü', 5),h('F', 5),h('I', 5),l('Q'),l('T')], - [h('S', 6), h('Ä', 6),h('C', 6),h('H', 6),h('S', 6),h('I', 6),h('S', 7),h('I', 7),h('B', 7),h('N', 7),h('I', 7)], - [h('A', 8), h('C', 8),h('H', 8),h('T', 8),h('I', 8),h('N', 9),h('Ü', 9),h('N', 9),h('I', 9),l('E'),l('L')], - [h('Z', 10), h('Ä', 10),h('N', 10),h('I', 10),l('E'),l('R'),l('B'),h('E', 11),h('U', 11),h('F', 11),h('I', 11)], - [h('Z', 12), h('W', 12),h('Ö', 12),h('U', 12),h('F', 12),h('I', 12),l('N'),l('A'),l('U'),l('H'),l('R')] - ] + "letters": [ + 'ESKISCHAFÜF', + 'VIERTUBFZÄÄ', + 'ZWÄNZGSIVOR', + 'ABOHAUBIEGE', + 'EISZWÖISDRÜ', + 'VIERIFÜFIQT', + 'SÄCHSISIBNI', + 'ACHTINÜNIEL', + 'ZÄNIERBEUFI', + 'ZWÖUFINAUHR' + ], + "permanent": h._es_isch, + "minutes": { + "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,48": [h._15, h._vor], + "50,51,52,53,54": [h._10, h._vor], + "55,56,57,58,59": [h._5, h._vor] + }, + "hours": { + "1": {5:[1,2,3]}, + "2": {5:[4,5,6,7]}, + "3": {5:[9,10,11]}, + "4": {6:[1,2,3,4,5]}, + "5": {6:[6,7,8,9]}, + "6": {7:[1,2,3,4,5,6]}, + "7": {7:[7,8,9,10,11]}, + "8": {8:[1,2,3,4,5]}, + "9": {8:[6,7,8,9]}, + "10": {9:[1,2,3,4]}, + "11": {9:[8,9,10,11]}, + "12": {10:[1,2,3,4,5,6]} + } }; window._uhr.languages['de_CH'] = layout; From 0c67a411164f6c3902958cb0a0b72c61a6dccd1f Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 16:37:43 +0200 Subject: [PATCH 16/34] fixed bug with minute 49 --- uhr-de_CH.js | 2 +- uhr-de_CH_genau.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/uhr-de_CH.js b/uhr-de_CH.js index edccee3..19ee2f1 100644 --- a/uhr-de_CH.js +++ b/uhr-de_CH.js @@ -47,7 +47,7 @@ var layout = { "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,48": [h._15, 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] }, diff --git a/uhr-de_CH_genau.js b/uhr-de_CH_genau.js index bb0df3c..2af5edd 100644 --- a/uhr-de_CH_genau.js +++ b/uhr-de_CH_genau.js @@ -49,7 +49,7 @@ var layout = { "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,48": [h._15, 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] }, From c1961d7fcaca739040a9d29e817de74ee54ee62f Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 16:38:30 +0200 Subject: [PATCH 17/34] migrated de to v2 --- uhr-de.js | 66 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 13 deletions(-) diff --git a/uhr-de.js b/uhr-de.js index 7c0d461..e1f0722 100644 --- a/uhr-de.js +++ b/uhr-de.js @@ -12,19 +12,59 @@ 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 = { + "_es_ist": {1:[1,2,4,5,6]}, + "_nach": {4:[8,9,10,11]}, + "_vor": {4:[1,2,3]}, + "_halb": {5:[1,2,3,4]}, + "_5": {1:[8,9,10,11]}, + "_10": {2:[1,2,3,4]}, + "_15": {3:[5,6,7,8,9,10,11]}, + "_20": {2:[5,6,7,8,9,10,11]}, + "_45": {3:[1,2,3,4,5,6,7,8,9,10,11]} +}; var layout = { - language: 'Deutsch', - values: [ - [l('E', 'on'), l('S', 'on'),l('K'),l('I', 'on'),l('S', 'on'),l('T', 'on'),l('A'),m('F', 5, 25, 35, 55),m('Ü', 5, 25, 35, 55),m('N', 5, 25, 35, 55),m('F', 5, 25, 35, 55)], - [m('Z', 10, 50), m('E', 10, 50),m('H', 10, 50),m('N', 10, 50),m('Z', 20, 40),m('W', 20, 40),m('A', 20, 40),m('N', 20, 40),m('Z', 20, 40),m('I', 20, 40),m('G', 20, 40)], - [m('D', 45), m('R', 45),m('E', 45),m('I', 45),m('V', 15, 45),m('I', 15, 45),m('E', 15, 45),m('R', 15, 45),m('T', 15, 45),m('E', 15, 45),m('L', 15, 45)], - [m('V', 25, 40, 50, 55), m('O', 25, 40, 50, 55),m('R', 25, 40, 50, 55),l('F'),l('U'),l('N'),l('K'),m('N', 5, 10, 15, 20, 35),m('A', 5, 10, 15, 20, 35),m('C', 5, 10, 15, 20, 35),m('H', 5, 10, 15, 20, 35)], - [m('H', 25, 30, 35),m('A', 25, 30, 35),m('L', 25, 30, 35),m('B', 25, 30, 35),l('A'),h('E', 11),h('L', 11),h('F', 5, 11),h('Ü', 5),h('N', 5),h('F', 5)], - [h('E', 1), h('I', 1),h('N', 1),h('S', 1),l('X'),l('A'),l('M'),h('Z', 2),h('W', 2),h('E', 2),h('I', 2)], - [h('D', 3), h('R', 3),h('E', 3),h('I', 3),l('P'),l('M'),l('J'),h('V', 4),h('I', 4),h('E', 4),h('R', 4)], - [h('S', 6), h('E', 6),h('C', 6),h('H', 6),h('S', 6),l('N'),l('L'),h('A', 8),h('C', 8),h('H', 8),h('T', 8)], - [h('S', 7), h('I', 7),h('E', 7),h('B', 7),h('E', 7),h('N', 7),h('Z', 12),h('W', 12),h('Ö', 12),h('L', 12),h('F', 12)], - [h('Z', 10), h('E', 10),h('H', 10),h('N', 9, 10),h('E', 9),h('U', 9),h('N', 9),l('K'),l('U'),l('H'),l('R')] - ] + "version": 2, + "language": 'Deutsch', + "letters": [ + 'ESKISTAFÜNF', + 'ZEHNZWANZIG', + 'DREIVIERTEL', + 'VORFUNKNACH', + 'HALBAELFÜNF', + 'EINSXAMZWEI', + 'DREIPMJVIER', + 'SECHSNLACHT', + 'SIEBENZWÖLF', + 'ZEHNEUNKUHR' + ], + "permanent": h._es_ist, + "minutes": { + "5,6,7,8,9": [h._5, h._nach], + "10,11,12,13,14": [h._10, h._nach], + "15,16,17,18,19": [h._15, h._nach], + "20,21,22,23,24": [h._20, h._nach], + "25,26,27,28,29": [h._5, h._vor, h._halb], + "30,31,32,33,34": [h._halb], + "35,36,37,38,39": [h._5, h._nach, h._halb], + "40,41,42,43,44": [h._20, h._vor], + "45,46,47,48,49": h._45, + "50,51,52,53,54": [h._10, h._vor], + "55,56,57,58,59": [h._5, h._vor] + }, + "hours": { + "1": {6:[1,2,3,4]}, + "2": {6:[8,9,10,11]}, + "3": {3:[1,2,3,4]}, + "4": {7:[8,9,10,11]}, + "5": {5:[8,9,10,11]}, + "6": {8:[1,2,3,4,5]}, + "7": {9:[1,2,3,4,5,6]}, + "8": {8:[8,9,10,11]}, + "9": {10:[4,5,6,7]}, + "10": {10:[1,2,3,4]}, + "11": {5:[6,7,8]}, + "12": {9:[7,8,9,10,11]} + } }; window._uhr.languages['de'] = layout; From c25a0d6c3370ae66e921ec9334f80df7c02807c3 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 26 Jun 2014 16:46:50 +0200 Subject: [PATCH 18/34] migrating en to v2, first step --- uhr-en.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/uhr-en.js b/uhr-en.js index bca4c8e..91065e7 100644 --- a/uhr-en.js +++ b/uhr-en.js @@ -12,9 +12,20 @@ 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 = { + "_es_isch": {1:[1,2,4,5,6,7]}, + "_ab": {4:[1,2]}, + "_vor": {3:[9,10,11]}, + "_haubi": {4:[4,5,6,7,8]}, + "_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 = { - language: 'English', - values: [ + "version": 2, + "language": 'English', + /* [l('I', 'on'), l('T', 'on'),l('L'),l('I', 'on'),l('S', 'on'),l('B'),l('F'),l('A'),l('M'),l('P'),l('M')], [m('A', 15, 45), l('C'),m('Q', 15, 45),m('U', 15, 45),m('A', 15, 45),m('R', 15, 45),m('T', 15, 45),m('E', 15, 45),m('R', 15, 45),l('D'),l('C')], [m('T', 20, 25, 35, 40), m('W', 20, 25, 35, 40),m('E', 20, 25, 35, 40),m('N', 20, 25, 35, 40),m('T', 20, 25, 35, 40),m('Y', 20, 25, 35, 40),m('F', 5, 25, 35, 55),m('I', 5, 25, 35, 55),m('V', 5, 25, 35, 55),m('E', 5, 25, 35, 55),l('X')], @@ -25,8 +36,48 @@ var layout = { [h('E', 8), h('I', 8),h('G', 8),h('H', 8),h('T', 8),h('E', 11),h('L', 11),h('E', 11),h('V', 11),h('E', 11),h('N', 11)], [h('S', 7), h('E', 7),h('V', 7),h('E', 7),h('N', 7),h('T', 12),h('W', 12),h('E', 12),h('L', 12),h('V', 12),h('E', 12)], [h('T', 10), h('E', 10),h('N', 10),l('S'),l('E'),l('O', 'sharphour'),l('C', 'sharphour'),l('L', 'sharphour'),l('O', 'sharphour'),l('C', 'sharphour'),l('K', 'sharphour')] - ], - getHour: function(date) { + */ + "letters": [ + 'ITLISBFAMPM', + 'ACQUARTERDC', + 'TWENTYFIVEX', + 'HALFBTENFTO', + 'PASTERUNINE', + 'ONESIXTHREE', + 'FOURFIVETWO', + 'EIGHTELEVEN', + 'SEVENTWELVE', + 'TENSEOCLOCK' + ], + "permanent": h._es_isch, + "minutes": { + "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": { + "1": {5:[1,2,3]}, + "2": {5:[4,5,6,7]}, + "3": {5:[9,10,11]}, + "4": {6:[1,2,3,4,5]}, + "5": {6:[6,7,8,9]}, + "6": {7:[1,2,3,4,5,6]}, + "7": {7:[7,8,9,10,11]}, + "8": {8:[1,2,3,4,5]}, + "9": {8:[6,7,8,9]}, + "10": {9:[1,2,3,4]}, + "11": {9:[8,9,10,11]}, + "12": {10:[1,2,3,4,5,6]} + }, + "getHour": function(date) { var hour = date.getHours(); if (date.getMinutes() >= 35) { return hour + 1; From 14d7ee79bc62bd35fe9ded5616a1ccb52f2168cf Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 27 Jun 2014 12:27:43 +0200 Subject: [PATCH 19/34] bugfix: when explicitly setting the time to a value with the same minute, it didn't get updated. --- uhr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uhr.js b/uhr.js index 8ed1906..546eb6a 100644 --- a/uhr.js +++ b/uhr.js @@ -81,8 +81,8 @@ along with this program. If not, see . } }, time: function(time) { + this._currentMinute = -1; if (time == null) { - this._currentMinute = -1; this.options.time = new Date(); } else { if (this._timer != null) { From d4874d1ec2909e1361806dd0c1053b72ffe01677 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 27 Jun 2014 12:28:19 +0200 Subject: [PATCH 20/34] migrated en to v2 --- uhr-en.js | 65 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/uhr-en.js b/uhr-en.js index 91065e7..5be556d 100644 --- a/uhr-en.js +++ b/uhr-en.js @@ -13,14 +13,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ var h = { - "_es_isch": {1:[1,2,4,5,6,7]}, - "_ab": {4:[1,2]}, - "_vor": {3:[9,10,11]}, - "_haubi": {4:[4,5,6,7,8]}, - "_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]} + "_it_is": {1:[1,2,4,5]}, + "_half": {4:[1,2,3,4]}, + "_to": {4:[10,11]}, + "_past": {5:[1,2,3,4]}, + "_o_clock": {10:[6,7,8,9,10,11]}, + "_5": {3:[7,8,9,10]}, + "_10": {4:[6,7,8]}, + "_15": {2:[1,3,4,5,6,7,8,9]}, + "_20": {3:[1,2,3,4,5,6]}, + "_25": {3:[1,2,3,4,5,6,7,8,9,10]} }; var layout = { "version": 2, @@ -49,33 +51,34 @@ var layout = { 'SEVENTWELVE', 'TENSEOCLOCK' ], - "permanent": h._es_isch, + "permanent": h._it_is, "minutes": { - "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] + "0,1,2,3,4": h._o_clock, + "5,6,7,8,9": [h._5, h._past], + "10,11,12,13,14": [h._10, h._past], + "15,16,17,18,19": [h._15, h._past], + "20,21,22,23,24": [h._20, h._past], + "25,26,27,28,29": [h._25, h._past], + "30,31,32,33,34": [h._half, h._past], + "35,36,37,38,39": [h._25, h._to], + "40,41,42,43,44": [h._20, h._to], + "45,46,47,48,49": [h._15, h._to], + "50,51,52,53,54": [h._10, h._to], + "55,56,57,58,59": [h._5, h._to] }, "hours": { - "1": {5:[1,2,3]}, - "2": {5:[4,5,6,7]}, - "3": {5:[9,10,11]}, - "4": {6:[1,2,3,4,5]}, - "5": {6:[6,7,8,9]}, - "6": {7:[1,2,3,4,5,6]}, - "7": {7:[7,8,9,10,11]}, + "1": {6:[1,2,3]}, + "2": {7:[9,10,11]}, + "3": {6:[7,8,9,10,11]}, + "4": {7:[1,2,3,4]}, + "5": {7:[5,6,7,8]}, + "6": {6:[4,5,6]}, + "7": {9:[1,2,3,4,5]}, "8": {8:[1,2,3,4,5]}, - "9": {8:[6,7,8,9]}, - "10": {9:[1,2,3,4]}, - "11": {9:[8,9,10,11]}, - "12": {10:[1,2,3,4,5,6]} + "9": {5:[8,9,10,11]}, + "10": {10:[1,2,3]}, + "11": {8:[6,7,8,9,10,11]}, + "12": {9:[6,7,8,9,10,11]} }, "getHour": function(date) { var hour = date.getHours(); From 4942cfda2f3ff6943276e94690f771e963e3d707 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 27 Jun 2014 12:34:01 +0200 Subject: [PATCH 21/34] deleted obsolete helper methods --- uhr.js | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/uhr.js b/uhr.js index 546eb6a..454dca1 100644 --- a/uhr.js +++ b/uhr.js @@ -319,7 +319,6 @@ UhrRenderer.prototype.render = function(uhr, beforeshow) { renderer.renderarea.fadeIn('fast'); }); }; - function _UhrRendererV2Delegate(layout) { this.layout = layout; this._parseArrayOrObject = function(letters, styleClass, input) { @@ -395,41 +394,3 @@ function Letter(value, style) { Letter.prototype.toString = function letterToString() { return '' + this.getValue() + ''; }; -/** - * Hilfsfunktion, um einen Buchstaben zu erzeugen. - * - * @param letter string: Der Buchstabe, der angezeigt werden soll - * @param style string: CSS-Klasse(n) als String - * @example l('I', 'is') erzeugt den Buchstaben 'I' mit der CSS-Styleklasse 'is' - */ -function l(letter, style) { - return new Letter(letter, style); -} -/** - * Hilfsfunktion, um einen Buchstaben zu erzeugen, der zu einem Stunden-Wort gehört. - * - * @param letter string: Der Buchstabe, der angezeigt werden soll - * @param hours... integer: Eine Aufzählung von Stundenwerten, zu welchen der Buchstabe als aktiv angezeigt werden soll - * @example h('Z', 2, 11) erzeugt den Buchstaben 'Z', der um 2:xx, 11:xx, 14:xx und 23:xx aktiv angezeigt wird - */ -function h(letter) { - var style = ''; - for (var i = 1; i < arguments.length; i++) { - style += ' hour' + arguments[i]; - } - return l(letter, style); -} -/** - * Hilfsfunktion, um einen Buchstaben zu erzeugen, der zu einem Minuten-Wort gehört. - * - * @param letter string: Der Buchstabe, der angezeigt werden soll - * @param minutes... integer: Eine Aufzählung von Minutenwerten, zu welchen der Buchstabe als aktiv angezeigt werden soll - * @example m('A', 5, 10, 15, 20, 35) erzeugt den Buchstaben 'A' der um :05, :10, :15, :20 und :35 aktiv angezeigt wird - */ -function m(letter) { - var style = ''; - for (var i = 1; i < arguments.length; i++) { - style += ' minute' + arguments[i]; - } - return l(letter, style); -} From a9d8888f6a95624c194be9e9411e6381ff93fcdb Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 27 Jun 2014 12:44:38 +0200 Subject: [PATCH 22/34] drop support for the old layout. only v2 supported as of now. --- uhr.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/uhr.js b/uhr.js index 454dca1..eef10c5 100644 --- a/uhr.js +++ b/uhr.js @@ -289,18 +289,14 @@ function UhrRenderer(layout, renderarea) { UhrRenderer.prototype.render = function(uhr, beforeshow) { var renderer = this; var letters; - if (this.layout.version !== undefined) { - switch (this.layout.version) { - case 2: - var delegate = new _UhrRendererV2Delegate(this.layout); - letters = delegate.parse(); - break; - default: - console.error("Unknown layout version: " + this.layout.version); - return; - } - } else { - letters = renderer.layout.values; + switch (this.layout.version) { + case 2: + var delegate = new _UhrRendererV2Delegate(this.layout); + letters = delegate.parse(); + break; + default: + console.warn("Unknown layout version: '" + this.layout.version + "'"); + return; } this.renderarea.fadeOut('fast', function() { renderer.renderarea.empty(); From fa1c6a1ea3491423c4feebd52b4c7e50c0618f85 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 27 Jun 2014 12:55:31 +0200 Subject: [PATCH 23/34] added comments --- uhr-de_CH.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/uhr-de_CH.js b/uhr-de_CH.js index 19ee2f1..1bb4be2 100644 --- a/uhr-de_CH.js +++ b/uhr-de_CH.js @@ -12,6 +12,7 @@ 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 . */ +// hilfsvariablen var h = { "_es_isch": {1:[1,2,4,5,6,7]}, "_ab": {4:[1,2]}, @@ -23,8 +24,11 @@ var h = { "_20": {3:[1,2,3,4,5,6]} }; var layout = { + // version: zur Zeit immer 2 (Pflichtattribut) "version": 2, + // Sprechender Name der Sprache "language": 'Bärndütsch', + // Buchstabenfeld als Array von Strings. "letters": [ 'ESKISCHAFÜF', 'VIERTUBFZÄÄ', @@ -37,20 +41,42 @@ var layout = { 'ZÄNIERBEUFI', 'ZWÖUFINAUHR' ], + // Permanent aktive Buchstaben. , vgl. ausführliche Beschreibung bei "minutes". "permanent": h._es_isch, + /* + * Minuten: Objekt im folgenden Format: + * { + * : , + * ... + * } + * : String von Komma-separierten Minutenwerten, zu welchem die in angegebenen Buchstaben aktiv sein sollen + * : [ , ...] | + * : { : [ , ... ] } + * : Die Zeile, in welcher die Buchstaben liegen; von oben gezählt, oben ist 1. + * : Die Spalte, in der ein einzelner Buchstabe liegt; von links gezählt, links ist 1. + * Beispiel: + * "minutes": { + * "0,1": {1: [6, 7, 9]}, + * "5": [ {3: [1, 2]}, {4: [10, 11]} ] + * } + * Erklärung: + * Bei Minuten 0 und 1 sind die Buchstaben 6, 7 und 9 der ersten Zeile aktiv. + * Bei Minute 5 sind die Buchstaben 1 und 2 der Zeile 3 sowie die Buchstaben 10 und 11 der Zeile 4 aktiv. + */ "minutes": { "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], + "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] }, + // Die Stunden; gleiches Format wie bei den Minuten "hours": { "1": {5:[1,2,3]}, "2": {5:[4,5,6,7]}, @@ -66,4 +92,5 @@ var layout = { "12": {10:[1,2,3,4,5,6]} } }; +// Das Layout bei der Uhr unter dem Code "de_CH" registrieren. window._uhr.languages['de_CH'] = layout; From 29b280cf8b775ab895dbe93569f61792a61738c3 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 27 Jun 2014 12:56:32 +0200 Subject: [PATCH 24/34] removed unnecessary array-brackets --- uhr-de.js | 2 +- uhr-de_CH_genau.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/uhr-de.js b/uhr-de.js index e1f0722..199bb06 100644 --- a/uhr-de.js +++ b/uhr-de.js @@ -45,7 +45,7 @@ var layout = { "15,16,17,18,19": [h._15, h._nach], "20,21,22,23,24": [h._20, h._nach], "25,26,27,28,29": [h._5, h._vor, h._halb], - "30,31,32,33,34": [h._halb], + "30,31,32,33,34": h._halb, "35,36,37,38,39": [h._5, h._nach, h._halb], "40,41,42,43,44": [h._20, h._vor], "45,46,47,48,49": h._45, diff --git a/uhr-de_CH_genau.js b/uhr-de_CH_genau.js index 2af5edd..f9cf0e8 100644 --- a/uhr-de_CH_genau.js +++ b/uhr-de_CH_genau.js @@ -46,7 +46,7 @@ var layout = { "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], + "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], From a263a1f18cfd44de918e2b13e7d478bc91d7b513 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 27 Jun 2014 13:20:36 +0200 Subject: [PATCH 25/34] fixed hour3 + minutes45 to 49 --- uhr-de.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uhr-de.js b/uhr-de.js index 199bb06..f8030a5 100644 --- a/uhr-de.js +++ b/uhr-de.js @@ -55,7 +55,7 @@ var layout = { "hours": { "1": {6:[1,2,3,4]}, "2": {6:[8,9,10,11]}, - "3": {3:[1,2,3,4]}, + "3": {7:[1,2,3,4]}, "4": {7:[8,9,10,11]}, "5": {5:[8,9,10,11]}, "6": {8:[1,2,3,4,5]}, From e5ce0ab2bbdd742353bb033394233df2e970a912 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 27 Jun 2014 13:23:10 +0200 Subject: [PATCH 26/34] cache parsed layouts instead of re-parsing them every time the language changes --- uhr.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/uhr.js b/uhr.js index eef10c5..0a1ede0 100644 --- a/uhr.js +++ b/uhr.js @@ -288,16 +288,18 @@ function UhrRenderer(layout, renderarea) { } UhrRenderer.prototype.render = function(uhr, beforeshow) { var renderer = this; - var letters; - switch (this.layout.version) { - case 2: - var delegate = new _UhrRendererV2Delegate(this.layout); - letters = delegate.parse(); - break; - default: - console.warn("Unknown layout version: '" + this.layout.version + "'"); - return; + 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++) { @@ -337,7 +339,7 @@ function _UhrRendererV2Delegate(layout) { } } } - this._definitionHelper = function(letters, styleClass, definition) { + this._parseTimeDefinition = function(letters, styleClass, definition) { for (listString in definition) { if (definition.hasOwnProperty(listString)) { var array = listString.split(','); @@ -361,8 +363,8 @@ _UhrRendererV2Delegate.prototype.parse = function() { letters.push(line); } this._parseArrayOrObject(letters, 'on', this.layout.permanent); - this._definitionHelper(letters, 'minute', this.layout.minutes); - this._definitionHelper(letters, 'hour', this.layout.hours); + this._parseTimeDefinition(letters, 'minute', this.layout.minutes); + this._parseTimeDefinition(letters, 'hour', this.layout.hours); return letters; }; /** From ffcf8fa2f25bcf569c0a837efb3ba8b5a8d23712 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 28 Jun 2014 15:52:48 +0200 Subject: [PATCH 27/34] added showcase --- index.html | 2 +- showcase/index.html | 57 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 showcase/index.html diff --git a/index.html b/index.html index 1019562..8762468 100644 --- a/index.html +++ b/index.html @@ -32,7 +32,7 @@ along with this program. If not, see .
-

Created by fritteli, inspired by QLOCKTWO. Read more!

+

Created by fritteli, inspired by QLOCKTWO. Read more! - View full showcase!

+ + + + + +
+

Go back to the main page

+ + + + + + + From 480736e877f3dacb7253db9792067d7b6e4f2f8f Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 28 Jun 2014 15:53:08 +0200 Subject: [PATCH 28/34] refactor: move every helper function inside the scope-limiting block in order not to pollute world --- uhr.js | 240 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 120 insertions(+), 120 deletions(-) diff --git a/uhr.js b/uhr.js index 158f00f..850f48e 100644 --- a/uhr.js +++ b/uhr.js @@ -34,7 +34,7 @@ along with this program. If not, see . if (name === undefined) { name = styleClass; } - window._uhr.themes.push({'class': styleClass, 'name': name}); + window._uhr.themes.push({'styleClass': styleClass, 'name': name}); } } // fall-back if no theme was included @@ -46,7 +46,7 @@ along with this program. If not, see . width: '100%', status: 'on', language: 'de_CH', - theme: window._uhr.themes[0].class, + theme: window._uhr.themes[0].styleClass, force: false, controls: true }, @@ -248,7 +248,7 @@ along with this program. If not, see . var themeChooser = $(''); for (var i = 0; i < window._uhr.themes.length; i++) { var theme = window._uhr.themes[i]; - themeChooser.append(''); + themeChooser.append(''); } e.after(themeChooser); } @@ -297,14 +297,14 @@ along with this program. If not, see . } var found = false; for (var i = 0; i < window._uhr.themes.length; i++) { - var styleClass = window._uhr.themes[i].class; + var styleClass = window._uhr.themes[i].styleClass; if (selectedTheme == styleClass) { found = true; break; } } if (!found) { - var fallback = window._uhr.themes[0].class; + var fallback = window._uhr.themes[0].styleClass; console.warn("Theme " + selectedTheme + " not found! Using fallback: " + fallback); selectedTheme = fallback; } @@ -313,120 +313,120 @@ along with this program. If not, see . this.theme(selectedTheme); } }); + /** + * 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 (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); + } + } + } + } + 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); + } + } + } + } + } + _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, '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); -/** - * 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 (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 (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 (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, '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() + ''; -}; From 194ebc58de94f931e45deb87bd2cf1f6b12f7a45 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 28 Jun 2014 15:58:28 +0200 Subject: [PATCH 29/34] fix sizing --- showcase/index.html | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/showcase/index.html b/showcase/index.html index 5dc1079..3c28105 100644 --- a/showcase/index.html +++ b/showcase/index.html @@ -45,10 +45,13 @@ along with this program. If not, see . From bb027261b2df068fd49b6750b603311d5a987a1d Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 28 Jun 2014 16:40:24 +0200 Subject: [PATCH 32/34] register languages with help of a function. that enables advances functionality with fallback-language and makes it generally more robust. this commit concludes the refactoring of the layout definition. --- uhr-de.js | 2 +- uhr-de_CH.js | 2 +- uhr-de_CH_genau.js | 2 +- uhr-en.js | 2 +- uhr.js | 57 ++++++++++++++++++++++++++++++++++------------ 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/uhr-de.js b/uhr-de.js index f8030a5..9ff1298 100644 --- a/uhr-de.js +++ b/uhr-de.js @@ -67,4 +67,4 @@ var layout = { "12": {9:[7,8,9,10,11]} } }; -window._uhr.languages['de'] = layout; +window,_uhr.register('de', layout); diff --git a/uhr-de_CH.js b/uhr-de_CH.js index 1bb4be2..d5d2bd3 100644 --- a/uhr-de_CH.js +++ b/uhr-de_CH.js @@ -93,4 +93,4 @@ var layout = { } }; // Das Layout bei der Uhr unter dem Code "de_CH" registrieren. -window._uhr.languages['de_CH'] = layout; +window,_uhr.register('de_CH', layout); diff --git a/uhr-de_CH_genau.js b/uhr-de_CH_genau.js index f9cf0e8..32f98cd 100644 --- a/uhr-de_CH_genau.js +++ b/uhr-de_CH_genau.js @@ -68,4 +68,4 @@ var layout = { "12": {10:[1,2,3,4,5,6]} } }; -window._uhr.languages['de_CH_genau'] = layout; +window,_uhr.register('de_CH_genau', layout); diff --git a/uhr-en.js b/uhr-en.js index 5be556d..51ea61f 100644 --- a/uhr-en.js +++ b/uhr-en.js @@ -88,4 +88,4 @@ var layout = { return hour; } }; -window._uhr.languages['en'] = layout; +window,_uhr.register('en', layout); diff --git a/uhr.js b/uhr.js index 850f48e..8578bc2 100644 --- a/uhr.js +++ b/uhr.js @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ (function($) { - "use strict"; + 'use strict'; if (window._uhr !== undefined) { return; @@ -22,7 +22,17 @@ along with this program. If not, see . window._uhr = { id: 0, languages: [], - themes: [] + 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 = $('head link[rel=stylesheet]'); @@ -148,7 +158,14 @@ along with this program. If not, see . } }, _language: function() { - return window._uhr.languages[this.options.language]; + 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'); @@ -228,17 +245,11 @@ along with this program. If not, see . e.after(toggleSwitch); // language chooser - var options = []; - for (var code in window._uhr.languages) { - if (window._uhr.languages.hasOwnProperty(code)) { - var language = window._uhr.languages[code]; - options.push(''); - } - } - if (options.length > 1) { + if (window._uhr.languages.length > 1) { var languageChooser = $(''); - for (var i = 0; i < options.length; i++) { - languageChooser.append(options[i]); + for (var i = 0; i < window._uhr.languages.length; i++) { + var language = window._uhr.languages[i]; + languageChooser.append(''); } e.after(languageChooser); } @@ -282,6 +293,24 @@ along with this program. If not, see . 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); @@ -295,7 +324,7 @@ along with this program. If not, see . if (selectedTheme == undefined || this.options.force) { selectedTheme = this.options.theme; } - var found = false; + found = false; for (var i = 0; i < window._uhr.themes.length; i++) { var styleClass = window._uhr.themes[i].styleClass; if (selectedTheme == styleClass) { From 59c5b8d358d467347536d2edaae369099e69f184 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 28 Jun 2014 16:44:03 +0200 Subject: [PATCH 33/34] updated manifest, including the version --- manifest.appcache | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/manifest.appcache b/manifest.appcache index 90703e1..b8ffb4b 100644 --- a/manifest.appcache +++ b/manifest.appcache @@ -1,5 +1,5 @@ CACHE MANIFEST -# 5.1 +# 6.0 COPYING README.md @@ -13,13 +13,16 @@ uhr-black.css uhr-blue.css uhr-de.js uhr-de_CH.js +uhr-de_CH_genau.js uhr-en.js uhr-green.css uhr-pink.css uhr-red.css uhr-white.css +uhr-yellow.css uhr.css uhr.js uhr.woff info/index.html info/info.css +showcase/index.html From f04d5a9aef105466177b3c27fae8e575db33c53c Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 28 Jun 2014 16:47:44 +0200 Subject: [PATCH 34/34] remove trailing newline --- uhr.js | 1 - 1 file changed, 1 deletion(-) diff --git a/uhr.js b/uhr.js index 8578bc2..76ae549 100644 --- a/uhr.js +++ b/uhr.js @@ -458,4 +458,3 @@ along with this program. If not, see . return '' + this.getValue() + ''; }; })(jQuery); -