From 448747626cefcf2a151b1356e97dc59070207fdb Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 28 Jun 2014 13:56:20 +0200 Subject: [PATCH] make auto-detection more robust and include a fallback if cookie or config doesn't match available themes --- uhr.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/uhr.js b/uhr.js index d842352..a2e4e46 100644 --- a/uhr.js +++ b/uhr.js @@ -37,6 +37,10 @@ along with this program. If not, see . window._uhr.themes.push({'class': styleClass, 'name': name}); } } + // fall-back if no theme was included + if (window._uhr.themes.length == 0) { + window._uhr.themes.push({}); + } $.widget("fritteli.uhr", { options: { width: '100%', @@ -292,6 +296,19 @@ along with this program. If not, see . if (selectedTheme == undefined || this.options.force) { selectedTheme = this.options.theme; } + var found = false; + for (var i = 0; i < window._uhr.themes.length; i++) { + var styleClass = window._uhr.themes[i].class; + if (selectedTheme == styleClass) { + found = true; + break; + } + } + if (!found) { + var fallback = window._uhr.themes[0].class; + console.warn("Theme " + selectedTheme + " not found! Using fallback: " + fallback); + selectedTheme = fallback; + } themeChooser.val(selectedTheme); this.options.theme = ""; this.theme(selectedTheme);