consider the path when setting a cookie, but make it overridable with the configuration parameter 'cookiePath'.

This commit is contained in:
Manuel Friedli 2014-06-28 23:27:41 +02:00
parent 6047499a18
commit c890429dd6

33
uhr.js
View file

@ -68,11 +68,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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 <http://www.gnu.org/licenses/>.
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 <http://www.gnu.org/licenses/>.
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 <http://www.gnu.org/licenses/>.
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 <http://www.gnu.org/licenses/>.
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);
}
});
/**