From 85b5670dfcf6af9586c8c1e46f5a7960bd556db1 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 3 Jul 2014 20:33:26 +0200 Subject: [PATCH] removed the window.uhr global variable! hooray! --- js/uhr-de.js | 3 ++- js/uhr-de_CH.js | 3 ++- js/uhr-de_CH_genau.js | 3 ++- js/uhr-en.js | 3 ++- js/uhr-fr.js | 3 ++- js/uhr-it.js | 3 ++- js/uhr.js | 60 ++++++++++++++++--------------------------- test/test.html | 11 ++++++-- 8 files changed, 43 insertions(+), 46 deletions(-) diff --git a/js/uhr-de.js b/js/uhr-de.js index cb01ab9..0975ff3 100644 --- a/js/uhr-de.js +++ b/js/uhr-de.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 . */ +'use strict'; var h = { "_es_ist": {1:[1,2,4,5,6]}, "_nach": {4:[8,9,10,11]}, @@ -67,4 +68,4 @@ var layout = { "11,23": {5:[6,7,8]} } }; -window.uhr.register('de', layout); +$.fritteli.uhr.register('de', layout); diff --git a/js/uhr-de_CH.js b/js/uhr-de_CH.js index 6afbf23..30a4245 100644 --- a/js/uhr-de_CH.js +++ b/js/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 . */ +'use strict'; // hilfsvariablen var h = { "_es_isch": {1:[1,2,4,5,6,7]}, @@ -93,4 +94,4 @@ var layout = { } }; // Das Layout bei der Uhr unter dem Code "de_CH" registrieren. -window.uhr.register('de_CH', layout); +$.fritteli.uhr.register('de_CH', layout); diff --git a/js/uhr-de_CH_genau.js b/js/uhr-de_CH_genau.js index 2f00090..f21dfed 100644 --- a/js/uhr-de_CH_genau.js +++ b/js/uhr-de_CH_genau.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 . */ +'use strict'; var h = { "_es_isch": {1:[1,2,4,5,6,7]}, "_genau": {3:[7,8,9,10,11]}, @@ -68,4 +69,4 @@ var layout = { "11,23": {9:[8,9,10,11]} } }; -window.uhr.register('de_CH_genau', layout); +$.fritteli.uhr.register('de_CH_genau', layout); diff --git a/js/uhr-en.js b/js/uhr-en.js index 7fc5fd8..e1d422e 100644 --- a/js/uhr-en.js +++ b/js/uhr-en.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 . */ +'use strict'; var h = { "_it_is": {1:[1,2,4,5]}, "_half": {4:[1,2,3,4]}, @@ -76,4 +77,4 @@ var layout = { return hour; } }; -window.uhr.register('en', layout); +$.fritteli.uhr.register('en', layout); diff --git a/js/uhr-fr.js b/js/uhr-fr.js index c9fa8ab..14e9be1 100644 --- a/js/uhr-fr.js +++ b/js/uhr-fr.js @@ -13,6 +13,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 . */ +'use strict'; var h = { "_il_est": {1:[1,2,4,5,6]}, "_et": {8:[1,2]}, @@ -78,4 +79,4 @@ var layout = { return hour; } }; -window.uhr.register('fr', layout); +$.fritteli.uhr.register('fr', layout); diff --git a/js/uhr-it.js b/js/uhr-it.js index 0f26df0..29dee3e 100644 --- a/js/uhr-it.js +++ b/js/uhr-it.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 . */ +'use strict'; var h = { "_sono_le": {1:[1,2,3,4,6,7]}, "_e_l": {2:[1,3,4]}, @@ -75,4 +76,4 @@ var layout = { return hour; } }; -window.uhr.register('it', layout); +$.fritteli.uhr.register('it', layout); diff --git a/js/uhr.js b/js/uhr.js index 8e9044c..20a6485 100644 --- a/js/uhr.js +++ b/js/uhr.js @@ -19,7 +19,7 @@ along with this program. If not, see . "languages": [], "themes": [], registerLanguage: function registerLanguage(code, language) { - var alreadyExists = this.languages.reduce(function (exists, element) { + var alreadyExists = uhrGlobals.languages.reduce(function (exists, element) { if (exists) { return true; } @@ -31,20 +31,11 @@ along with this program. If not, see . }, false); if (!alreadyExists) { language.code = code; - this.languages.push(language); + uhrGlobals.languages.push(language); } } }; - if (window.uhr !== undefined) { - return; - } - window.uhr = { - id: 0, - languages: [], - themes: [], - register: uhrGlobals.registerLanguage - }; // auto-detect themes var styleSheets = $('link[rel=stylesheet]'); for (var i = 0; i < styleSheets.length; i++) { @@ -55,12 +46,12 @@ along with this program. If not, see . if (name === undefined) { name = styleClass; } - window.uhr.themes.push({'styleClass': styleClass, 'name': name}); + uhrGlobals.themes.push({'styleClass': styleClass, 'name': name}); } } // fall-back if no theme was included - if (window.uhr.themes.length === 0) { - window.uhr.themes.push({}); + if (uhrGlobals.themes.length === 0) { + uhrGlobals.themes.push({}); } // public interface methods (exported later) @@ -126,7 +117,7 @@ along with this program. If not, see . // private interface methods var create = function create() { - this._id = window.uhr.id++; + this._id = uhrGlobals.id++; var userTime = this.options.time; if (this.options.time === undefined) { this.options.time = new Date(); @@ -167,20 +158,20 @@ along with this program. If not, see . e.after(toggleSwitch); // language chooser - if (window.uhr.languages.length > 1) { + if (uhrGlobals.languages.length > 1) { var languageChooser = $(''); - for (var i = 0; i < window.uhr.languages.length; i++) { - var language = window.uhr.languages[i]; + for (var i = 0; i < uhrGlobals.languages.length; i++) { + var language = uhrGlobals.languages[i]; languageChooser.append(''); } e.after(languageChooser); } // theme chooser - if (window.uhr.themes.length > 1) { + if (uhrGlobals.themes.length > 1) { var themeChooser = $(''); - for (var i = 0; i < window.uhr.themes.length; i++) { - var theme = window.uhr.themes[i]; + for (var i = 0; i < uhrGlobals.themes.length; i++) { + var theme = uhrGlobals.themes[i]; themeChooser.append(''); } e.after(themeChooser); @@ -215,8 +206,8 @@ along with this program. If not, see . selectedLanguage = uhr.options.language; } var found = false; - for (var i = 0; i < window.uhr.languages.length; i++) { - var code = window.uhr.languages[i].code; + for (var i = 0; i < uhrGlobals.languages.length; i++) { + var code = uhrGlobals.languages[i].code; if (selectedLanguage === code) { found = true; break; @@ -224,8 +215,8 @@ along with this program. If not, see . } if (!found) { var fallback; - if (window.uhr.languages.length > 0) { - fallback = window.uhr.languages[0].code; + if (uhrGlobals.languages.length > 0) { + fallback = uhrGlobals.languages[0].code; } else { fallback = ''; } @@ -246,15 +237,15 @@ along with this program. If not, see . selectedTheme = uhr.options.theme; } found = false; - for (var i = 0; i < window.uhr.themes.length; i++) { - var styleClass = window.uhr.themes[i].styleClass; + for (var i = 0; i < uhrGlobals.themes.length; i++) { + var styleClass = uhrGlobals.themes[i].styleClass; if (selectedTheme === styleClass) { found = true; break; } } if (!found) { - var fallback = window.uhr.themes[0].styleClass; + var fallback = uhrGlobals.themes[0].styleClass; console.warn("Theme " + selectedTheme + " not found! Using fallback: " + fallback); selectedTheme = fallback; } @@ -332,7 +323,7 @@ along with this program. If not, see . }; var language = function language(uhr) { - var matchingLanguages = window.uhr.languages.filter(function (element) { + var matchingLanguages = uhrGlobals.languages.filter(function (element) { return (element.code === this.options.language) }, uhr); if (matchingLanguages.length > 0) { @@ -340,14 +331,6 @@ along with this program. If not, see . } // fallback: return empty object return {}; -/* for (var i = 0; i < window.uhr.languages.length; i++) { - var language = window.uhr.languages[i]; - if (language.code == uhr.options.language) { - return language; - } - } - // fallback: return empty object - return {};*/ }; $.widget("fritteli.uhr", { @@ -355,7 +338,7 @@ along with this program. If not, see . width: '100%', status: 'on', language: 'de_CH', - theme: window.uhr.themes[0].styleClass, + theme: uhrGlobals.themes[0].styleClass, force: false, controls: true }, @@ -372,6 +355,7 @@ along with this program. If not, see . "_timer": null, "_currentMinute": -1 }); + $.fritteli.uhr.register = uhrGlobals.registerLanguage; /** * Hilfsklasse zum Rendern der Uhr. * @param layout Layout-Objekt, das gerendert werden soll. diff --git a/test/test.html b/test/test.html index 74b56da..8b3df81 100644 --- a/test/test.html +++ b/test/test.html @@ -5,8 +5,12 @@ Test - + + + + + @@ -14,6 +18,9 @@ + + +
@@ -21,7 +28,7 @@