diff options
author | Andreas Gohr <andi@splitbrain.org> | 2006-03-11 21:01:48 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2006-03-11 21:01:48 +0100 |
commit | ee4c4a1b5a5840c1b9d2d8c74b3f4298dd52928b (patch) | |
tree | ec7011afc97d0159819e8b334709fe0680cab9b1 /lib/scripts | |
parent | 6d8affe6a4c62d13d1cd6051c23ab305145f9db6 (diff) | |
download | rpg-ee4c4a1b5a5840c1b9d2d8c74b3f4298dd52928b.tar.gz rpg-ee4c4a1b5a5840c1b9d2d8c74b3f4298dd52928b.tar.bz2 |
Automatic draft saving
DokuWiki now automatically creates a draft file of the currently edited
page. In case of an editing interuption (eg. Browsercrash) the draftfile
can be continued later.
darcs-hash:20060311200148-7ad00-919337a51e001136178d175a1755cd26122e9726.gz
Diffstat (limited to 'lib/scripts')
-rw-r--r-- | lib/scripts/edit.js | 41 | ||||
-rw-r--r-- | lib/scripts/script.js | 10 |
2 files changed, 46 insertions, 5 deletions
diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js index d39835526..48acc542a 100644 --- a/lib/scripts/edit.js +++ b/lib/scripts/edit.js @@ -328,7 +328,24 @@ var textChanged = false; */ function changeCheck(msg){ if(textChanged){ - return confirm(msg); + var ok = confirm(msg); + if(ok){ + // remove a possibly saved draft using ajax + var dwform = $('dw__editform'); + if(dwform){ + var params = 'call=draftdel'; + params += '&id='+dwform.elements.id.value; + params += '&user='+encodeURI(USERNAME); + + var sackobj = new sack(DOKU_BASE + 'lib/exe/ajax.php'); + sackobj.AjaxFailedAlert = ''; + sackobj.encodeURIString = false; + sackobj.runAJAX(params); + // we send this request blind without waiting for + // and handling the returned data + } + } + return ok; }else{ return true; } @@ -408,10 +425,11 @@ function locktimer_class(){ this.pageid = ''; }; var locktimer = new locktimer_class(); - locktimer.init = function(timeout,msg){ + locktimer.init = function(timeout,msg,draft){ // init values locktimer.timeout = timeout*1000; locktimer.msg = msg; + locktimer.draft = draft; locktimer.lasttime = new Date(); if(!$('dw__editform')) return; @@ -465,8 +483,16 @@ var locktimer = new locktimer_class(); locktimer.refresh = function(){ var now = new Date(); // refresh every minute only - if(now.getTime() - locktimer.lasttime.getTime() > 60*1000){ - locktimer.sack.runAJAX('call=lock&id='+encodeURI(locktimer.pageid)); + if(now.getTime() - locktimer.lasttime.getTime() > 30*1000){ //FIXME decide on time + var params = 'call=lock&id='+encodeURI(locktimer.pageid); + if(locktimer.draft){ + var dwform = $('dw__editform'); + params += '&prefix='+encodeURI(dwform.elements.prefix.value); + params += '&wikitext='+encodeURI(dwform.elements.wikitext.value); + params += '&suffix='+encodeURI(dwform.elements.suffix.value); + params += '&date='+encodeURI(dwform.elements.date.value); + } + locktimer.sack.runAJAX(params); locktimer.lasttime = now; } }; @@ -476,7 +502,12 @@ var locktimer = new locktimer_class(); * Callback. Resets the warning timer */ locktimer.refreshed = function(){ - if(this.response != '1') return; // locking failed + var data = this.response; + var error = data.charAt(0); + data = data.substring(1); + + $('draft__status').innerHTML=data; + if(error != '1') return; // locking failed locktimer.reset(); }; // end of locktimer class functions diff --git a/lib/scripts/script.js b/lib/scripts/script.js index e05aeb0fe..87fd8e503 100644 --- a/lib/scripts/script.js +++ b/lib/scripts/script.js @@ -41,6 +41,16 @@ function $() { } /** + * Simple function to check if a global var is defined + * + * @author Kae Verens + * @link http://verens.com/archives/2005/07/25/isset-for-javascript/#comment-2835 + */ +function isset(varname){ + return(typeof(window[varname])!='undefined'); +} + +/** * Get the X offset of the top left corner of the given object * * @link http://www.quirksmode.org/index.html?/js/findpos.html |