summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichal Rezler <rezlemic@fel.cvut.cz>2011-03-26 12:46:37 +0100
committerMichal Rezler <rezlemic@fel.cvut.cz>2011-03-26 12:46:37 +0100
commit80997d21e0aee9b8f27153000742ecd781f429f8 (patch)
tree52fabb5d4930a6c8c14d92c1e40db68d7ef0a685 /lib
parentb29919f7882f5825a2b980e97f208e0bb3aeffa0 (diff)
downloadrpg-80997d21e0aee9b8f27153000742ecd781f429f8.tar.gz
rpg-80997d21e0aee9b8f27153000742ecd781f429f8.tar.bz2
locktimer.js is jQueryfied
Diffstat (limited to 'lib')
-rw-r--r--lib/exe/js.php2
-rw-r--r--lib/scripts/locktimer.js122
2 files changed, 73 insertions, 51 deletions
diff --git a/lib/exe/js.php b/lib/exe/js.php
index f953aae9e..b0b722a2e 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -122,7 +122,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("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].")");
+ js_runonstart("initLocktimer(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].")");
}
js_runonstart('scrollToMarker()');
js_runonstart('focusMarker()');
diff --git a/lib/scripts/locktimer.js b/lib/scripts/locktimer.js
index f5ba1c60d..6681438d7 100644
--- a/lib/scripts/locktimer.js
+++ b/lib/scripts/locktimer.js
@@ -1,99 +1,121 @@
/**
* 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){
+// 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){
+
// init values
locktimer.timeout = timeout*1000;
locktimer.msg = msg;
locktimer.draft = draft;
locktimer.lasttime = new Date();
- if(!$('dw__editform')) return;
- locktimer.pageid = $('dw__editform').elements.id.value;
+ if($('#dw__editform').length == 0) return;
+ locktimer.pageid = $('#dw__editform input[name=id]').val();
+
if(!locktimer.pageid) return;
- if($('wiki__text').readOnly) return;
-
- // init ajax component
- locktimer.sack = new sack(DOKU_BASE + 'lib/exe/ajax.php');
- locktimer.sack.AjaxFailedAlert = '';
- locktimer.sack.encodeURIString = false;
- locktimer.sack.onCompletion = locktimer.refreshed;
+ if($('#wiki__text').attr('readonly')) return;
// register refresh event
- addEvent($('dw__editform'),'keypress',function(){locktimer.refresh();});
+ $('#dw__editform').keypress(
+ function() {
+ refresh();
+ }
+ );
+
// start timer
- locktimer.reset();
- },
+ reset();
+ };
/**
* (Re)start the warning timer
*/
- reset: function(){
- locktimer.clear();
- locktimer.timerID = window.setTimeout("locktimer.warning()", locktimer.timeout);
- },
+ reset = function(){
+ clear();
+ locktimer.timerID = window.setTimeout("expWarning()", locktimer.timeout);
+ };
/**
* Display the warning about the expiring lock
*/
- warning: function(){
- locktimer.clear();
+ expWarning = function(){
+ clear();
alert(locktimer.msg);
- },
+ };
/**
* Remove the current warning timer
*/
- clear: function(){
+ clear = function(){
if(locktimer.timerID !== null){
window.clearTimeout(locktimer.timerID);
locktimer.timerID = null;
}
- },
+ };
/**
* Refresh the lock via AJAX
*
* Called on keypresses in the edit area
*/
- refresh: function(){
+ refresh = function(){
+
var now = new Date();
- // refresh every minute only
+ var params = {};
+
+ // refresh every minute only
if(now.getTime() - locktimer.lasttime.getTime() > 30*1000){
- var params = 'call=lock&id='+encodeURIComponent(locktimer.pageid);
- var dwform = $('dw__editform');
- if(locktimer.draft && dwform.elements.wikitext){
- params += '&prefix='+encodeURIComponent(dwform.elements.prefix.value);
- params += '&wikitext='+encodeURIComponent(dwform.elements.wikitext.value);
- params += '&suffix='+encodeURIComponent(dwform.elements.suffix.value);
- if(dwform.elements.date){
- params += '&date='+encodeURIComponent(dwform.elements.date.value);
+
+ 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();
}
}
- locktimer.sack.runAJAX(params);
+
+ $.post(
+ DOKU_BASE + 'lib/exe/ajax.php',
+ params,
+ function (data) {
+ refreshed(data);
+ },
+ 'html'
+ );
+
locktimer.lasttime = now;
}
- },
+ };
/**
* Callback. Resets the warning timer
*/
- refreshed: function(){
- var data = this.response;
+ refreshed = function(data){
var error = data.charAt(0);
- data = data.substring(1);
-
- $('draft__status').innerHTML=data;
+ data = data.substring(1);
+
+ $('#draft__status').html(data);
if(error != '1') return; // locking failed
- locktimer.reset();
- }
-};
-
+ reset();
+ };
+
+}(jQuery));