Skip to content
Snippets Groups Projects
Commit 80997d21 authored by Michal Rezler's avatar Michal Rezler
Browse files

locktimer.js is jQueryfied

parent b29919f7
No related branches found
No related tags found
No related merge requests found
...@@ -122,7 +122,7 @@ function js_out(){ ...@@ -122,7 +122,7 @@ function js_out(){
js_runonstart("initSizeCtl('size__ctl','wiki__text')"); js_runonstart("initSizeCtl('size__ctl','wiki__text')");
js_runonstart("initToolbar('tool__bar','wiki__text',toolbar)"); js_runonstart("initToolbar('tool__bar','wiki__text',toolbar)");
if($conf['locktime'] != 0){ 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('scrollToMarker()');
js_runonstart('focusMarker()'); js_runonstart('focusMarker()');
......
/** /**
* Class managing the timer to display a warning on a expiring lock * 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 // init values
locktimer.timeout = timeout*1000; locktimer.timeout = timeout*1000;
locktimer.msg = msg; locktimer.msg = msg;
locktimer.draft = draft; locktimer.draft = draft;
locktimer.lasttime = new Date(); locktimer.lasttime = new Date();
if(!$('dw__editform')) return; if($('#dw__editform').length == 0) return;
locktimer.pageid = $('dw__editform').elements.id.value; locktimer.pageid = $('#dw__editform input[name=id]').val();
if(!locktimer.pageid) return; if(!locktimer.pageid) return;
if($('wiki__text').readOnly) return; if($('#wiki__text').attr('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;
// register refresh event // register refresh event
addEvent($('dw__editform'),'keypress',function(){locktimer.refresh();}); $('#dw__editform').keypress(
function() {
refresh();
}
);
// start timer // start timer
locktimer.reset(); reset();
}, };
/** /**
* (Re)start the warning timer * (Re)start the warning timer
*/ */
reset: function(){ reset = function(){
locktimer.clear(); clear();
locktimer.timerID = window.setTimeout("locktimer.warning()", locktimer.timeout); locktimer.timerID = window.setTimeout("expWarning()", locktimer.timeout);
}, };
/** /**
* Display the warning about the expiring lock * Display the warning about the expiring lock
*/ */
warning: function(){ expWarning = function(){
locktimer.clear(); clear();
alert(locktimer.msg); alert(locktimer.msg);
}, };
/** /**
* Remove the current warning timer * Remove the current warning timer
*/ */
clear: function(){ clear = function(){
if(locktimer.timerID !== null){ if(locktimer.timerID !== null){
window.clearTimeout(locktimer.timerID); window.clearTimeout(locktimer.timerID);
locktimer.timerID = null; locktimer.timerID = null;
} }
}, };
/** /**
* Refresh the lock via AJAX * Refresh the lock via AJAX
* *
* Called on keypresses in the edit area * Called on keypresses in the edit area
*/ */
refresh: function(){ refresh = function(){
var now = new Date(); var now = new Date();
// refresh every minute only var params = {};
// refresh every minute only
if(now.getTime() - locktimer.lasttime.getTime() > 30*1000){ if(now.getTime() - locktimer.lasttime.getTime() > 30*1000){
var params = 'call=lock&id='+encodeURIComponent(locktimer.pageid);
var dwform = $('dw__editform'); params['call'] = 'lock';
if(locktimer.draft && dwform.elements.wikitext){ params['id'] = locktimer.pageid;
params += '&prefix='+encodeURIComponent(dwform.elements.prefix.value);
params += '&wikitext='+encodeURIComponent(dwform.elements.wikitext.value); if(locktimer.draft && $('#dw__editform textarea[name=wikitext]').length > 0){
params += '&suffix='+encodeURIComponent(dwform.elements.suffix.value); params['prefix'] = $('#dw__editform input[name=prefix]').val();
if(dwform.elements.date){ params['wikitext'] = $('#dw__editform textarea[name=wikitext]').val();
params += '&date='+encodeURIComponent(dwform.elements.date.value); 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; locktimer.lasttime = now;
} }
}, };
/** /**
* Callback. Resets the warning timer * Callback. Resets the warning timer
*/ */
refreshed: function(){ refreshed = function(data){
var data = this.response;
var error = data.charAt(0); var error = data.charAt(0);
data = data.substring(1); data = data.substring(1);
$('draft__status').innerHTML=data; $('#draft__status').html(data);
if(error != '1') return; // locking failed if(error != '1') return; // locking failed
locktimer.reset(); reset();
} };
};
}(jQuery));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment