diff --git a/uhr.js b/uhr.js index d2c6f3c..94e2280 100644 --- a/uhr.js +++ b/uhr.js @@ -68,11 +68,7 @@ along with this program. If not, see . uhr._update(); }, 1000); this._update(); - if (this.options.cookiePath !== undefined) { - $.cookie('uhr-status' + this._id, 'on', {expires: 365, path: this.options.cookiePath}); - } else { - $.cookie('uhr-status' + this._id, 'on', {expires: 365}); - } + this._setCookie('uhr-status', 'on'); } else { } }, @@ -81,11 +77,7 @@ along with this program. If not, see . window.clearInterval(this._timer); this._timer = null; this._update(); - if (this.options.cookiePath !== undefined) { - $.cookie('uhr-status' + this._id, 'off', {expires: 365, path: this.options.cookiePath}); - } else { - $.cookie('uhr-status' + this._id, 'off', {expires: 365}); - } + this._setCookie('uhr-status', 'off'); } }, toggle: function() { @@ -104,11 +96,7 @@ along with this program. If not, see . uhr._currentMinute = -1; uhr._update(); }); - if (this.options.cookiePath !== undefined) { - $.cookie('uhr-language' + this._id, languageKey, {expires: 365, path: this.options.cookiePath}); - } else { - $.cookie('uhr-language' + this._id, languageKey, {expires: 365}); - } + this._setCookie('uhr-language', languageKey); this._update(); } }, @@ -117,11 +105,7 @@ along with this program. If not, see . this.element.removeClass(this.options.theme).addClass(theme); $('#uhr-onoffswitch' + this._id).removeClass(this.options.theme).addClass(theme); this.options.theme = theme; - if (this.options.cookiePath !== undefined) { - $.cookie('uhr-theme' + this._id, theme, {expires: 365, path: this.options.cookiePath}); - } else { - $.cookie('uhr-theme' + this._id, theme, {expires: 365}); - } + this._setCookie('uhr-theme', theme); } }, time: function(time) { @@ -343,6 +327,15 @@ along with this program. If not, see . themeChooser.val(selectedTheme); this.options.theme = ""; this.theme(selectedTheme); + }, + _setCookie: function(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); } }); /**