adapted the changes on the seconds branch to the refactored code

This commit is contained in:
Manuel Friedli 2014-08-11 23:52:46 +02:00
parent 020fc96036
commit 504e139bf2
6 changed files with 290 additions and 273 deletions

View file

@ -37,6 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<script type="text/javascript" src="js/uhr.js"></script>
<script type="text/javascript" src="js/uhr-de_CH.js"></script>
<script type="text/javascript" src="js/uhr-de_CH_genau.js"></script>
<script type="text/javascript" src="js/uhr-de_CH-seconds.js"></script>
<script type="text/javascript" src="js/uhr-de.js"></script>
<script type="text/javascript" src="js/uhr-en.js"></script>
<script type="text/javascript" src="js/uhr-fr.js"></script>

247
js/uhr-de_CH-seconds.js Normal file
View file

@ -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 <http://www.gnu.org/licenses/>.
*/
(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);
}());

View file

@ -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;

View file

@ -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

View file

@ -29,8 +29,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<link rel="stylesheet" type="text/css" href="../css/uhr-yellow.css" data-class="yellow" data-name="Gelb" />
<link rel="stylesheet" type="text/css" href="../css/uhr-blue.css" data-class="blue" data-name="Blau" />
<link rel="stylesheet" type="text/css" href="../css/uhr-pink.css" data-class="pink" data-name="Pink" />
<link rel="shortcut icon" type="image/png" href="favicon.png" />
<link rel="apple-touch-icon-precomposed" href="apple-touch-icon-precomposed.png" />
<link rel="shortcut icon" type="image/png" href="../resources/favicon.png" />
<link rel="apple-touch-icon-precomposed" href="../resources/apple-touch-icon-precomposed.png" />
<script type="text/javascript" src="../lib/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../lib/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript" src="../lib/jquery-cookie-1.4.0.js"></script>
@ -41,7 +41,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<p ><a href="..">Go back to the main page</a></p>
<script type="text/javascript" src="../js/uhr-de_CH.js"></script>
<script type="text/javascript" src="../js/uhr-de_CH_genau.js"></script>
<script type="text/javascript" src="../uhr-de_CH-seconds.js"></script>
<script type="text/javascript" src="../js/uhr-de_CH-seconds.js"></script>
<script type="text/javascript" src="../js/uhr-de.js"></script>
<script type="text/javascript" src="../js/uhr-en.js"></script>
<script type="text/javascript" src="../js/uhr-fr.js"></script>
@ -50,7 +50,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
(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;
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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);