From 1bc60d7a1b250be86705d062b08d40a0fb61a98f Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 28 Jun 2014 10:54:28 +0200 Subject: [PATCH] use data-class and data-name attributes on stylesheets to define styleclass and pretty-name of themes --- index.html | 12 ++++++------ uhr.js | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/index.html b/index.html index 92f2665..8e8c9b7 100644 --- a/index.html +++ b/index.html @@ -22,12 +22,12 @@ along with this program. If not, see . - - - - - - + + + + + + diff --git a/uhr.js b/uhr.js index a2f3110..1d00bbb 100644 --- a/uhr.js +++ b/uhr.js @@ -25,12 +25,17 @@ along with this program. If not, see . themes: [] }; // auto-detect themes - var uhrCSSs = $('head link[rel=stylesheet][href^=uhr-]'); - var matcher = /^(.*)uhr-(.+).css$/; - for (var i = 0; i < uhrCSSs.length; i++) { - var name = $(uhrCSSs[i]).attr('href'); - var code = name.match(matcher)[2]; - window._uhr.themes.push(code); + var styleSheets = $('head link[rel=stylesheet]'); + for (var i = 0; i < styleSheets.length; i++) { + var styleSheet = $(styleSheets[i]); + var styleClass = styleSheet.attr('data-class'); + if (styleClass !== undefined) { + var name = styleSheet.attr('data-name'); + if (name === undefined) { + name = styleClass; + } + window._uhr.themes.push({'class': styleClass, 'name': name}); + } } $.widget("fritteli.uhr", { options: { @@ -233,7 +238,7 @@ along with this program. If not, see . var themeChooser = $(''); for (var i = 0; i < window._uhr.themes.length; i++) { var theme = window._uhr.themes[i]; - themeChooser.append(''); + themeChooser.append(''); } e.after(themeChooser); }