diff --git a/dist/jquery.uhr.main.js b/dist/jquery.uhr.main.js index 5936457..1d4d75f 100644 --- a/dist/jquery.uhr.main.js +++ b/dist/jquery.uhr.main.js @@ -1,820 +1,817 @@ -(function () { - 'use strict'; +'use strict'; - /* - 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. +/* + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + 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 . - */ - (function ($) { - var uhrGlobals = { - "id": 0, - "languages": [], - "themes": [], - registerLanguage: function registerLanguage(code, language) { - var alreadyExists = uhrGlobals.languages.some(function (element) { - if (code === element.code) { - console.error("Error: Language code '" + code + "' cannot be registered for language '" + language.language + - "' because it is already registered for language '" + element.language + "'!"); - return true; - } - return false; - }); - if (!alreadyExists) { - language.code = code; - uhrGlobals.languages.push(language); + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +(function ($) { + var uhrGlobals = { + "id": 0, + "languages": [], + "themes": [], + registerLanguage: function registerLanguage(code, language) { + var alreadyExists = uhrGlobals.languages.some(function (element) { + if (code === element.code) { + console.error("Error: Language code '" + code + "' cannot be registered for language '" + language.language + + "' because it is already registered for language '" + element.language + "'!"); + return true; } + return false; + }); + if (!alreadyExists) { + language.code = code; + uhrGlobals.languages.push(language); } - }; - - // auto-detect themes - $('link[rel=stylesheet]').each(function (index, item) { - var styleSheet = $(item); - var styleClass = styleSheet.attr('data-class'); - if (styleClass !== undefined) { - var name = styleSheet.attr('data-name'); - if (name === undefined) { - name = styleClass; - } - uhrGlobals.themes.push({'styleClass': styleClass, 'name': name}); - } - }); - // fall-back if no theme was included - if (uhrGlobals.themes.length === 0) { - uhrGlobals.themes.push({}); } + }; - // public interface methods (exported later) - var setCookie; - var isOn; - var update; - var start = function start() { - if (!isOn.bind(this)()) { - this.timer = window.setInterval(function () { - this.options.time = new Date(); - update.bind(this)(); - }.bind(this), 1000); - update.bind(this)(); - setCookie.bind(this)('uhr-status', 'on'); + // auto-detect themes + $('link[rel=stylesheet]').each(function (index, item) { + var styleSheet = $(item); + var styleClass = styleSheet.attr('data-class'); + if (styleClass !== undefined) { + var name = styleSheet.attr('data-name'); + if (name === undefined) { + name = styleClass; } - }; - var stop = function stop() { - if (isOn.bind(this)()) { - window.clearInterval(this.timer); - this.timer = null; - update.bind(this)(); - setCookie.bind(this)('uhr-status', 'off'); - } - }; - var toggle = function toggle() { - if (isOn.bind(this)()) { - this.stop(); - } else { - this.start(); - } - }; - var language; - - /** - * Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays. - * @param value Der Buchstabe, der Dargestellt werden soll. - * @param style Die CSS-Styleklassen des Buchstabens. - */ - function Letter(value, style) { - var myValue = value; - var myStyle = style || ''; - this.addStyle = function (style) { - if (myStyle === '') { - myStyle = style; - } else { - myStyle += ' ' + style; - } - }; - this.toString = function () { - return '' + myValue + ''; - }; + uhrGlobals.themes.push({'styleClass': styleClass, 'name': name}); } + }); + // fall-back if no theme was included + if (uhrGlobals.themes.length === 0) { + uhrGlobals.themes.push({}); + } - function UhrRendererV2Delegate(layout) { - var vorne0 = { - 3: [2, 3, 4], - 4: [1, 5], - 5: [1, 4, 5], - 6: [1, 3, 5], - 7: [1, 2, 5], - 8: [1, 5], - 9: [2, 3, 4] - }; - var hinten0 = { - 3: [8, 9, 10], - 4: [7, 11], - 5: [7, 10, 11], - 6: [7, 9, 11], - 7: [7, 8, 11], - 8: [7, 11], - 9: [8, 9, 10] - }; - var vorne1 = { - 3: [3], - 4: [2, 3], - 5: [3], - 6: [3], - 7: [3], - 8: [3], - 9: [2, 3, 4] - }; - var hinten1 = { - 3: [9], - 4: [8, 9], - 5: [9], - 6: [9], - 7: [9], - 8: [9], - 9: [8, 9, 10] - }; - var vorne2 = { - 3: [2, 3, 4], - 4: [1, 5], - 5: [5], - 6: [4], - 7: [3], - 8: [2], - 9: [1, 2, 3, 4, 5] - }; - var hinten2 = { - 3: [8, 9, 10], - 4: [7, 11], - 5: [11], - 6: [10], - 7: [9], - 8: [8], - 9: [7, 8, 9, 10, 11] - }; - var vorne3 = { - 3: [1, 2, 3, 4, 5], - 4: [4], - 5: [3], - 6: [4], - 7: [5], - 8: [1, 5], - 9: [2, 3, 4] - }; - var hinten3 = { - 3: [7, 8, 9, 10, 11], - 4: [10], - 5: [9], - 6: [10], - 7: [11], - 8: [7, 11], - 9: [8, 9, 10] - }; - var vorne4 = { - 3: [4], - 4: [3, 4], - 5: [2, 4], - 6: [1, 4], - 7: [1, 2, 3, 4, 5], - 8: [4], - 9: [4] - }; - var hinten4 = { - 3: [10], - 4: [9, 10], - 5: [8, 10], - 6: [7, 10], - 7: [7, 8, 9, 10, 11], - 8: [10], - 9: [10] - }; - var vorne5 = { - 3: [1, 2, 3, 4, 5], - 4: [1], - 5: [1, 2, 3, 4], - 6: [5], - 7: [5], - 8: [1, 5], - 9: [2, 3, 4] - }; - var hinten5 = { - 3: [7, 8, 9, 10, 11], - 4: [7], - 5: [7, 8, 9, 10], - 6: [11], - 7: [11], - 8: [7, 11], - 9: [8, 9, 10] - }; - var hinten6 = { - 3: [9, 10], - 4: [8], - 5: [7], - 6: [7, 8, 9, 10], - 7: [7, 11], - 8: [7, 11], - 9: [8, 9, 10] - }; - var hinten7 = { - 3: [7, 8, 9, 10, 11], - 4: [11], - 5: [10], - 6: [9], - 7: [8], - 8: [8], - 9: [8] - }; - var hinten8 = { - 3: [8, 9, 10], - 4: [7, 11], - 5: [7, 11], - 6: [8, 9, 10], - 7: [7, 11], - 8: [7, 11], - 9: [8, 9, 10] - }; - var hinten9 = { - 3: [8, 9, 10], - 4: [7, 11], - 5: [7, 11], - 6: [8, 9, 10, 11], - 7: [11], - 8: [10], - 9: [8, 9] - }; - var seconds = { - "0": [vorne0, hinten0], - "1": [vorne0, hinten1], - "2": [vorne0, hinten2], - "3": [vorne0, hinten3], - "4": [vorne0, hinten4], - "5": [vorne0, hinten5], - "6": [vorne0, hinten6], - "7": [vorne0, hinten7], - "8": [vorne0, hinten8], - "9": [vorne0, hinten9], - "10": [vorne1, hinten0], - "11": [vorne1, hinten1], - "12": [vorne1, hinten2], - "13": [vorne1, hinten3], - "14": [vorne1, hinten4], - "15": [vorne1, hinten5], - "16": [vorne1, hinten6], - "17": [vorne1, hinten7], - "18": [vorne1, hinten8], - "19": [vorne1, hinten9], - "20": [vorne2, hinten0], - "21": [vorne2, hinten1], - "22": [vorne2, hinten2], - "23": [vorne2, hinten3], - "24": [vorne2, hinten4], - "25": [vorne2, hinten5], - "26": [vorne2, hinten6], - "27": [vorne2, hinten7], - "28": [vorne2, hinten8], - "29": [vorne2, hinten9], - "30": [vorne3, hinten0], - "31": [vorne3, hinten1], - "32": [vorne3, hinten2], - "33": [vorne3, hinten3], - "34": [vorne3, hinten4], - "35": [vorne3, hinten5], - "36": [vorne3, hinten6], - "37": [vorne3, hinten7], - "38": [vorne3, hinten8], - "39": [vorne3, hinten9], - "40": [vorne4, hinten0], - "41": [vorne4, hinten1], - "42": [vorne4, hinten2], - "43": [vorne4, hinten3], - "44": [vorne4, hinten4], - "45": [vorne4, hinten5], - "46": [vorne4, hinten6], - "47": [vorne4, hinten7], - "48": [vorne4, hinten8], - "49": [vorne4, hinten9], - "50": [vorne5, hinten0], - "51": [vorne5, hinten1], - "52": [vorne5, hinten2], - "53": [vorne5, hinten3], - "54": [vorne5, hinten4], - "55": [vorne5, hinten5], - "56": [vorne5, hinten6], - "57": [vorne5, hinten7], - "58": [vorne5, hinten8], - "59": [vorne5, hinten9] - }; - - function parseObject(letters, styleClass, object) { - if (typeof object !== 'undefined' && object !== null) { - Object.keys(object).forEach(function (y) { - var highlightLetters = object[y]; - highlightLetters.forEach(function (x) { - letters[y - 1][x - 1].addStyle(styleClass); - }); - }); - } - } - - function parseArrayOrObject(letters, styleClass, input) { - if (typeof input !== 'undefined' && input !== null) { - if (Array.isArray(input)) { - input.forEach(function (item) { - parseObject(letters, styleClass, item); - }); - } else { - parseObject(letters, styleClass, input); - } - } - } - - function parseTimeDefinition(letters, styleClass, definition) { - if (typeof definition !== 'undefined' && definition !== null) { - Object.keys(definition).forEach(function (listString) { - var array = listString.split(','); - var highlightLetters = definition[listString]; - array.forEach(function (item) { - parseArrayOrObject(letters, styleClass + item, highlightLetters); - }); - }); - } - } - - this.parse = function parse() { - var letters = []; - layout.letters.forEach(function (string) { - var line = []; - for (var c = 0; c < string.length; c++) { - var character = new Letter(string[c]); - line.push(character); - } - letters.push(line); - }); - parseArrayOrObject(letters, 'on', layout.permanent); - if (typeof layout.seconds !== 'undefined' && layout.seconds !== null) { - parseTimeDefinition(letters, 'second', layout.seconds); - } else { - parseTimeDefinition(letters, 'second', seconds); - } - parseTimeDefinition(letters, 'minute', layout.minutes); - parseTimeDefinition(letters, 'hour', layout.hours); - return letters; - }; - } - - /** - * Hilfsklasse zum Rendern der Uhr. - * @param layout Layout-Objekt, das gerendert werden soll. - * @param renderarea Das jQuery-gewrappte HTML-Element, auf dem gerendert werden soll. - */ - function UhrRenderer(layout, renderarea) { - this.render = function render(beforeshow) { - if (layout.parsed === undefined) { - switch (layout.version) { - case 2: - var delegate = new UhrRendererV2Delegate(layout); - var parsedLayout = delegate.parse(); - Object.defineProperty(layout, "parsed", { - "value": parsedLayout, - "writable": false, - "configurable": false - }); - break; - default: - console.warn("Unknown layout version: '" + layout.version + "'"); - return; - } - } - var letters = layout.parsed; - renderarea.fadeOut('fast', function () { - renderarea.empty(); - letters.forEach(function (line, index, array) { - line.forEach(function (letter) { - renderarea.append(letter.toString()); - }); - if (index < array.length - 1) { - renderarea.append('
'); - } - }); - if (typeof beforeshow === 'function') { - beforeshow(); - } - renderarea.fadeIn('fast'); - }); - }; - } - - var setLanguage = function setLanguage(languageKey) { - if (languageKey !== this.options.language) { - this.options.language = languageKey; - var renderer = new UhrRenderer(language.bind(this)(), this.element.find('.letterarea')); - renderer.render.bind(this)(function () { - this.currentMinute = -1; - update.bind(this)(); - }.bind(this)); - setCookie.bind(this)('uhr-language', languageKey); - update.bind(this)(); - } - }; - var setTheme = function setTheme(theme) { - if (theme !== this.options.theme) { - this.element.removeClass(this.options.theme).addClass(theme); - $('#uhr-onoffswitch' + this.id).removeClass(this.options.theme).addClass(theme); - this.options.theme = theme; - setCookie.bind(this)('uhr-theme', theme); - } - }; - var setTime = function setTime(time) { - this.currentMinute = -1; - if (time === null) { + // public interface methods (exported later) + var setCookie; + var isOn; + var update; + var start = function start() { + if (!isOn.bind(this)()) { + this.timer = window.setInterval(function () { this.options.time = new Date(); - } else { - if (this.timer !== null) { - window.clearInterval(this.timer); - } - this.options.time = time; - } + update.bind(this)(); + }.bind(this), 1000); update.bind(this)(); - }; - var setMode = function (mode) { - this.options.mode = mode; - this.currentMinute = -1; - update.bind(this)(); - setCookie.bind(this)('uhr-mode', mode); - }; - var setWidth = function setWidth(width) { - var e = this.element; - e.css('width', width); - var realWidth = e.width(); - e.width(realWidth); - e.height(realWidth); - e.css('font-size', (realWidth / 40) + 'px'); - }; - - // private interface methods - var setupHTML; - var wireFunctionality; - var create = function create() { - this.id = uhrGlobals.id++; + setCookie.bind(this)('uhr-status', 'on'); + } + }; + var stop = function stop() { + if (isOn.bind(this)()) { + window.clearInterval(this.timer); this.timer = null; - this.currentMinute = -1; - var userTime = this.options.time; - var hash, params; - if (this.options.time === undefined) { - this.options.time = new Date(); - } - // parse the URL params - hash = window.location.hash; - if (hash !== undefined && typeof hash === 'string' && hash.charAt(0) === '#') { - hash = hash.substring(1); - hash = decodeURIComponent(hash); - params = hash.split('&'); - params.forEach(function (element) { - var pair = element.split('='); - var key = pair[0]; - var value = pair[1]; - switch (key) { - case 'l': - case 'language': - this.options.language = value; - this.options.force = true; - break; - case 't': - case 'theme': - this.options.theme = value; - this.options.force = true; - break; - case 'm': - case 'mode': - this.options.mode = value; - this.options.force = true; - break; - case 's': - case 'status': - this.options.status = value; - this.options.force = true; - break; - } - }.bind(this)); - } - // end parse the URL params - setupHTML.bind(this)(); - wireFunctionality.bind(this)(); - if (userTime !== undefined) { - this.time(userTime); - } - }; - // private helper methods (not exported) - var toggleConfigScreen = function toggleConfigScreen() { - $('#uhr-controlpanel' + this.id).toggle('fast'); - }; - // set up - setupHTML = function setupHTML() { - var e = this.element; - // Base clock area - e.addClass('uhr'); - e.empty(); - e.append(''); - e.append(''); - e.append(''); - e.append(''); - e.append('
'); - e.append('
'); - setWidth.bind(this)(this.options.width); + update.bind(this)(); + setCookie.bind(this)('uhr-status', 'off'); + } + }; + var toggle = function toggle() { + if (isOn.bind(this)()) { + this.stop(); + } else { + this.start(); + } + }; + var language; - if (this.options.controls) { - var controlpanel = $('
'); - var content = $('
'); - controlpanel.append(content); - // on/off switch - var toggleSwitch = $('
'); - toggleSwitch.append(''); - toggleSwitch.append(''); - content.append(toggleSwitch); - - // time mode switch - var modeSwitch = $('
'); - modeSwitch.append(''); - modeSwitch.append(''); - content.append(modeSwitch); - // language chooser - if (uhrGlobals.languages.length > 1) { - var languageChooser = $(''); - uhrGlobals.languages.forEach(function (item) { - languageChooser.append(''); - }); - content.append(languageChooser); - } - - // theme chooser - if (uhrGlobals.themes.length > 1) { - var themeChooser = $(''); - uhrGlobals.themes.forEach(function (item) { - themeChooser.append(''); - }); - content.append(themeChooser); - } - var closebutton = $(''); - closebutton.on('click', function () { - $('#uhr-controlpanel' + this.id).hide('fast'); - }.bind(this)); - content.append(closebutton); - e.after(controlpanel); - controlpanel.hide(); - var configlink = $(''); - configlink.on('click', function () { - toggleConfigScreen.bind(this)(); - }.bind(this)); - e.after(configlink); - } - }; - wireFunctionality = function wireFunctionality() { - // on/off switch - var toggleSwitch = $('#uhr-onoffswitch-checkbox' + this.id); - toggleSwitch.on('click', function () { - this.toggle(); - }.bind(this)); - var status = $.cookie('uhr-status' + this.id); - if (status === undefined || this.options.force) { - status = this.options.status; - } - toggleSwitch.prop('checked', status === 'on'); - if (status === 'on') { - this.start(); + /** + * Ein Buchstabe. Hilfsklasse für den Renderer und Inhalt der Layout-Arrays. + * @param value Der Buchstabe, der Dargestellt werden soll. + * @param style Die CSS-Styleklassen des Buchstabens. + */ + function Letter(value, style) { + var myValue = value; + var myStyle = style || ''; + this.addStyle = function (style) { + if (myStyle === '') { + myStyle = style; } else { - this.stop(); + myStyle += ' ' + style; } + }; + this.toString = function () { + return '' + myValue + ''; + }; + } + + function UhrRendererV2Delegate(layout) { + var vorne0 = { + 3: [2, 3, 4], + 4: [1, 5], + 5: [1, 4, 5], + 6: [1, 3, 5], + 7: [1, 2, 5], + 8: [1, 5], + 9: [2, 3, 4] + }; + var hinten0 = { + 3: [8, 9, 10], + 4: [7, 11], + 5: [7, 10, 11], + 6: [7, 9, 11], + 7: [7, 8, 11], + 8: [7, 11], + 9: [8, 9, 10] + }; + var vorne1 = { + 3: [3], + 4: [2, 3], + 5: [3], + 6: [3], + 7: [3], + 8: [3], + 9: [2, 3, 4] + }; + var hinten1 = { + 3: [9], + 4: [8, 9], + 5: [9], + 6: [9], + 7: [9], + 8: [9], + 9: [8, 9, 10] + }; + var vorne2 = { + 3: [2, 3, 4], + 4: [1, 5], + 5: [5], + 6: [4], + 7: [3], + 8: [2], + 9: [1, 2, 3, 4, 5] + }; + var hinten2 = { + 3: [8, 9, 10], + 4: [7, 11], + 5: [11], + 6: [10], + 7: [9], + 8: [8], + 9: [7, 8, 9, 10, 11] + }; + var vorne3 = { + 3: [1, 2, 3, 4, 5], + 4: [4], + 5: [3], + 6: [4], + 7: [5], + 8: [1, 5], + 9: [2, 3, 4] + }; + var hinten3 = { + 3: [7, 8, 9, 10, 11], + 4: [10], + 5: [9], + 6: [10], + 7: [11], + 8: [7, 11], + 9: [8, 9, 10] + }; + var vorne4 = { + 3: [4], + 4: [3, 4], + 5: [2, 4], + 6: [1, 4], + 7: [1, 2, 3, 4, 5], + 8: [4], + 9: [4] + }; + var hinten4 = { + 3: [10], + 4: [9, 10], + 5: [8, 10], + 6: [7, 10], + 7: [7, 8, 9, 10, 11], + 8: [10], + 9: [10] + }; + var vorne5 = { + 3: [1, 2, 3, 4, 5], + 4: [1], + 5: [1, 2, 3, 4], + 6: [5], + 7: [5], + 8: [1, 5], + 9: [2, 3, 4] + }; + var hinten5 = { + 3: [7, 8, 9, 10, 11], + 4: [7], + 5: [7, 8, 9, 10], + 6: [11], + 7: [11], + 8: [7, 11], + 9: [8, 9, 10] + }; + var hinten6 = { + 3: [9, 10], + 4: [8], + 5: [7], + 6: [7, 8, 9, 10], + 7: [7, 11], + 8: [7, 11], + 9: [8, 9, 10] + }; + var hinten7 = { + 3: [7, 8, 9, 10, 11], + 4: [11], + 5: [10], + 6: [9], + 7: [8], + 8: [8], + 9: [8] + }; + var hinten8 = { + 3: [8, 9, 10], + 4: [7, 11], + 5: [7, 11], + 6: [8, 9, 10], + 7: [7, 11], + 8: [7, 11], + 9: [8, 9, 10] + }; + var hinten9 = { + 3: [8, 9, 10], + 4: [7, 11], + 5: [7, 11], + 6: [8, 9, 10, 11], + 7: [11], + 8: [10], + 9: [8, 9] + }; + var seconds = { + "0": [vorne0, hinten0], + "1": [vorne0, hinten1], + "2": [vorne0, hinten2], + "3": [vorne0, hinten3], + "4": [vorne0, hinten4], + "5": [vorne0, hinten5], + "6": [vorne0, hinten6], + "7": [vorne0, hinten7], + "8": [vorne0, hinten8], + "9": [vorne0, hinten9], + "10": [vorne1, hinten0], + "11": [vorne1, hinten1], + "12": [vorne1, hinten2], + "13": [vorne1, hinten3], + "14": [vorne1, hinten4], + "15": [vorne1, hinten5], + "16": [vorne1, hinten6], + "17": [vorne1, hinten7], + "18": [vorne1, hinten8], + "19": [vorne1, hinten9], + "20": [vorne2, hinten0], + "21": [vorne2, hinten1], + "22": [vorne2, hinten2], + "23": [vorne2, hinten3], + "24": [vorne2, hinten4], + "25": [vorne2, hinten5], + "26": [vorne2, hinten6], + "27": [vorne2, hinten7], + "28": [vorne2, hinten8], + "29": [vorne2, hinten9], + "30": [vorne3, hinten0], + "31": [vorne3, hinten1], + "32": [vorne3, hinten2], + "33": [vorne3, hinten3], + "34": [vorne3, hinten4], + "35": [vorne3, hinten5], + "36": [vorne3, hinten6], + "37": [vorne3, hinten7], + "38": [vorne3, hinten8], + "39": [vorne3, hinten9], + "40": [vorne4, hinten0], + "41": [vorne4, hinten1], + "42": [vorne4, hinten2], + "43": [vorne4, hinten3], + "44": [vorne4, hinten4], + "45": [vorne4, hinten5], + "46": [vorne4, hinten6], + "47": [vorne4, hinten7], + "48": [vorne4, hinten8], + "49": [vorne4, hinten9], + "50": [vorne5, hinten0], + "51": [vorne5, hinten1], + "52": [vorne5, hinten2], + "53": [vorne5, hinten3], + "54": [vorne5, hinten4], + "55": [vorne5, hinten5], + "56": [vorne5, hinten6], + "57": [vorne5, hinten7], + "58": [vorne5, hinten8], + "59": [vorne5, hinten9] + }; + + function parseObject(letters, styleClass, object) { + if (typeof object !== 'undefined' && object !== null) { + Object.keys(object).forEach(function (y) { + var highlightLetters = object[y]; + highlightLetters.forEach(function (x) { + letters[y - 1][x - 1].addStyle(styleClass); + }); + }); + } + } + + function parseArrayOrObject(letters, styleClass, input) { + if (typeof input !== 'undefined' && input !== null) { + if (Array.isArray(input)) { + input.forEach(function (item) { + parseObject(letters, styleClass, item); + }); + } else { + parseObject(letters, styleClass, input); + } + } + } + + function parseTimeDefinition(letters, styleClass, definition) { + if (typeof definition !== 'undefined' && definition !== null) { + Object.keys(definition).forEach(function (listString) { + var array = listString.split(','); + var highlightLetters = definition[listString]; + array.forEach(function (item) { + parseArrayOrObject(letters, styleClass + item, highlightLetters); + }); + }); + } + } + + this.parse = function parse() { + var letters = []; + layout.letters.forEach(function (string) { + var line = []; + for (var c = 0; c < string.length; c++) { + var character = new Letter(string[c]); + line.push(character); + } + letters.push(line); + }); + parseArrayOrObject(letters, 'on', layout.permanent); + if (typeof layout.seconds !== 'undefined' && layout.seconds !== null) { + parseTimeDefinition(letters, 'second', layout.seconds); + } else { + parseTimeDefinition(letters, 'second', seconds); + } + parseTimeDefinition(letters, 'minute', layout.minutes); + parseTimeDefinition(letters, 'hour', layout.hours); + return letters; + }; + } + + /** + * Hilfsklasse zum Rendern der Uhr. + * @param layout Layout-Objekt, das gerendert werden soll. + * @param renderarea Das jQuery-gewrappte HTML-Element, auf dem gerendert werden soll. + */ + function UhrRenderer(layout, renderarea) { + this.render = function render(beforeshow) { + if (layout.parsed === undefined) { + switch (layout.version) { + case 2: + var delegate = new UhrRendererV2Delegate(layout); + var parsedLayout = delegate.parse(); + Object.defineProperty(layout, "parsed", { + "value": parsedLayout, + "writable": false, + "configurable": false + }); + break; + default: + console.warn("Unknown layout version: '" + layout.version + "'"); + return; + } + } + var letters = layout.parsed; + renderarea.fadeOut('fast', function () { + renderarea.empty(); + letters.forEach(function (line, index, array) { + line.forEach(function (letter) { + renderarea.append(letter.toString()); + }); + if (index < array.length - 1) { + renderarea.append('
'); + } + }); + if (typeof beforeshow === 'function') { + beforeshow(); + } + renderarea.fadeIn('fast'); + }); + }; + } + + var setLanguage = function setLanguage(languageKey) { + if (languageKey !== this.options.language) { + this.options.language = languageKey; + var renderer = new UhrRenderer(language.bind(this)(), this.element.find('.letterarea')); + renderer.render.bind(this)(function () { + this.currentMinute = -1; + update.bind(this)(); + }.bind(this)); + setCookie.bind(this)('uhr-language', languageKey); + update.bind(this)(); + } + }; + var setTheme = function setTheme(theme) { + if (theme !== this.options.theme) { + this.element.removeClass(this.options.theme).addClass(theme); + $('#uhr-onoffswitch' + this.id).removeClass(this.options.theme).addClass(theme); + this.options.theme = theme; + setCookie.bind(this)('uhr-theme', theme); + } + }; + var setTime = function setTime(time) { + this.currentMinute = -1; + if (time === null) { + this.options.time = new Date(); + } else { + if (this.timer !== null) { + window.clearInterval(this.timer); + } + this.options.time = time; + } + update.bind(this)(); + }; + var setMode = function (mode) { + this.options.mode = mode; + this.currentMinute = -1; + update.bind(this)(); + setCookie.bind(this)('uhr-mode', mode); + }; + var setWidth = function setWidth(width) { + var e = this.element; + e.css('width', width); + var realWidth = e.width(); + e.width(realWidth); + e.height(realWidth); + e.css('font-size', (realWidth / 40) + 'px'); + }; + + // private interface methods + var setupHTML; + var wireFunctionality; + var create = function create() { + this.id = uhrGlobals.id++; + this.timer = null; + this.currentMinute = -1; + var userTime = this.options.time; + var hash, params; + if (this.options.time === undefined) { + this.options.time = new Date(); + } + // parse the URL params + hash = window.location.hash; + if (hash !== undefined && typeof hash === 'string' && hash.charAt(0) === '#') { + hash = hash.substring(1); + hash = decodeURIComponent(hash); + params = hash.split('&'); + params.forEach(function (element) { + var pair = element.split('='); + var key = pair[0]; + var value = pair[1]; + switch (key) { + case 'l': + case 'language': + this.options.language = value; + this.options.force = true; + break; + case 't': + case 'theme': + this.options.theme = value; + this.options.force = true; + break; + case 'm': + case 'mode': + this.options.mode = value; + this.options.force = true; + break; + case 's': + case 'status': + this.options.status = value; + this.options.force = true; + break; + } + }.bind(this)); + } + // end parse the URL params + setupHTML.bind(this)(); + wireFunctionality.bind(this)(); + if (userTime !== undefined) { + this.time(userTime); + } + }; + // private helper methods (not exported) + var toggleConfigScreen = function toggleConfigScreen() { + $('#uhr-controlpanel' + this.id).toggle('fast'); + }; + // set up + setupHTML = function setupHTML() { + var e = this.element; + // Base clock area + e.addClass('uhr'); + e.empty(); + e.append(''); + e.append(''); + e.append(''); + e.append(''); + e.append('
'); + e.append('
'); + setWidth.bind(this)(this.options.width); + + if (this.options.controls) { + var controlpanel = $('
'); + var content = $('
'); + controlpanel.append(content); + // on/off switch + var toggleSwitch = $('
'); + toggleSwitch.append(''); + toggleSwitch.append(''); + content.append(toggleSwitch); // time mode switch - var modeSwitch = $('#uhr-modeswitch-checkbox' + this.id); - modeSwitch.on('click', function () { - if (this.options.mode === 'seconds') { - setMode.bind(this)('normal'); - } else { - setMode.bind(this)('seconds'); - } - }.bind(this)); - - var mode = $.cookie('uhr-mode' + this.id); - if (mode === undefined || this.options.force) { - mode = this.options.mode; - } - modeSwitch.prop('checked', mode !== 'seconds'); - if (mode === 'seconds') { - setMode.bind(this)('seconds'); - } else { - setMode.bind(this)('normal'); - } - + var modeSwitch = $('
'); + modeSwitch.append(''); + modeSwitch.append(''); + content.append(modeSwitch); // language chooser - var languageChooser = $('#uhr-languagechooser' + this.id); - languageChooser.on('change', function () { - var languageKey = $('#uhr-languagechooser' + this.id).val(); - this.language(languageKey); - }.bind(this)); - var selectedLanguage = $.cookie('uhr-language' + this.id); - if (selectedLanguage === undefined || this.options.force) { - selectedLanguage = this.options.language; + if (uhrGlobals.languages.length > 1) { + var languageChooser = $(''); + uhrGlobals.languages.forEach(function (item) { + languageChooser.append(''); + }); + content.append(languageChooser); } - var found = uhrGlobals.languages.some(function (item) { - return selectedLanguage === item.code; - }); - if (!found) { - var fallbackLanguage; - if (uhrGlobals.languages.length > 0) { - fallbackLanguage = uhrGlobals.languages[0].code; - } else { - fallbackLanguage = ''; - } - console.warn("Language '" + selectedLanguage + "' not found! Using fallback '" + fallbackLanguage + "'"); - selectedLanguage = fallbackLanguage; - } - languageChooser.val(selectedLanguage); - this.options.language = ""; - this.language(selectedLanguage); // theme chooser - var themeChooser = $('#uhr-themechooser' + this.id); - themeChooser.on('change', function () { - var themeKey = $('#uhr-themechooser' + this.id).val(); - this.theme(themeKey); + if (uhrGlobals.themes.length > 1) { + var themeChooser = $(''); + uhrGlobals.themes.forEach(function (item) { + themeChooser.append(''); + }); + content.append(themeChooser); + } + var closebutton = $(''); + closebutton.on('click', function () { + $('#uhr-controlpanel' + this.id).hide('fast'); }.bind(this)); - var selectedTheme = $.cookie('uhr-theme' + this.id); - if (selectedTheme === undefined || this.options.force) { - selectedTheme = this.options.theme; - } - found = uhrGlobals.themes.some(function (item) { - return selectedTheme === item.styleClass; - }); - if (!found) { - var fallbackTheme = uhrGlobals.themes[0].styleClass; - console.warn("Theme '" + selectedTheme + "' not found! Using fallback '" + fallbackTheme + "'"); - selectedTheme = fallbackTheme; - } - themeChooser.val(selectedTheme); - this.options.theme = ""; - this.theme(selectedTheme); - if (this.options.autoresize) { - $(window).on('resize', function () { - var $e = this.element; - var $parent = $e.parent(); - var $window = $(window); - var parentWidth = $parent.width(); - var parentHeight = $parent.height(); - var windowWidth = $window.width(); - var windowHeight = $window.height(); - var size = Math.min(parentWidth, parentHeight, windowWidth, windowHeight) + 'px'; - setWidth.bind(this)(size); - }.bind(this)); - } - }; - var destroy = function destroy() { - this.timer = null; - $(this.element) - .removeAttr('style') - .removeAttr('class') - .empty(); - $('#uhr-configlink' + this.id).remove(); - $('#uhr-controlpanel' + this.id).remove(); + content.append(closebutton); + e.after(controlpanel); + controlpanel.hide(); + var configlink = $(''); + configlink.on('click', function () { + toggleConfigScreen.bind(this)(); + }.bind(this)); + e.after(configlink); + } + }; + wireFunctionality = function wireFunctionality() { + // on/off switch + var toggleSwitch = $('#uhr-onoffswitch-checkbox' + this.id); + toggleSwitch.on('click', function () { + this.toggle(); + }.bind(this)); + var status = $.cookie('uhr-status' + this.id); + if (status === undefined || this.options.force) { + status = this.options.status; + } + toggleSwitch.prop('checked', status === 'on'); + if (status === 'on') { + this.start(); + } else { + this.stop(); + } - }; - setCookie = function setCookie(cookieName, cookieValue) { - var options = {}; - if (this.options.cookiePath !== undefined) { - options = {expires: 365, path: this.options.cookiePath}; - } else { - options = {expires: 365}; - } - $.cookie(cookieName + this.id, cookieValue, options); - }; - - // business logic - isOn = function isOn() { - return this.timer !== null; - }; - var show; - var clear; - update = function update() { - if (isOn.bind(this)()) { - var time = this.options.time; - if (!language.bind(this)().hasOwnProperty('seconds') && this.options.mode !== 'seconds') { - if (time.getMinutes() === this.currentMinute) { - return; - } - this.currentMinute = time.getMinutes(); - } - show.bind(this)(time); - } else { - clear.bind(this)(); - this.currentMinute = -1; - } - }; - var highlight; - var getSecond; - var getDotMinute; - var getCoarseMinute; - var getHour; - show = function show(time) { - var second = getSecond.bind(this)(time); - var dotMinute = getDotMinute.bind(this)(time); - var hour = getHour.bind(this)(time); - var coarseMinute = getCoarseMinute.bind(this)(time); - clear.bind(this)(); + // time mode switch + var modeSwitch = $('#uhr-modeswitch-checkbox' + this.id); + modeSwitch.on('click', function () { if (this.options.mode === 'seconds') { - highlight.bind(this)('second' + second); + setMode.bind(this)('normal'); } else { - highlight.bind(this)('on'); - for (var i = 1; i <= dotMinute; i++) { - highlight.bind(this)('dot' + i); - } - highlight.bind(this)('minute' + coarseMinute); - highlight.bind(this)('hour' + hour); + setMode.bind(this)('seconds'); } - }; - highlight = function highlight(itemClass) { - this.element.find('.item.' + itemClass).addClass('active'); - }; - clear = function clear() { - this.element.find('.item').removeClass('active'); - }; - getSecond = function getSecond(date) { - if (typeof language.bind(this)().getSeconds === 'function') { - return language.bind(this)().getSeconds(date); - } - return date.getSeconds(); - }; - getDotMinute = function getDotMinute(date) { - if (typeof language.bind(this)().getDotMinute === 'function') { - return language.bind(this)().getDotMinute(date); - } - var minutes = date.getMinutes(); - return minutes % 5; - }; - getCoarseMinute = function getCoarseMinute(date) { - if (typeof language.bind(this)().getCoarseMinute === 'function') { - return language.bind(this)().getCoarseMinute(date); - } - return date.getMinutes(); - }; - getHour = function getHour(date) { - if (typeof language.bind(this)().getHour === 'function') { - return language.bind(this)().getHour(date); - } - var hour = date.getHours(); - if (date.getMinutes() >= 25) { - return (hour + 1) % 24; - } - return hour; - }; - language = function language() { - var matchingLanguages = uhrGlobals.languages.filter(function (element) { - return (element.code === this.options.language); - }, this); - if (matchingLanguages.length > 0) { - return matchingLanguages[0]; - } - // fallback: return empty object - return {}; - }; + }.bind(this)); - $.widget("fritteli.uhr", { - "options": { - width: '100%', - status: 'on', - language: 'de_CH', - theme: uhrGlobals.themes[0].styleClass, - force: false, - controls: true, - cookiePath: undefined, - autoresize: true, - mode: 'normal' - }, - "start": start, - "stop": stop, - "toggle": toggle, - "language": setLanguage, - "theme": setTheme, - "time": setTime, - "mode": setMode, - "width": setWidth, - // constructor method - "_create": create, - // destructor method - "_destroy": destroy + var mode = $.cookie('uhr-mode' + this.id); + if (mode === undefined || this.options.force) { + mode = this.options.mode; + } + modeSwitch.prop('checked', mode !== 'seconds'); + if (mode === 'seconds') { + setMode.bind(this)('seconds'); + } else { + setMode.bind(this)('normal'); + } + + // language chooser + var languageChooser = $('#uhr-languagechooser' + this.id); + languageChooser.on('change', function () { + var languageKey = $('#uhr-languagechooser' + this.id).val(); + this.language(languageKey); + }.bind(this)); + var selectedLanguage = $.cookie('uhr-language' + this.id); + if (selectedLanguage === undefined || this.options.force) { + selectedLanguage = this.options.language; + } + var found = uhrGlobals.languages.some(function (item) { + return selectedLanguage === item.code; }); - $.fritteli.uhr.register = uhrGlobals.registerLanguage; - })(jQuery); + if (!found) { + var fallbackLanguage; + if (uhrGlobals.languages.length > 0) { + fallbackLanguage = uhrGlobals.languages[0].code; + } else { + fallbackLanguage = ''; + } + console.warn("Language '" + selectedLanguage + "' not found! Using fallback '" + fallbackLanguage + "'"); + selectedLanguage = fallbackLanguage; + } + languageChooser.val(selectedLanguage); + this.options.language = ""; + this.language(selectedLanguage); -}()); + // theme chooser + var themeChooser = $('#uhr-themechooser' + this.id); + themeChooser.on('change', function () { + var themeKey = $('#uhr-themechooser' + this.id).val(); + this.theme(themeKey); + }.bind(this)); + var selectedTheme = $.cookie('uhr-theme' + this.id); + if (selectedTheme === undefined || this.options.force) { + selectedTheme = this.options.theme; + } + found = uhrGlobals.themes.some(function (item) { + return selectedTheme === item.styleClass; + }); + if (!found) { + var fallbackTheme = uhrGlobals.themes[0].styleClass; + console.warn("Theme '" + selectedTheme + "' not found! Using fallback '" + fallbackTheme + "'"); + selectedTheme = fallbackTheme; + } + themeChooser.val(selectedTheme); + this.options.theme = ""; + this.theme(selectedTheme); + if (this.options.autoresize) { + $(window).on('resize', function () { + var $e = this.element; + var $parent = $e.parent(); + var $window = $(window); + var parentWidth = $parent.width(); + var parentHeight = $parent.height(); + var windowWidth = $window.width(); + var windowHeight = $window.height(); + var size = Math.min(parentWidth, parentHeight, windowWidth, windowHeight) + 'px'; + setWidth.bind(this)(size); + }.bind(this)); + } + }; + var destroy = function destroy() { + this.timer = null; + $(this.element) + .removeAttr('style') + .removeAttr('class') + .empty(); + $('#uhr-configlink' + this.id).remove(); + $('#uhr-controlpanel' + this.id).remove(); + + }; + setCookie = function setCookie(cookieName, cookieValue) { + var options = {}; + if (this.options.cookiePath !== undefined) { + options = {expires: 365, path: this.options.cookiePath}; + } else { + options = {expires: 365}; + } + $.cookie(cookieName + this.id, cookieValue, options); + }; + + // business logic + isOn = function isOn() { + return this.timer !== null; + }; + var show; + var clear; + update = function update() { + if (isOn.bind(this)()) { + var time = this.options.time; + if (!language.bind(this)().hasOwnProperty('seconds') && this.options.mode !== 'seconds') { + if (time.getMinutes() === this.currentMinute) { + return; + } + this.currentMinute = time.getMinutes(); + } + show.bind(this)(time); + } else { + clear.bind(this)(); + this.currentMinute = -1; + } + }; + var highlight; + var getSecond; + var getDotMinute; + var getCoarseMinute; + var getHour; + show = function show(time) { + var second = getSecond.bind(this)(time); + var dotMinute = getDotMinute.bind(this)(time); + var hour = getHour.bind(this)(time); + var coarseMinute = getCoarseMinute.bind(this)(time); + clear.bind(this)(); + if (this.options.mode === 'seconds') { + highlight.bind(this)('second' + second); + } else { + highlight.bind(this)('on'); + for (var i = 1; i <= dotMinute; i++) { + highlight.bind(this)('dot' + i); + } + highlight.bind(this)('minute' + coarseMinute); + highlight.bind(this)('hour' + hour); + } + }; + highlight = function highlight(itemClass) { + this.element.find('.item.' + itemClass).addClass('active'); + }; + clear = function clear() { + this.element.find('.item').removeClass('active'); + }; + getSecond = function getSecond(date) { + if (typeof language.bind(this)().getSeconds === 'function') { + return language.bind(this)().getSeconds(date); + } + return date.getSeconds(); + }; + getDotMinute = function getDotMinute(date) { + if (typeof language.bind(this)().getDotMinute === 'function') { + return language.bind(this)().getDotMinute(date); + } + var minutes = date.getMinutes(); + return minutes % 5; + }; + getCoarseMinute = function getCoarseMinute(date) { + if (typeof language.bind(this)().getCoarseMinute === 'function') { + return language.bind(this)().getCoarseMinute(date); + } + return date.getMinutes(); + }; + getHour = function getHour(date) { + if (typeof language.bind(this)().getHour === 'function') { + return language.bind(this)().getHour(date); + } + var hour = date.getHours(); + if (date.getMinutes() >= 25) { + return (hour + 1) % 24; + } + return hour; + }; + language = function language() { + var matchingLanguages = uhrGlobals.languages.filter(function (element) { + return (element.code === this.options.language); + }, this); + if (matchingLanguages.length > 0) { + return matchingLanguages[0]; + } + // fallback: return empty object + return {}; + }; + + $.widget("fritteli.uhr", { + "options": { + width: '100%', + status: 'on', + language: 'de_CH', + theme: uhrGlobals.themes[0].styleClass, + force: false, + controls: true, + cookiePath: undefined, + autoresize: true, + mode: 'normal' + }, + "start": start, + "stop": stop, + "toggle": toggle, + "language": setLanguage, + "theme": setTheme, + "time": setTime, + "mode": setMode, + "width": setWidth, + // constructor method + "_create": create, + // destructor method + "_destroy": destroy + }); + $.fritteli.uhr.register = uhrGlobals.registerLanguage; +})(jQuery); diff --git a/dist/jquery.uhr.main.min.js b/dist/jquery.uhr.main.min.js index c415152..7d985f6 100644 --- a/dist/jquery.uhr.main.min.js +++ b/dist/jquery.uhr.main.min.js @@ -1 +1 @@ -!function(){"use strict";!function(t){var i,e,n,s={id:0,languages:[],themes:[],registerLanguage:function(t,i){s.languages.some((function(e){return t===e.code&&(console.error("Error: Language code '"+t+"' cannot be registered for language '"+i.language+"' because it is already registered for language '"+e.language+"'!"),!0)}))||(i.code=t,s.languages.push(i))}};t("link[rel=stylesheet]").each((function(i,e){var n=t(e),o=n.attr("data-class");if(void 0!==o){var h=n.attr("data-name");void 0===h&&(h=o),s.themes.push({styleClass:o,name:h})}})),0===s.themes.length&&s.themes.push({});var o;function h(t,i){var e=t,n=i||"";this.addStyle=function(t){""===n?n=t:n+=" "+t},this.toString=function(){return''+e+""}}function a(t){var i={3:[2,3,4],4:[1,5],5:[1,4,5],6:[1,3,5],7:[1,2,5],8:[1,5],9:[2,3,4]},e={3:[8,9,10],4:[7,11],5:[7,10,11],6:[7,9,11],7:[7,8,11],8:[7,11],9:[8,9,10]},n={3:[3],4:[2,3],5:[3],6:[3],7:[3],8:[3],9:[2,3,4]},s={3:[9],4:[8,9],5:[9],6:[9],7:[9],8:[9],9:[8,9,10]},o={3:[2,3,4],4:[1,5],5:[5],6:[4],7:[3],8:[2],9:[1,2,3,4,5]},a={3:[8,9,10],4:[7,11],5:[11],6:[10],7:[9],8:[8],9:[7,8,9,10,11]},r={3:[1,2,3,4,5],4:[4],5:[3],6:[4],7:[5],8:[1,5],9:[2,3,4]},c={3:[7,8,9,10,11],4:[10],5:[9],6:[10],7:[11],8:[7,11],9:[8,9,10]},d={3:[4],4:[3,4],5:[2,4],6:[1,4],7:[1,2,3,4,5],8:[4],9:[4]},u={3:[10],4:[9,10],5:[8,10],6:[7,10],7:[7,8,9,10,11],8:[10],9:[10]},l={3:[1,2,3,4,5],4:[1],5:[1,2,3,4],6:[5],7:[5],8:[1,5],9:[2,3,4]},f={3:[7,8,9,10,11],4:[7],5:[7,8,9,10],6:[11],7:[11],8:[7,11],9:[8,9,10]},p={3:[9,10],4:[8],5:[7],6:[7,8,9,10],7:[7,11],8:[7,11],9:[8,9,10]},g={3:[7,8,9,10,11],4:[11],5:[10],6:[9],7:[8],8:[8],9:[8]},m={3:[8,9,10],4:[7,11],5:[7,11],6:[8,9,10],7:[7,11],8:[7,11],9:[8,9,10]},v={3:[8,9,10],4:[7,11],5:[7,11],6:[8,9,10,11],7:[11],8:[10],9:[8,9]},b={0:[i,e],1:[i,s],2:[i,a],3:[i,c],4:[i,u],5:[i,f],6:[i,p],7:[i,g],8:[i,m],9:[i,v],10:[n,e],11:[n,s],12:[n,a],13:[n,c],14:[n,u],15:[n,f],16:[n,p],17:[n,g],18:[n,m],19:[n,v],20:[o,e],21:[o,s],22:[o,a],23:[o,c],24:[o,u],25:[o,f],26:[o,p],27:[o,g],28:[o,m],29:[o,v],30:[r,e],31:[r,s],32:[r,a],33:[r,c],34:[r,u],35:[r,f],36:[r,p],37:[r,g],38:[r,m],39:[r,v],40:[d,e],41:[d,s],42:[d,a],43:[d,c],44:[d,u],45:[d,f],46:[d,p],47:[d,g],48:[d,m],49:[d,v],50:[l,e],51:[l,s],52:[l,a],53:[l,c],54:[l,u],55:[l,f],56:[l,p],57:[l,g],58:[l,m],59:[l,v]};function w(t,i,e){null!=e&&Object.keys(e).forEach((function(n){e[n].forEach((function(e){t[n-1][e-1].addStyle(i)}))}))}function k(t,i,e){null!=e&&(Array.isArray(e)?e.forEach((function(e){w(t,i,e)})):w(t,i,e))}function y(t,i,e){null!=e&&Object.keys(e).forEach((function(n){var s=n.split(","),o=e[n];s.forEach((function(e){k(t,i+e,o)}))}))}this.parse=function(){var i=[];return t.letters.forEach((function(t){for(var e=[],n=0;n")})),"function"==typeof e&&e(),i.fadeIn("fast")}))}}var c,d,u=function(t){this.options.mode=t,this.currentMinute=-1,n.bind(this)(),i.bind(this)("uhr-mode",t)},l=function(t){var i=this.element;i.css("width",t);var e=i.width();i.width(e),i.height(e),i.css("font-size",e/40+"px")},f=function(){t("#uhr-controlpanel"+this.id).toggle("fast")};c=function(){var i=this.element;if(i.addClass("uhr"),i.empty(),i.append(''),i.append(''),i.append(''),i.append(''),i.append('
'),i.append('
'),l.bind(this)(this.options.width),this.options.controls){var e=t('
'),n=t('
');e.append(n);var o=t('
');o.append(''),o.append(''),n.append(o);var h=t('
');if(h.append(''),h.append(''),n.append(h),s.languages.length>1){var a=t('');s.languages.forEach((function(t){a.append('")})),n.append(a)}if(s.themes.length>1){var r=t('');s.themes.forEach((function(t){r.append('")})),n.append(r)}var c=t('');c.on("click",function(){t("#uhr-controlpanel"+this.id).hide("fast")}.bind(this)),n.append(c),i.after(e),e.hide();var d=t('');d.on("click",function(){f.bind(this)()}.bind(this)),i.after(d)}},d=function(){var i=t("#uhr-onoffswitch-checkbox"+this.id);i.on("click",function(){this.toggle()}.bind(this));var e=t.cookie("uhr-status"+this.id);(void 0===e||this.options.force)&&(e=this.options.status),i.prop("checked","on"===e),"on"===e?this.start():this.stop();var n=t("#uhr-modeswitch-checkbox"+this.id);n.on("click",function(){"seconds"===this.options.mode?u.bind(this)("normal"):u.bind(this)("seconds")}.bind(this));var o=t.cookie("uhr-mode"+this.id);(void 0===o||this.options.force)&&(o=this.options.mode),n.prop("checked","seconds"!==o),"seconds"===o?u.bind(this)("seconds"):u.bind(this)("normal");var h=t("#uhr-languagechooser"+this.id);h.on("change",function(){var i=t("#uhr-languagechooser"+this.id).val();this.language(i)}.bind(this));var a=t.cookie("uhr-language"+this.id);(void 0===a||this.options.force)&&(a=this.options.language);var r,c=s.languages.some((function(t){return a===t.code}));c||(r=s.languages.length>0?s.languages[0].code:"",console.warn("Language '"+a+"' not found! Using fallback '"+r+"'"),a=r);h.val(a),this.options.language="",this.language(a);var d=t("#uhr-themechooser"+this.id);d.on("change",function(){var i=t("#uhr-themechooser"+this.id).val();this.theme(i)}.bind(this));var f=t.cookie("uhr-theme"+this.id);if((void 0===f||this.options.force)&&(f=this.options.theme),!(c=s.themes.some((function(t){return f===t.styleClass})))){var p=s.themes[0].styleClass;console.warn("Theme '"+f+"' not found! Using fallback '"+p+"'"),f=p}d.val(f),this.options.theme="",this.theme(f),this.options.autoresize&&t(window).on("resize",function(){var i=this.element.parent(),e=t(window),n=i.width(),s=i.height(),o=e.width(),h=e.height(),a=Math.min(n,s,o,h)+"px";l.bind(this)(a)}.bind(this))};var p,g,m,v,b,w,k;i=function(i,e){var n={};n=void 0!==this.options.cookiePath?{expires:365,path:this.options.cookiePath}:{expires:365},t.cookie(i+this.id,e,n)},e=function(){return null!==this.timer},n=function(){if(e.bind(this)()){var t=this.options.time;if(!o.bind(this)().hasOwnProperty("seconds")&&"seconds"!==this.options.mode){if(t.getMinutes()===this.currentMinute)return;this.currentMinute=t.getMinutes()}p.bind(this)(t)}else g.bind(this)(),this.currentMinute=-1},p=function(t){var i=v.bind(this)(t),e=b.bind(this)(t),n=k.bind(this)(t),s=w.bind(this)(t);if(g.bind(this)(),"seconds"===this.options.mode)m.bind(this)("second"+i);else{m.bind(this)("on");for(var o=1;o<=e;o++)m.bind(this)("dot"+o);m.bind(this)("minute"+s),m.bind(this)("hour"+n)}},m=function(t){this.element.find(".item."+t).addClass("active")},g=function(){this.element.find(".item").removeClass("active")},v=function(t){return"function"==typeof o.bind(this)().getSeconds?o.bind(this)().getSeconds(t):t.getSeconds()},b=function(t){return"function"==typeof o.bind(this)().getDotMinute?o.bind(this)().getDotMinute(t):t.getMinutes()%5},w=function(t){return"function"==typeof o.bind(this)().getCoarseMinute?o.bind(this)().getCoarseMinute(t):t.getMinutes()},k=function(t){if("function"==typeof o.bind(this)().getHour)return o.bind(this)().getHour(t);var i=t.getHours();return t.getMinutes()>=25?(i+1)%24:i},o=function(){var t=s.languages.filter((function(t){return t.code===this.options.language}),this);return t.length>0?t[0]:{}},t.widget("fritteli.uhr",{options:{width:"100%",status:"on",language:"de_CH",theme:s.themes[0].styleClass,force:!1,controls:!0,cookiePath:void 0,autoresize:!0,mode:"normal"},start:function(){e.bind(this)()||(this.timer=window.setInterval(function(){this.options.time=new Date,n.bind(this)()}.bind(this),1e3),n.bind(this)(),i.bind(this)("uhr-status","on"))},stop:function(){e.bind(this)()&&(window.clearInterval(this.timer),this.timer=null,n.bind(this)(),i.bind(this)("uhr-status","off"))},toggle:function(){e.bind(this)()?this.stop():this.start()},language:function(t){t!==this.options.language&&(this.options.language=t,new r(o.bind(this)(),this.element.find(".letterarea")).render.bind(this)(function(){this.currentMinute=-1,n.bind(this)()}.bind(this)),i.bind(this)("uhr-language",t),n.bind(this)())},theme:function(e){e!==this.options.theme&&(this.element.removeClass(this.options.theme).addClass(e),t("#uhr-onoffswitch"+this.id).removeClass(this.options.theme).addClass(e),this.options.theme=e,i.bind(this)("uhr-theme",e))},time:function(t){this.currentMinute=-1,null===t?this.options.time=new Date:(null!==this.timer&&window.clearInterval(this.timer),this.options.time=t),n.bind(this)()},mode:u,width:l,_create:function(){this.id=s.id++,this.timer=null,this.currentMinute=-1;var t,i=this.options.time;void 0===this.options.time&&(this.options.time=new Date),void 0!==(t=window.location.hash)&&"string"==typeof t&&"#"===t.charAt(0)&&(t=t.substring(1),(t=decodeURIComponent(t)).split("&").forEach(function(t){var i=t.split("="),e=i[0],n=i[1];switch(e){case"l":case"language":this.options.language=n,this.options.force=!0;break;case"t":case"theme":this.options.theme=n,this.options.force=!0;break;case"m":case"mode":this.options.mode=n,this.options.force=!0;break;case"s":case"status":this.options.status=n,this.options.force=!0}}.bind(this))),c.bind(this)(),d.bind(this)(),void 0!==i&&this.time(i)},_destroy:function(){this.timer=null,t(this.element).removeAttr("style").removeAttr("class").empty(),t("#uhr-configlink"+this.id).remove(),t("#uhr-controlpanel"+this.id).remove()}}),t.fritteli.uhr.register=s.registerLanguage}(jQuery)}(); +"use strict";!function(t){var i,e,n,s={id:0,languages:[],themes:[],registerLanguage:function(t,i){s.languages.some((function(e){return t===e.code&&(console.error("Error: Language code '"+t+"' cannot be registered for language '"+i.language+"' because it is already registered for language '"+e.language+"'!"),!0)}))||(i.code=t,s.languages.push(i))}};t("link[rel=stylesheet]").each((function(i,e){var n=t(e),o=n.attr("data-class");if(void 0!==o){var h=n.attr("data-name");void 0===h&&(h=o),s.themes.push({styleClass:o,name:h})}})),0===s.themes.length&&s.themes.push({});var o;function h(t,i){var e=t,n=i||"";this.addStyle=function(t){""===n?n=t:n+=" "+t},this.toString=function(){return''+e+""}}function a(t){var i={3:[2,3,4],4:[1,5],5:[1,4,5],6:[1,3,5],7:[1,2,5],8:[1,5],9:[2,3,4]},e={3:[8,9,10],4:[7,11],5:[7,10,11],6:[7,9,11],7:[7,8,11],8:[7,11],9:[8,9,10]},n={3:[3],4:[2,3],5:[3],6:[3],7:[3],8:[3],9:[2,3,4]},s={3:[9],4:[8,9],5:[9],6:[9],7:[9],8:[9],9:[8,9,10]},o={3:[2,3,4],4:[1,5],5:[5],6:[4],7:[3],8:[2],9:[1,2,3,4,5]},a={3:[8,9,10],4:[7,11],5:[11],6:[10],7:[9],8:[8],9:[7,8,9,10,11]},r={3:[1,2,3,4,5],4:[4],5:[3],6:[4],7:[5],8:[1,5],9:[2,3,4]},c={3:[7,8,9,10,11],4:[10],5:[9],6:[10],7:[11],8:[7,11],9:[8,9,10]},d={3:[4],4:[3,4],5:[2,4],6:[1,4],7:[1,2,3,4,5],8:[4],9:[4]},u={3:[10],4:[9,10],5:[8,10],6:[7,10],7:[7,8,9,10,11],8:[10],9:[10]},l={3:[1,2,3,4,5],4:[1],5:[1,2,3,4],6:[5],7:[5],8:[1,5],9:[2,3,4]},f={3:[7,8,9,10,11],4:[7],5:[7,8,9,10],6:[11],7:[11],8:[7,11],9:[8,9,10]},p={3:[9,10],4:[8],5:[7],6:[7,8,9,10],7:[7,11],8:[7,11],9:[8,9,10]},g={3:[7,8,9,10,11],4:[11],5:[10],6:[9],7:[8],8:[8],9:[8]},m={3:[8,9,10],4:[7,11],5:[7,11],6:[8,9,10],7:[7,11],8:[7,11],9:[8,9,10]},v={3:[8,9,10],4:[7,11],5:[7,11],6:[8,9,10,11],7:[11],8:[10],9:[8,9]},b={0:[i,e],1:[i,s],2:[i,a],3:[i,c],4:[i,u],5:[i,f],6:[i,p],7:[i,g],8:[i,m],9:[i,v],10:[n,e],11:[n,s],12:[n,a],13:[n,c],14:[n,u],15:[n,f],16:[n,p],17:[n,g],18:[n,m],19:[n,v],20:[o,e],21:[o,s],22:[o,a],23:[o,c],24:[o,u],25:[o,f],26:[o,p],27:[o,g],28:[o,m],29:[o,v],30:[r,e],31:[r,s],32:[r,a],33:[r,c],34:[r,u],35:[r,f],36:[r,p],37:[r,g],38:[r,m],39:[r,v],40:[d,e],41:[d,s],42:[d,a],43:[d,c],44:[d,u],45:[d,f],46:[d,p],47:[d,g],48:[d,m],49:[d,v],50:[l,e],51:[l,s],52:[l,a],53:[l,c],54:[l,u],55:[l,f],56:[l,p],57:[l,g],58:[l,m],59:[l,v]};function w(t,i,e){null!=e&&Object.keys(e).forEach((function(n){e[n].forEach((function(e){t[n-1][e-1].addStyle(i)}))}))}function k(t,i,e){null!=e&&(Array.isArray(e)?e.forEach((function(e){w(t,i,e)})):w(t,i,e))}function y(t,i,e){null!=e&&Object.keys(e).forEach((function(n){var s=n.split(","),o=e[n];s.forEach((function(e){k(t,i+e,o)}))}))}this.parse=function(){var i=[];return t.letters.forEach((function(t){for(var e=[],n=0;n")})),"function"==typeof e&&e(),i.fadeIn("fast")}))}}var c,d,u=function(t){this.options.mode=t,this.currentMinute=-1,n.bind(this)(),i.bind(this)("uhr-mode",t)},l=function(t){var i=this.element;i.css("width",t);var e=i.width();i.width(e),i.height(e),i.css("font-size",e/40+"px")},f=function(){t("#uhr-controlpanel"+this.id).toggle("fast")};c=function(){var i=this.element;if(i.addClass("uhr"),i.empty(),i.append(''),i.append(''),i.append(''),i.append(''),i.append('
'),i.append('
'),l.bind(this)(this.options.width),this.options.controls){var e=t('
'),n=t('
');e.append(n);var o=t('
');o.append(''),o.append(''),n.append(o);var h=t('
');if(h.append(''),h.append(''),n.append(h),s.languages.length>1){var a=t('');s.languages.forEach((function(t){a.append('")})),n.append(a)}if(s.themes.length>1){var r=t('');s.themes.forEach((function(t){r.append('")})),n.append(r)}var c=t('');c.on("click",function(){t("#uhr-controlpanel"+this.id).hide("fast")}.bind(this)),n.append(c),i.after(e),e.hide();var d=t('');d.on("click",function(){f.bind(this)()}.bind(this)),i.after(d)}},d=function(){var i=t("#uhr-onoffswitch-checkbox"+this.id);i.on("click",function(){this.toggle()}.bind(this));var e=t.cookie("uhr-status"+this.id);(void 0===e||this.options.force)&&(e=this.options.status),i.prop("checked","on"===e),"on"===e?this.start():this.stop();var n=t("#uhr-modeswitch-checkbox"+this.id);n.on("click",function(){"seconds"===this.options.mode?u.bind(this)("normal"):u.bind(this)("seconds")}.bind(this));var o=t.cookie("uhr-mode"+this.id);(void 0===o||this.options.force)&&(o=this.options.mode),n.prop("checked","seconds"!==o),"seconds"===o?u.bind(this)("seconds"):u.bind(this)("normal");var h=t("#uhr-languagechooser"+this.id);h.on("change",function(){var i=t("#uhr-languagechooser"+this.id).val();this.language(i)}.bind(this));var a=t.cookie("uhr-language"+this.id);(void 0===a||this.options.force)&&(a=this.options.language);var r,c=s.languages.some((function(t){return a===t.code}));c||(r=s.languages.length>0?s.languages[0].code:"",console.warn("Language '"+a+"' not found! Using fallback '"+r+"'"),a=r);h.val(a),this.options.language="",this.language(a);var d=t("#uhr-themechooser"+this.id);d.on("change",function(){var i=t("#uhr-themechooser"+this.id).val();this.theme(i)}.bind(this));var f=t.cookie("uhr-theme"+this.id);if((void 0===f||this.options.force)&&(f=this.options.theme),!(c=s.themes.some((function(t){return f===t.styleClass})))){var p=s.themes[0].styleClass;console.warn("Theme '"+f+"' not found! Using fallback '"+p+"'"),f=p}d.val(f),this.options.theme="",this.theme(f),this.options.autoresize&&t(window).on("resize",function(){var i=this.element.parent(),e=t(window),n=i.width(),s=i.height(),o=e.width(),h=e.height(),a=Math.min(n,s,o,h)+"px";l.bind(this)(a)}.bind(this))};var p,g,m,v,b,w,k;i=function(i,e){var n={};n=void 0!==this.options.cookiePath?{expires:365,path:this.options.cookiePath}:{expires:365},t.cookie(i+this.id,e,n)},e=function(){return null!==this.timer},n=function(){if(e.bind(this)()){var t=this.options.time;if(!o.bind(this)().hasOwnProperty("seconds")&&"seconds"!==this.options.mode){if(t.getMinutes()===this.currentMinute)return;this.currentMinute=t.getMinutes()}p.bind(this)(t)}else g.bind(this)(),this.currentMinute=-1},p=function(t){var i=v.bind(this)(t),e=b.bind(this)(t),n=k.bind(this)(t),s=w.bind(this)(t);if(g.bind(this)(),"seconds"===this.options.mode)m.bind(this)("second"+i);else{m.bind(this)("on");for(var o=1;o<=e;o++)m.bind(this)("dot"+o);m.bind(this)("minute"+s),m.bind(this)("hour"+n)}},m=function(t){this.element.find(".item."+t).addClass("active")},g=function(){this.element.find(".item").removeClass("active")},v=function(t){return"function"==typeof o.bind(this)().getSeconds?o.bind(this)().getSeconds(t):t.getSeconds()},b=function(t){return"function"==typeof o.bind(this)().getDotMinute?o.bind(this)().getDotMinute(t):t.getMinutes()%5},w=function(t){return"function"==typeof o.bind(this)().getCoarseMinute?o.bind(this)().getCoarseMinute(t):t.getMinutes()},k=function(t){if("function"==typeof o.bind(this)().getHour)return o.bind(this)().getHour(t);var i=t.getHours();return t.getMinutes()>=25?(i+1)%24:i},o=function(){var t=s.languages.filter((function(t){return t.code===this.options.language}),this);return t.length>0?t[0]:{}},t.widget("fritteli.uhr",{options:{width:"100%",status:"on",language:"de_CH",theme:s.themes[0].styleClass,force:!1,controls:!0,cookiePath:void 0,autoresize:!0,mode:"normal"},start:function(){e.bind(this)()||(this.timer=window.setInterval(function(){this.options.time=new Date,n.bind(this)()}.bind(this),1e3),n.bind(this)(),i.bind(this)("uhr-status","on"))},stop:function(){e.bind(this)()&&(window.clearInterval(this.timer),this.timer=null,n.bind(this)(),i.bind(this)("uhr-status","off"))},toggle:function(){e.bind(this)()?this.stop():this.start()},language:function(t){t!==this.options.language&&(this.options.language=t,new r(o.bind(this)(),this.element.find(".letterarea")).render.bind(this)(function(){this.currentMinute=-1,n.bind(this)()}.bind(this)),i.bind(this)("uhr-language",t),n.bind(this)())},theme:function(e){e!==this.options.theme&&(this.element.removeClass(this.options.theme).addClass(e),t("#uhr-onoffswitch"+this.id).removeClass(this.options.theme).addClass(e),this.options.theme=e,i.bind(this)("uhr-theme",e))},time:function(t){this.currentMinute=-1,null===t?this.options.time=new Date:(null!==this.timer&&window.clearInterval(this.timer),this.options.time=t),n.bind(this)()},mode:u,width:l,_create:function(){this.id=s.id++,this.timer=null,this.currentMinute=-1;var t,i=this.options.time;void 0===this.options.time&&(this.options.time=new Date),void 0!==(t=window.location.hash)&&"string"==typeof t&&"#"===t.charAt(0)&&(t=t.substring(1),(t=decodeURIComponent(t)).split("&").forEach(function(t){var i=t.split("="),e=i[0],n=i[1];switch(e){case"l":case"language":this.options.language=n,this.options.force=!0;break;case"t":case"theme":this.options.theme=n,this.options.force=!0;break;case"m":case"mode":this.options.mode=n,this.options.force=!0;break;case"s":case"status":this.options.status=n,this.options.force=!0}}.bind(this))),c.bind(this)(),d.bind(this)(),void 0!==i&&this.time(i)},_destroy:function(){this.timer=null,t(this.element).removeAttr("style").removeAttr("class").empty(),t("#uhr-configlink"+this.id).remove(),t("#uhr-controlpanel"+this.id).remove()}}),t.fritteli.uhr.register=s.registerLanguage}(jQuery); diff --git a/rollup.config-base.js b/rollup.config-base.js index 6c07355..daefb6d 100644 --- a/rollup.config-base.js +++ b/rollup.config-base.js @@ -6,18 +6,16 @@ export default { 'jquery-ui', 'jquery.cookie' ], - input: { - 'jquery.uhr.base': 'src/main-base.js' - }, + input: 'src/main-base.js', output: [ { dir: 'dist', - entryFileNames: '[name].js', + entryFileNames: 'jquery.uhr.base.js', format: 'cjs' }, { dir: 'dist', - entryFileNames: '[name].min.js', + entryFileNames: 'jquery.uhr.base.min.js', format: 'cjs', plugins: [terser()] } diff --git a/rollup.config-baselangs.js b/rollup.config-baselangs.js index 942e788..9072365 100644 --- a/rollup.config-baselangs.js +++ b/rollup.config-baselangs.js @@ -6,18 +6,16 @@ export default { 'jquery-ui', 'jquery.cookie' ], - input: { - 'jquery.uhr.baselangs': 'src/main-baselangs.js' - }, + input: 'src/main-baselangs.js', output: [ { dir: 'dist', - entryFileNames: '[name].js', + entryFileNames: 'jquery.uhr.baselangs.js', format: 'cjs' }, { dir: 'dist', - entryFileNames: '[name].min.js', + entryFileNames: 'jquery.uhr.baselangs.min.js', format: 'cjs', plugins: [terser()] } diff --git a/rollup.config-complete.js b/rollup.config-complete.js index ae08b0a..10a4b0e 100644 --- a/rollup.config-complete.js +++ b/rollup.config-complete.js @@ -6,18 +6,16 @@ export default { 'jquery-ui', 'jquery.cookie' ], - input: { - 'jquery.uhr.complete': 'src/main-complete.js' - }, + input: 'src/main-complete.js', output: [ { dir: 'dist', - entryFileNames: '[name].js', + entryFileNames: 'jquery.uhr.complete.js', format: 'cjs' }, { dir: 'dist', - entryFileNames: '[name].min.js', + entryFileNames: 'jquery.uhr.complete.min.js', format: 'cjs', plugins: [terser()] } diff --git a/rollup.config-langs.js b/rollup.config-langs.js index 12a18d7..dc9ff47 100644 --- a/rollup.config-langs.js +++ b/rollup.config-langs.js @@ -6,18 +6,16 @@ export default { 'jquery-ui', 'jquery.cookie' ], - input: { - 'jquery.uhr.langs': 'src/main-langs.js' - }, + input: 'src/main-langs.js', output: [ { dir: 'dist', - entryFileNames: '[name].js', + entryFileNames: 'jquery.uhr.langs.js', format: 'cjs' }, { dir: 'dist', - entryFileNames: '[name].min.js', + entryFileNames: 'jquery.uhr.langs.min.js', format: 'cjs', plugins: [terser()] } diff --git a/rollup.config-libs.js b/rollup.config-libs.js index 97342f4..3e7883b 100644 --- a/rollup.config-libs.js +++ b/rollup.config-libs.js @@ -2,18 +2,16 @@ import {terser} from 'rollup-plugin-terser'; import {nodeResolve} from '@rollup/plugin-node-resolve'; export default { - input: { - 'libs': 'src/main-libs.js' - }, + input: 'src/main-libs.js', output: [ { dir: 'dist', - entryFileNames: '[name].js', + entryFileNames: 'libs.js', format: 'cjs' }, { dir: 'dist', - entryFileNames: '[name].min.js', + entryFileNames: 'libs.min.js', format: 'cjs', plugins: [terser()] }