summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Rezler <rezlemic@fel.cvut.cz>2011-03-28 23:09:13 +0200
committerMichal Rezler <rezlemic@fel.cvut.cz>2011-03-28 23:09:13 +0200
commit2ed49e2ac1bc9ed8a9d514d3ea9515e455768152 (patch)
treee6dc99486f47cdeea96f2c43a648baad22db9014
parent11bf24d856a6a4cb606bc6fe10ebcbd844f4127f (diff)
downloadrpg-2ed49e2ac1bc9ed8a9d514d3ea9515e455768152.tar.gz
rpg-2ed49e2ac1bc9ed8a9d514d3ea9515e455768152.tar.bz2
JS API is corrected to the original state
-rw-r--r--lib/exe/js.php3
-rw-r--r--lib/scripts/cookie.js97
-rw-r--r--lib/scripts/helpers.js146
-rw-r--r--lib/scripts/locktimer.js131
-rw-r--r--lib/scripts/media.js58
-rw-r--r--lib/scripts/script.js8
6 files changed, 290 insertions, 153 deletions
diff --git a/lib/exe/js.php b/lib/exe/js.php
index 4aa2851c8..169803658 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -47,6 +47,7 @@ function js_out(){
DOKU_INC.'lib/scripts/jquery/jquery.cookie.js',
DOKU_INC.'lib/scripts/jquery-ui/jquery-ui.core.min.js',
DOKU_INC.'lib/scripts/jquery-ui/jquery-ui.interactions.min.js',
+ DOKU_INC.'lib/scripts/helpers.js',
DOKU_INC.'lib/scripts/events.js',
DOKU_INC.'lib/scripts/delay.js',
DOKU_INC.'lib/scripts/cookie.js',
@@ -122,7 +123,7 @@ function js_out(){
js_runonstart("initSizeCtl('size__ctl','wiki__text')");
js_runonstart("initToolbar('tool__bar','wiki__text',toolbar)");
if($conf['locktime'] != 0){
- js_runonstart("initLocktimer(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].")");
+ js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].")");
}
js_runonstart('scrollToMarker()');
js_runonstart('focusMarker()');
diff --git a/lib/scripts/cookie.js b/lib/scripts/cookie.js
index 1fccf85ba..4904117ee 100644
--- a/lib/scripts/cookie.js
+++ b/lib/scripts/cookie.js
@@ -1,97 +1,102 @@
/**
- * Handles the cookie used by several JavaScript functions
- *
- * Only a single cookie is written and read. You may only save
- * sime name-value pairs - no complex types!
- *
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- * @author Michal Rezler <m.rezler@centrum.cz>
- */
-
-var setDokuCookie, getDokuCookie;
-
-(function ($) {
- var init, setCookie, fixDate;
-
- var data = Array();
- var name = 'DOKU_PREFS';
+* Handles the cookie used by several JavaScript functions
+*
+* 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',
/**
* Save a value to the cookie
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- setDokuCookie = function(key,val){
- init();
- data[key] = val;
+ setValue: function(key,val){
+ this.init();
+ this.data[key] = val;
// prepare expire date
var now = new Date();
- fixDate(now);
+ this.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 data){
- if (!data.hasOwnProperty(key)) continue;
- text += '#'+escape(key)+'#'+data[key];
+ for(var key in this.data){
+ if (!this.data.hasOwnProperty(key)) continue;
+ text += '#'+escape(key)+'#'+this.data[key];
}
- setCookie(name,text.substr(1),now,DOKU_BASE);
- };
+ this.setCookie(this.name,text.substr(1),now,DOKU_BASE);
+ },
/**
* Get a Value from the Cookie
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- getDokuCookie = function(key){
- init();
- return data[key];
- };
+ getValue: function(key){
+ this.init();
+ return this.data[key];
+ },
/**
* Loads the current set cookie
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- init = function(){
- if(data.length) return;
- var text = $.cookie(name);
-
+ init: function(){
+ if(this.data.length) return;
+ var text = this.getCookie(this.name);
if(text){
var parts = text.split('#');
for(var i=0; i<parts.length; i+=2){
- data[unescape(parts[i])] = unescape(parts[i+1]);
+ this.data[unescape(parts[i])] = unescape(parts[i+1]);
}
}
- };
+ },
/**
- * This sets a cookie
+ * This sets a cookie by JavaScript
*
+ * @link http://www.webreference.com/js/column8/functions.html
*/
- setCookie = function(name, value, expires_, path_, domain_, secure_) {
- var params = {
+ setCookie: function(name, value, expires_, path_, domain_, secure_) {
+ var params = {
expires: expires_,
path: path_,
domain: domain_,
secure: secure_,
- };
- $.cookie(name, value, params);
- };
+ };
+
+ jQuery.cookie(name, value, params);
+ },
+
+ /**
+ * This reads a cookie by JavaScript
+ *
+ * @link http://www.webreference.com/js/column8/functions.html
+ */
+ getCookie: function(name) {
+ return unescape(jQuery.cookie(name));
+ },
/**
* 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));
+ }
+}; \ No newline at end of file
diff --git a/lib/scripts/helpers.js b/lib/scripts/helpers.js
new file mode 100644
index 000000000..babd652d7
--- /dev/null
+++ b/lib/scripts/helpers.js
@@ -0,0 +1,146 @@
+/**
+* Differrent helper functions
+*
+* @author Ilya Lebedev <ilya@lebedev.net>
+* @license LGPL
+*/
+//-----------------------------------------------------------------------------
+// Variable/property checks
+//-----------------------------------------------------------------------------
+/**
+* Checks if property is undefined
+*
+* @param {Object} prop value to check
+* @return {Boolean} true if matched
+* @scope public
+*/
+function isUndefined (prop /* :Object */) /* :Boolean */ {
+ return (typeof prop == 'undefined');
+}
+/**
+* Checks if property is function
+*
+* @param {Object} prop value to check
+* @return {Boolean} true if matched
+* @scope public
+*/
+function isFunction (prop /* :Object */) /* :Boolean */ {
+ return (typeof prop == 'function');
+}
+/**
+* Checks if property is string
+*
+* @param {Object} prop value to check
+* @return {Boolean} true if matched
+* @scope public
+*/
+function isString (prop /* :Object */) /* :Boolean */ {
+ return (typeof prop == 'string');
+}
+/**
+* Checks if property is number
+*
+* @param {Object} prop value to check
+* @return {Boolean} true if matched
+* @scope public
+*/
+function isNumber (prop /* :Object */) /* :Boolean */ {
+ return (typeof prop == 'number');
+}
+/**
+* Checks if property is the calculable number
+*
+* @param {Object} prop value to check
+* @return {Boolean} true if matched
+* @scope public
+*/
+function isNumeric (prop /* :Object */) /* :Boolean */ {
+ return isNumber(prop)&&!isNaN(prop)&&isFinite(prop);
+}
+/**
+* Checks if property is array
+*
+* @param {Object} prop value to check
+* @return {Boolean} true if matched
+* @scope public
+*/
+function isArray (prop /* :Object */) /* :Boolean */ {
+ return (prop instanceof Array);
+}
+/**
+* Checks if property is regexp
+*
+* @param {Object} prop value to check
+* @return {Boolean} true if matched
+* @scope public
+*/
+function isRegExp (prop /* :Object */) /* :Boolean */ {
+ return (prop instanceof RegExp);
+}
+/**
+* Checks if property is a boolean value
+*
+* @param {Object} prop value to check
+* @return {Boolean} true if matched
+* @scope public
+*/
+function isBoolean (prop /* :Object */) /* :Boolean */ {
+ return ('boolean' == typeof prop);
+}
+/**
+* Checks if property is a scalar value (value that could be used as the hash key)
+*
+* @param {Object} prop value to check
+* @return {Boolean} true if matched
+* @scope public
+*/
+function isScalar (prop /* :Object */) /* :Boolean */ {
+ return isNumeric(prop)||isString(prop);
+}
+/**
+* Checks if property is empty
+*
+* @param {Object} prop value to check
+* @return {Boolean} true if matched
+* @scope public
+*/
+function isEmpty (prop /* :Object */) /* :Boolean */ {
+ if (isBoolean(prop)) return false;
+ if (isRegExp(prop) && new RegExp("").toString() == prop.toString()) return true;
+ if (isString(prop) || isNumber(prop)) return !prop;
+ if (Boolean(prop)&&false != prop) {
+ for (var i in prop) if(prop.hasOwnProperty(i)) return false;
+ }
+ return true;
+}
+
+/**
+* Checks if property is derived from prototype, applies method if it is not exists
+*
+* @param string property name
+* @return bool true if prototyped
+* @access public
+*/
+if ('undefined' == typeof Object.hasOwnProperty) {
+ Object.prototype.hasOwnProperty = function (prop) {
+ return !('undefined' == typeof this[prop] || this.constructor && this.constructor.prototype[prop] && this[prop] === this.constructor.prototype[prop]);
+ };
+}
+
+/**
+* Very simplistic Flash plugin check, probably works for Flash 8 and higher only
+*/
+function hasFlash(version){
+ var ver = 0;
+ try{
+ if(navigator.plugins != null && navigator.plugins.length > 0){
+ ver = navigator.plugins["Shockwave Flash"].description.split(' ')[2].split('.')[0];
+ }else{
+ var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
+ ver = axo.GetVariable("$version").split(' ')[1].split(',')[0];
+ }
+ }catch(e){ }
+
+ if(ver >= version) return true;
+ return false;
+} \ No newline at end of file
diff --git a/lib/scripts/locktimer.js b/lib/scripts/locktimer.js
index 6681438d7..ad3e7ff62 100644
--- a/lib/scripts/locktimer.js
+++ b/lib/scripts/locktimer.js
@@ -1,121 +1,106 @@
/**
- * Class managing the timer to display a warning on a expiring lock
- */
-
-// must be global variables, they are called from outside too
-var initLocktimer, expWarning;
-
-(function ($) {
- var reset, clear, refresh, refreshed;
-
- var locktimer = {
- timeout: 0,
- timerID: null,
- lasttime: null,
- msg: '',
- pageid: '',
- };
-
- initLocktimer = function(timeout, msg, draft){
+* Class managing the timer to display a warning on a expiring lock
+*/
+var locktimer = {
+ sack: null,
+ timeout: 0,
+ timerID: null,
+ lasttime: null,
+ msg: '',
+ pageid: '',
+ init: function(timeout,msg,draft){
// init values
- locktimer.timeout = timeout*1000;
- locktimer.msg = msg;
- locktimer.draft = draft;
- locktimer.lasttime = new Date();
+ this.timeout = timeout*1000;
+ this.msg = msg;
+ this.draft = draft;
+ this.lasttime = new Date();
- if($('#dw__editform').length == 0) return;
- locktimer.pageid = $('#dw__editform input[name=id]').val();
+ if(jQuery('#dw__editform').length == 0) return;
+ this.pageid = jQuery('#dw__editform input[name=id]').val();
+ if(!this.pageid) return;
- if(!locktimer.pageid) return;
- if($('#wiki__text').attr('readonly')) return;
+ if(jQuery('#wiki__text').attr('readonly')) return;
// register refresh event
- $('#dw__editform').keypress(
+ jQuery('#dw__editform').keypress(
function() {
- refresh();
+ locktimer.refresh();
}
);
-
// start timer
- reset();
- };
+ this.reset();
+ },
/**
* (Re)start the warning timer
*/
- reset = function(){
- clear();
- locktimer.timerID = window.setTimeout("expWarning()", locktimer.timeout);
- };
+ reset: function(){
+ this.clear();
+ this.timerID = window.setTimeout("locktimer.warning()", this.timeout);
+ },
/**
* Display the warning about the expiring lock
*/
- expWarning = function(){
- clear();
- alert(locktimer.msg);
- };
+ warning: function(){
+ this.clear();
+ alert(this.msg);
+ },
/**
* Remove the current warning timer
*/
- clear = function(){
- if(locktimer.timerID !== null){
- window.clearTimeout(locktimer.timerID);
- locktimer.timerID = null;
+ clear: function(){
+ if(this.timerID !== null){
+ window.clearTimeout(this.timerID);
+ this.timerID = null;
}
- };
+ },
/**
* Refresh the lock via AJAX
*
* Called on keypresses in the edit area
*/
- refresh = function(){
-
+ refresh: function(){
var now = new Date();
- var params = {};
-
- // refresh every minute only
- if(now.getTime() - locktimer.lasttime.getTime() > 30*1000){
-
+ var params = {};
+ // refresh every minute only
+ if(now.getTime() - this.lasttime.getTime() > 30*1000){
params['call'] = 'lock';
params['id'] = locktimer.pageid;
-
- if(locktimer.draft && $('#dw__editform textarea[name=wikitext]').length > 0){
- params['prefix'] = $('#dw__editform input[name=prefix]').val();
- params['wikitext'] = $('#dw__editform textarea[name=wikitext]').val();
- params['suffix'] = $('#dw__editform input[name=suffix]').val();
-
- if($('#dw__editform input[name=date]').length > 0){
- params['date'] = $('#dw__editform input[name=id]').val();
+
+ if(locktimer.draft && jQuery('#dw__editform textarea[name=wikitext]').length > 0){
+ params['prefix'] = jQuery('#dw__editform input[name=prefix]').val();
+ params['wikitext'] = jQuery('#dw__editform textarea[name=wikitext]').val();
+ params['suffix'] = jQuery('#dw__editform input[name=suffix]').val();
+ if(jQuery('#dw__editform input[name=date]').length > 0) {
+ params['date'] = jQuery('#dw__editform input[name=id]').val();
}
}
- $.post(
+ jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
params,
- function (data) {
- refreshed(data);
+ function (data) {
+ locktimer.refreshed(data);
},
'html'
);
-
- locktimer.lasttime = now;
+ this.lasttime = now;
}
- };
+ },
/**
* Callback. Resets the warning timer
*/
- refreshed = function(data){
+ refreshed: function(data){
var error = data.charAt(0);
- data = data.substring(1);
-
- $('#draft__status').html(data);
+ data = data.substring(1);
+
+ jQuery('#draft__status').html(data);
if(error != '1') return; // locking failed
- reset();
- };
-
-}(jQuery));
+ this.reset();
+ }
+}; \ No newline at end of file
diff --git a/lib/scripts/media.js b/lib/scripts/media.js
index f407aa2f7..7529523ad 100644
--- a/lib/scripts/media.js
+++ b/lib/scripts/media.js
@@ -409,25 +409,25 @@
if ( media_manager.link == '2' || media_manager.link == '1') {
inSet('media__linkbtn3');
media_manager.link = '3';
- setDokuCookie('link','3');
+ DokuCookie.setValue('link','3');
} else {
inSet('media__linkbtn'+media_manager.link);
}
- } else if (getDokuCookie('link')) {
- if ( getDokuCookie('link') == '2' || getDokuCookie('link') == '1') {
+ } else if (DokuCookie.getValue('link')) {
+ if ( DokuCookie.getValue('link') == '2' || DokuCookie.getValue('link') == '1') {
// this options are not availible
inSet('media__linkbtn3');
media_manager.link = '3';
- setDokuCookie('link','3');
+ DokuCookie.setValue('link','3');
} else {
- inSet('media__linkbtn'+getDokuCookie('link'));
- media_manager.link = getDokuCookie('link');
+ inSet('media__linkbtn'+DokuCookie.getValue('link'));
+ media_manager.link = DokuCookie.getValue('link');
}
} else {
// default case
media_manager.link = '3';
inSet('media__linkbtn3');
- setDokuCookie('link','3');
+ DokuCookie.setValue('link','3');
}
// disable button for original size
@@ -442,13 +442,13 @@
$('#media__sizebtn4').show();
// set the link button to default
- if (getDokuCookie('link')) {
- media_manager.link = getDokuCookie('link');
+ if (DokuCookie.getValue('link')) {
+ media_manager.link = DokuCookie.getValue('link');
}
if (media_manager.link == false) {
// default case
media_manager.link = '1';
- setDokuCookie('link','1');
+ DokuCookie.setValue('link','1');
}
inSet('media__linkbtn'+media_manager.link);
}
@@ -465,24 +465,24 @@
// set the align button to default
if (media_manager.align != false) {
inSet('media__alignbtn'+media_manager.align);
- } else if (getDokuCookie('align')) {
- inSet('media__alignbtn'+getDokuCookie('align'));
- media_manager.align = getDokuCookie('align');
+ } else if (DokuCookie.getValue('align')) {
+ inSet('media__alignbtn'+DokuCookie.getValue('align'));
+ media_manager.align = DokuCookie.getValue('align');
} else {
// default case
media_manager.align = '0';
inSet('media__alignbtn0');
- setDokuCookie('align','0');
+ DokuCookie.setValue('align','0');
}
// set the size button to default
- if (getDokuCookie('size')) {
- media_manager.size = getDokuCookie('size');
+ if (DokuCookie.getValue('size')) {
+ media_manager.size = DokuCookie.getValue('size');
}
if (media_manager.size == false || (media_manager.size === '4' && ext === '.swf')) {
// default case
media_manager.size = '2';
- setDokuCookie('size','2');
+ DokuCookie.setValue('size','2');
}
inSet('media__sizebtn'+media_manager.size);
@@ -519,7 +519,7 @@
var kobox = document.createElement('input');
kobox.type = 'checkbox';
kobox.id = 'media__keepopen';
- if(getDokuCookie('keepopen')){
+ if(DokuCookie.getValue('keepopen')){
kobox.checked = true;
kobox.defaultChecked = true; //IE wants this
media_manager.keepopen = true;
@@ -546,7 +546,7 @@
var hdbox = document.createElement('input');
hdbox.type = 'checkbox';
hdbox.id = 'media__hide';
- if(getDokuCookie('hide')){
+ if(DokuCookie.getValue('hide')){
hdbox.checked = true;
hdbox.defaultChecked = true; //IE wants this
media_manager.hide = true;
@@ -577,10 +577,10 @@
*/
toggleOption = function (checkbox, variable) {
if (checkbox.checked) {
- setDokuCookie(variable, 1);
+ DokuCookie.setValue(variable, 1);
media_manager[variable] = true;
} else {
- setDokuCookie(variable, '');
+ DokuCookie.setValue(variable, '');
media_manager[variable] = false;
}
};
@@ -641,14 +641,14 @@
var id = cb.id.substring(cb.id.length -1);
if(id){
- setDokuCookie('align',id);
+ DokuCookie.setValue('align',id);
media_manager.align = id;
for (var i = 1; i<=4; i++) {
outSet("media__alignbtn" + i);
}
inSet("media__alignbtn"+id);
}else{
- setDokuCookie('align','');
+ DokuCookie.setValue('align','');
media_manager.align = false;
}
};
@@ -661,7 +661,7 @@
setlink = function(event,cb){
var id = cb.id.substring(cb.id.length -1);
if(id){
- setDokuCookie('link',id);
+ DokuCookie.setValue('link',id);
for (var i = 1; i<=4; i++) {
outSet("media__linkbtn"+i);
}
@@ -674,11 +674,11 @@
align.show();
if (media_manager.link == '4') {
media_manager.align = '1';
- setDokuCookie('align', '1');
+ DokuCookie.setValue('align', '1');
inSet('media__alignbtn1');
media_manager.size = '2';
- setDokuCookie('size', '2');
+ DokuCookie.setValue('size', '2');
inSet('media__sizebtn2');
}
@@ -688,7 +688,7 @@
}
media_manager.link = id;
}else{
- setDokuCookie('link','');
+ DokuCookie.setValue('link','');
media_manager.link = false;
}
};
@@ -701,14 +701,14 @@
setsize = function(event,cb){
var id = cb.id.substring(cb.id.length -1);
if (id) {
- setDokuCookie('size',id);
+ DokuCookie.setValue('size',id);
media_manager.size = id;
for (var i = 1 ; i <=4 ; ++i) {
outSet("media__sizebtn" + i);
}
inSet("media__sizebtn"+id);
} else {
- setDokuCookie('size','');
+ DokuCookie.setValue('size','');
media_manager.width = false;
}
};
diff --git a/lib/scripts/script.js b/lib/scripts/script.js
index 09e61d88d..a99735c99 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 = getDokuCookie('sizeCtl');
+ var hgt = DokuCookie.getValue('sizeCtl');
if(hgt){
textarea.style.height = hgt;
}else{
textarea.style.height = '300px';
}
- var wrp = getDokuCookie('wrapCtl');
+ var wrp = DokuCookie.getValue('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';
- setDokuCookie('sizeCtl',textarea.style.height);
+ DokuCookie.setValue('sizeCtl',textarea.style.height);
}
/**
@@ -408,7 +408,7 @@ function toggleWrap(edid){
setWrap(textarea, 'off');
}
- setDokuCookie('wrapCtl',textarea.getAttribute('wrap'));
+ DokuCookie.setValue('wrapCtl',textarea.getAttribute('wrap'));
}
/**