summaryrefslogtreecommitdiff
path: root/lib/scripts
diff options
context:
space:
mode:
authorMichal Rezler <rezlemic@fel.cvut.cz>2011-03-26 15:42:22 +0100
committerMichal Rezler <rezlemic@fel.cvut.cz>2011-03-26 15:42:22 +0100
commitfdfb9c6a2877dcbadeab697aad779bea76780965 (patch)
treeabcf9001620e93fd471f53c396f905a14142c269 /lib/scripts
parent3044fa04f4879fe194de48009c13d119ac7782a5 (diff)
downloadrpg-fdfb9c6a2877dcbadeab697aad779bea76780965.tar.gz
rpg-fdfb9c6a2877dcbadeab697aad779bea76780965.tar.bz2
cookie.js is jQueryfied, added jQuery-cookie-plugin
Diffstat (limited to 'lib/scripts')
-rw-r--r--lib/scripts/cookie.js99
-rw-r--r--lib/scripts/jquery/jquery.cookie.js96
-rw-r--r--lib/scripts/media.js58
-rw-r--r--lib/scripts/script.js8
4 files changed, 171 insertions, 90 deletions
diff --git a/lib/scripts/cookie.js b/lib/scripts/cookie.js
index d7e6b3550..1fccf85ba 100644
--- a/lib/scripts/cookie.js
+++ b/lib/scripts/cookie.js
@@ -4,109 +4,94 @@
* Only a single cookie is written and read. You may only save
* sime name-value pairs - no complex types!
*
- * You should only use the getValue and setValue methods
*
* @author Andreas Gohr <andi@splitbrain.org>
+ * @author Michal Rezler <m.rezler@centrum.cz>
*/
-DokuCookie = {
- data: Array(),
- name: 'DOKU_PREFS',
+
+var setDokuCookie, getDokuCookie;
+
+(function ($) {
+ var init, setCookie, fixDate;
+
+ var data = Array();
+ var name = 'DOKU_PREFS';
/**
* Save a value to the cookie
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- setValue: function(key,val){
- DokuCookie.init();
- DokuCookie.data[key] = val;
+ setDokuCookie = function(key,val){
+ init();
+ data[key] = val;
// prepare expire date
var now = new Date();
- DokuCookie.fixDate(now);
+ fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); //expire in a year
//save the whole data array
var text = '';
- for(var key in DokuCookie.data){
- if (!DokuCookie.data.hasOwnProperty(key)) continue;
- text += '#'+escape(key)+'#'+DokuCookie.data[key];
+ for(var key in data){
+ if (!data.hasOwnProperty(key)) continue;
+ text += '#'+escape(key)+'#'+data[key];
}
- DokuCookie.setCookie(DokuCookie.name,text.substr(1),now,DOKU_BASE);
- },
+ setCookie(name,text.substr(1),now,DOKU_BASE);
+ };
/**
* Get a Value from the Cookie
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- getValue: function(key){
- DokuCookie.init();
- return DokuCookie.data[key];
- },
+ getDokuCookie = function(key){
+ init();
+ return data[key];
+ };
/**
* Loads the current set cookie
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- init: function(){
- if(DokuCookie.data.length) return;
- var text = DokuCookie.getCookie(DokuCookie.name);
+ init = function(){
+ if(data.length) return;
+ var text = $.cookie(name);
+
if(text){
var parts = text.split('#');
for(var i=0; i<parts.length; i+=2){
- DokuCookie.data[unescape(parts[i])] = unescape(parts[i+1]);
+ data[unescape(parts[i])] = unescape(parts[i+1]);
}
}
- },
+ };
/**
- * This sets a cookie by JavaScript
+ * This sets a cookie
*
- * @link http://www.webreference.com/js/column8/functions.html
*/
- setCookie: function(name, value, expires, path, domain, secure) {
- var curCookie = name + "=" + escape(value) +
- ((expires) ? "; expires=" + expires.toGMTString() : "") +
- ((path) ? "; path=" + path : "") +
- ((domain) ? "; domain=" + domain : "") +
- ((secure) ? "; secure" : "");
- document.cookie = curCookie;
- },
-
- /**
- * This reads a cookie by JavaScript
- *
- * @link http://www.webreference.com/js/column8/functions.html
- */
- getCookie: function(name) {
- var dc = document.cookie;
- var prefix = name + "=";
- var begin = dc.indexOf("; " + prefix);
- if (begin == -1) {
- begin = dc.indexOf(prefix);
- if (begin !== 0){ return null; }
- } else {
- begin += 2;
- }
- var end = document.cookie.indexOf(";", begin);
- if (end == -1){
- end = dc.length;
- }
- return unescape(dc.substring(begin + prefix.length, end));
- },
+ setCookie = function(name, value, expires_, path_, domain_, secure_) {
+ var params = {
+ expires: expires_,
+ path: path_,
+ domain: domain_,
+ secure: secure_,
+ };
+ $.cookie(name, value, params);
+ };
/**
* This is needed for the cookie functions
*
* @link http://www.webreference.com/js/column8/functions.html
*/
- fixDate: function(date) {
+ fixDate = function(date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0){
date.setTime(date.getTime() - skew);
}
- }
-};
+ };
+
+}(jQuery));
diff --git a/lib/scripts/jquery/jquery.cookie.js b/lib/scripts/jquery/jquery.cookie.js
new file mode 100644
index 000000000..6df1faca2
--- /dev/null
+++ b/lib/scripts/jquery/jquery.cookie.js
@@ -0,0 +1,96 @@
+/**
+ * Cookie plugin
+ *
+ * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ *
+ */
+
+/**
+ * Create a cookie with the given name and value and other optional parameters.
+ *
+ * @example $.cookie('the_cookie', 'the_value');
+ * @desc Set the value of a cookie.
+ * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
+ * @desc Create a cookie with all available options.
+ * @example $.cookie('the_cookie', 'the_value');
+ * @desc Create a session cookie.
+ * @example $.cookie('the_cookie', null);
+ * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
+ * used when the cookie was set.
+ *
+ * @param String name The name of the cookie.
+ * @param String value The value of the cookie.
+ * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
+ * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
+ * If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
+ * If set to null or omitted, the cookie will be a session cookie and will not be retained
+ * when the the browser exits.
+ * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
+ * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
+ * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
+ * require a secure protocol (like HTTPS).
+ * @type undefined
+ *
+ * @name $.cookie
+ * @cat Plugins/Cookie
+ * @author Klaus Hartl/klaus.hartl@stilbuero.de
+ */
+
+/**
+ * Get the value of a cookie with the given name.
+ *
+ * @example $.cookie('the_cookie');
+ * @desc Get the value of a cookie.
+ *
+ * @param String name The name of the cookie.
+ * @return The value of the cookie.
+ * @type String
+ *
+ * @name $.cookie
+ * @cat Plugins/Cookie
+ * @author Klaus Hartl/klaus.hartl@stilbuero.de
+ */
+jQuery.cookie = function(name, value, options) {
+ if (typeof value != 'undefined') { // name and value given, set cookie
+ options = options || {};
+ if (value === null) {
+ value = '';
+ options.expires = -1;
+ }
+ var expires = '';
+ if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
+ var date;
+ if (typeof options.expires == 'number') {
+ date = new Date();
+ date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
+ } else {
+ date = options.expires;
+ }
+ expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
+ }
+ // CAUTION: Needed to parenthesize options.path and options.domain
+ // in the following expressions, otherwise they evaluate to undefined
+ // in the packed version for some reason...
+ var path = options.path ? '; path=' + (options.path) : '';
+ var domain = options.domain ? '; domain=' + (options.domain) : '';
+ var secure = options.secure ? '; secure' : '';
+ document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
+ } else { // only name given, get cookie
+ var cookieValue = null;
+ if (document.cookie && document.cookie != '') {
+ var cookies = document.cookie.split(';');
+ for (var i = 0; i < cookies.length; i++) {
+ var cookie = jQuery.trim(cookies[i]);
+ // Does this cookie string begin with the name we want?
+ if (cookie.substring(0, name.length + 1) == (name + '=')) {
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
+ break;
+ }
+ }
+ }
+ return cookieValue;
+ }
+}; \ No newline at end of file
diff --git a/lib/scripts/media.js b/lib/scripts/media.js
index c00a71e5f..a9b8b49da 100644
--- a/lib/scripts/media.js
+++ b/lib/scripts/media.js
@@ -389,25 +389,25 @@
if ( media_manager.link == '2' || media_manager.link == '1') {
inSet('media__linkbtn3');
media_manager.link = '3';
- DokuCookie.setValue('link','3');
+ setDokuCookie('link','3');
} else {
inSet('media__linkbtn'+media_manager.link);
}
- } else if (DokuCookie.getValue('link')) {
- if ( DokuCookie.getValue('link') == '2' || DokuCookie.getValue('link') == '1') {
+ } else if (getDokuCookie('link')) {
+ if ( getDokuCookie('link') == '2' || getDokuCookie('link') == '1') {
// this options are not availible
inSet('media__linkbtn3');
media_manager.link = '3';
- DokuCookie.setValue('link','3');
+ setDokuCookie('link','3');
} else {
- inSet('media__linkbtn'+DokuCookie.getValue('link'));
- media_manager.link = DokuCookie.getValue('link');
+ inSet('media__linkbtn'+getDokuCookie('link'));
+ media_manager.link = getDokuCookie('link');
}
} else {
// default case
media_manager.link = '3';
inSet('media__linkbtn3');
- DokuCookie.setValue('link','3');
+ setDokuCookie('link','3');
}
// disable button for original size
@@ -422,13 +422,13 @@
$('#media__sizebtn4').show();
// set the link button to default
- if (DokuCookie.getValue('link')) {
- media_manager.link = DokuCookie.getValue('link');
+ if (getDokuCookie('link')) {
+ media_manager.link = getDokuCookie('link');
}
if (media_manager.link == false) {
// default case
media_manager.link = '1';
- DokuCookie.setValue('link','1');
+ setDokuCookie('link','1');
}
inSet('media__linkbtn'+media_manager.link);
}
@@ -445,24 +445,24 @@
// set the align button to default
if (media_manager.align != false) {
inSet('media__alignbtn'+media_manager.align);
- } else if (DokuCookie.getValue('align')) {
- inSet('media__alignbtn'+DokuCookie.getValue('align'));
- media_manager.align = DokuCookie.getValue('align');
+ } else if (getDokuCookie('align')) {
+ inSet('media__alignbtn'+getDokuCookie('align'));
+ media_manager.align = getDokuCookie('align');
} else {
// default case
media_manager.align = '0';
inSet('media__alignbtn0');
- DokuCookie.setValue('align','0');
+ setDokuCookie('align','0');
}
// set the size button to default
- if (DokuCookie.getValue('size')) {
- media_manager.size = DokuCookie.getValue('size');
+ if (getDokuCookie('size')) {
+ media_manager.size = getDokuCookie('size');
}
if (media_manager.size == false || (media_manager.size === '4' && ext === '.swf')) {
// default case
media_manager.size = '2';
- DokuCookie.setValue('size','2');
+ setDokuCookie('size','2');
}
inSet('media__sizebtn'+media_manager.size);
@@ -499,7 +499,7 @@
var kobox = document.createElement('input');
kobox.type = 'checkbox';
kobox.id = 'media__keepopen';
- if(DokuCookie.getValue('keepopen')){
+ if(getDokuCookie('keepopen')){
kobox.checked = true;
kobox.defaultChecked = true; //IE wants this
media_manager.keepopen = true;
@@ -526,7 +526,7 @@
var hdbox = document.createElement('input');
hdbox.type = 'checkbox';
hdbox.id = 'media__hide';
- if(DokuCookie.getValue('hide')){
+ if(getDokuCookie('hide')){
hdbox.checked = true;
hdbox.defaultChecked = true; //IE wants this
media_manager.hide = true;
@@ -557,10 +557,10 @@
*/
toggleOption = function (checkbox, variable) {
if (checkbox.checked) {
- DokuCookie.setValue(variable, 1);
+ setDokuCookie(variable, 1);
media_manager[variable] = true;
} else {
- DokuCookie.setValue(variable, '');
+ setDokuCookie(variable, '');
media_manager[variable] = false;
}
};
@@ -621,14 +621,14 @@
var id = cb.id.substring(cb.id.length -1);
if(id){
- DokuCookie.setValue('align',id);
+ setDokuCookie('align',id);
media_manager.align = id;
for (var i = 1; i<=4; i++) {
outSet("media__alignbtn" + i);
}
inSet("media__alignbtn"+id);
}else{
- DokuCookie.setValue('align','');
+ setDokuCookie('align','');
media_manager.align = false;
}
};
@@ -641,7 +641,7 @@
setlink = function(event,cb){
var id = cb.id.substring(cb.id.length -1);
if(id){
- DokuCookie.setValue('link',id);
+ setDokuCookie('link',id);
for (var i = 1; i<=4; i++) {
outSet("media__linkbtn"+i);
}
@@ -654,11 +654,11 @@
align.show();
if (media_manager.link == '4') {
media_manager.align = '1';
- DokuCookie.setValue('align', '1');
+ setDokuCookie('align', '1');
inSet('media__alignbtn1');
media_manager.size = '2';
- DokuCookie.setValue('size', '2');
+ setDokuCookie('size', '2');
inSet('media__sizebtn2');
}
@@ -668,7 +668,7 @@
}
media_manager.link = id;
}else{
- DokuCookie.setValue('link','');
+ setDokuCookie('link','');
media_manager.link = false;
}
};
@@ -681,14 +681,14 @@
setsize = function(event,cb){
var id = cb.id.substring(cb.id.length -1);
if (id) {
- DokuCookie.setValue('size',id);
+ setDokuCookie('size',id);
media_manager.size = id;
for (var i = 1 ; i <=4 ; ++i) {
outSet("media__sizebtn" + i);
}
inSet("media__sizebtn"+id);
} else {
- DokuCookie.setValue('size','');
+ setDokuCookie('size','');
media_manager.width = false;
}
};
diff --git a/lib/scripts/script.js b/lib/scripts/script.js
index a99735c99..09e61d88d 100644
--- a/lib/scripts/script.js
+++ b/lib/scripts/script.js
@@ -358,14 +358,14 @@ function initSizeCtl(ctlid,edid){
var textarea = $(edid);
if(!ctl || !textarea) return;
- var hgt = DokuCookie.getValue('sizeCtl');
+ var hgt = getDokuCookie('sizeCtl');
if(hgt){
textarea.style.height = hgt;
}else{
textarea.style.height = '300px';
}
- var wrp = DokuCookie.getValue('wrapCtl');
+ var wrp = getDokuCookie('wrapCtl');
if(wrp){
setWrap(textarea, wrp);
} // else use default value
@@ -393,7 +393,7 @@ function sizeCtl(edid,val){
height += val;
textarea.style.height = height+'px';
- DokuCookie.setValue('sizeCtl',textarea.style.height);
+ setDokuCookie('sizeCtl',textarea.style.height);
}
/**
@@ -408,7 +408,7 @@ function toggleWrap(edid){
setWrap(textarea, 'off');
}
- DokuCookie.setValue('wrapCtl',textarea.getAttribute('wrap'));
+ setDokuCookie('wrapCtl',textarea.getAttribute('wrap'));
}
/**