make auto-detection more robust and include a fallback if cookie or config
doesn't match available themes
This commit is contained in:
parent
ae3da935be
commit
448747626c
1 changed files with 17 additions and 0 deletions
17
uhr.js
17
uhr.js
|
@ -37,6 +37,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
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 <http://www.gnu.org/licenses/>.
|
|||
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);
|
||||
|
|
Loading…
Reference in a new issue