re-indented the code
This commit is contained in:
parent
de75a3bdaf
commit
6f6feb5cf5
1 changed files with 46 additions and 41 deletions
87
js/uhr.js
87
js/uhr.js
|
@ -1,19 +1,19 @@
|
||||||
/*
|
/*
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
(function ($) {
|
(function ($) {
|
||||||
'use strict';
|
'use strict';
|
||||||
var uhrGlobals = {
|
var uhrGlobals = {
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"languages": [],
|
"languages": [],
|
||||||
|
@ -33,7 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// auto-detect themes
|
// auto-detect themes
|
||||||
$('link[rel=stylesheet]').each(function (index, item) {
|
$('link[rel=stylesheet]').each(function (index, item) {
|
||||||
var styleSheet = $(item);
|
var styleSheet = $(item);
|
||||||
var styleClass = styleSheet.attr('data-class');
|
var styleClass = styleSheet.attr('data-class');
|
||||||
|
@ -45,10 +45,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
uhrGlobals.themes.push({'styleClass': styleClass, 'name': name});
|
uhrGlobals.themes.push({'styleClass': styleClass, 'name': name});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// fall-back if no theme was included
|
// fall-back if no theme was included
|
||||||
if (uhrGlobals.themes.length === 0) {
|
if (uhrGlobals.themes.length === 0) {
|
||||||
uhrGlobals.themes.push({});
|
uhrGlobals.themes.push({});
|
||||||
}
|
}
|
||||||
|
|
||||||
// public interface methods (exported later)
|
// public interface methods (exported later)
|
||||||
var start = function start() {
|
var start = function start() {
|
||||||
|
@ -339,13 +339,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"_create": create
|
"_create": create
|
||||||
});
|
});
|
||||||
$.fritteli.uhr.register = uhrGlobals.registerLanguage;
|
$.fritteli.uhr.register = uhrGlobals.registerLanguage;
|
||||||
/**
|
/**
|
||||||
* Hilfsklasse zum Rendern der Uhr.
|
* Hilfsklasse zum Rendern der Uhr.
|
||||||
* @param layout Layout-Objekt, das gerendert werden soll.
|
* @param layout Layout-Objekt, das gerendert werden soll.
|
||||||
* @param renderarea Das jQuery-gewrappte HTML-Element, auf dem gerendert werden soll.
|
* @param renderarea Das jQuery-gewrappte HTML-Element, auf dem gerendert werden soll.
|
||||||
*/
|
*/
|
||||||
function UhrRenderer(layout, renderarea) {
|
function UhrRenderer(layout, renderarea) {
|
||||||
this.render = function render(uhr, beforeshow) {
|
this.render = function render(uhr, beforeshow) {
|
||||||
if (layout.parsed === undefined) {
|
if (layout.parsed === undefined) {
|
||||||
switch (layout.version) {
|
switch (layout.version) {
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -376,16 +376,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function UhrRendererV2Delegate(layout) {
|
|
||||||
function parseArrayOrObject(letters, styleClass, input) {
|
function UhrRendererV2Delegate(layout) {
|
||||||
if (Array.isArray(input)) {
|
function parseArrayOrObject(letters, styleClass, input) {
|
||||||
|
if (Array.isArray(input)) {
|
||||||
input.forEach(function (item) {
|
input.forEach(function (item) {
|
||||||
parseObject(letters, styleClass, item);
|
parseObject(letters, styleClass, item);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
parseObject(letters, styleClass, input);
|
parseObject(letters, styleClass, input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseObject(letters, styleClass, object) {
|
function parseObject(letters, styleClass, object) {
|
||||||
Object.keys(object).forEach(function (y) {
|
Object.keys(object).forEach(function (y) {
|
||||||
var highlightLetters = object[y];
|
var highlightLetters = object[y];
|
||||||
|
@ -394,7 +396,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function parseTimeDefinition(letters, styleClass, definition) {
|
|
||||||
|
function parseTimeDefinition(letters, styleClass, definition) {
|
||||||
Object.keys(definition).forEach(function (listString) {
|
Object.keys(definition).forEach(function (listString) {
|
||||||
var array = listString.split(',');
|
var array = listString.split(',');
|
||||||
var highlightLetters = definition[listString];
|
var highlightLetters = definition[listString];
|
||||||
|
@ -402,7 +405,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
parseArrayOrObject(letters, styleClass + item, highlightLetters);
|
parseArrayOrObject(letters, styleClass + item, highlightLetters);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.parse = function parse() {
|
this.parse = function parse() {
|
||||||
var letters = [];
|
var letters = [];
|
||||||
layout.letters.forEach(function (string) {
|
layout.letters.forEach(function (string) {
|
||||||
|
@ -418,13 +422,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
parseTimeDefinition(letters, 'hour', layout.hours);
|
parseTimeDefinition(letters, 'hour', layout.hours);
|
||||||
return letters;
|
return letters;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays.
|
/**
|
||||||
* @param value Der Buchstabe, der Dargestellt werden soll.
|
* Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays.
|
||||||
* @param style Die CSS-Styleklassen des Buchstabens.
|
* @param value Der Buchstabe, der Dargestellt werden soll.
|
||||||
*/
|
* @param style Die CSS-Styleklassen des Buchstabens.
|
||||||
function Letter(value, style) {
|
*/
|
||||||
|
function Letter(value, style) {
|
||||||
var myValue = value;
|
var myValue = value;
|
||||||
var myStyle = style || '';
|
var myStyle = style || '';
|
||||||
this.addStyle = function (style) {
|
this.addStyle = function (style) {
|
||||||
|
@ -437,5 +442,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
this.toString = function () {
|
this.toString = function () {
|
||||||
return '<span class="item letter ' + myStyle + '">' + myValue + '</span>';
|
return '<span class="item letter ' + myStyle + '">' + myValue + '</span>';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})(jQuery);
|
})(jQuery);
|
Loading…
Reference in a new issue