diff options
author | Michal Rezler <rezlemic@fel.cvut.cz> | 2011-03-28 23:09:13 +0200 |
---|---|---|
committer | Michal Rezler <rezlemic@fel.cvut.cz> | 2011-03-28 23:09:13 +0200 |
commit | 2ed49e2ac1bc9ed8a9d514d3ea9515e455768152 (patch) | |
tree | e6dc99486f47cdeea96f2c43a648baad22db9014 /lib/scripts/locktimer.js | |
parent | 11bf24d856a6a4cb606bc6fe10ebcbd844f4127f (diff) | |
download | dokuwiki-2ed49e2ac1bc9ed8a9d514d3ea9515e455768152.tar.gz dokuwiki-2ed49e2ac1bc9ed8a9d514d3ea9515e455768152.zip |
JS API is corrected to the original state
Diffstat (limited to 'lib/scripts/locktimer.js')
-rw-r--r-- | lib/scripts/locktimer.js | 131 |
1 files changed, 58 insertions, 73 deletions
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 |