summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/exe/ajax.php2
-rw-r--r--lib/scripts/edit.js59
-rw-r--r--lib/scripts/tw-sack.js5
3 files changed, 27 insertions, 39 deletions
diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php
index 8b03bb07c..582be90e5 100644
--- a/lib/exe/ajax.php
+++ b/lib/exe/ajax.php
@@ -156,7 +156,7 @@ function ajax_lock(){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function ajax_draftdel(){
- $id = cleanID($_POST['id']);
+ $id = cleanID($_REQUEST['id']);
if(empty($id)) return;
$client = $_SERVER['REMOTE_USER'];
diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js
index e66154f83..5178dba4c 100644
--- a/lib/scripts/edit.js
+++ b/lib/scripts/edit.js
@@ -258,35 +258,30 @@ function currentHeadlineLevel(textboxId){
var textChanged = false;
/**
- * Check for changes before leaving the page
+ * Delete the draft before leaving the page
*/
-function changeCheck(){
- if(textChanged){
- var ok = confirm(LANG.notsavedyet);
- if(ok){
- // remove a possibly saved draft using ajax
- var dwform = $('dw__editform');
- if(dwform){
- var params = 'call=draftdel';
- params += '&id='+encodeURIComponent(dwform.elements.id.value);
-
- 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
- }
+function deleteDraft() {
+ if (is_opera) return;
+
+ // remove a possibly saved draft using ajax
+ var dwform = $('dw__editform');
+ if(dwform){
+ var params = 'call=draftdel';
+ params += '&id='+encodeURIComponent(dwform.elements.id.value);
+
+ var sackobj = new sack(DOKU_BASE + 'lib/exe/ajax.php');
+ // this needs to be synchronous and GET to not be aborted upon page unload
+ sackobj.asynchronous = false;
+ sackobj.method = 'GET';
+ sackobj.AjaxFailedAlert = '';
+ sackobj.encodeURIString = false;
+ sackobj.runAJAX(params);
}
- return ok;
- }else{
- return true;
- }
}
/**
- * Add changeCheck to all Links and Forms (except those with a
- * JSnocheck class), add handlers to monitor changes
+ * Activate "not saved" dialog, add draft deletion to page unload,
+ * add handlers to monitor changes
*
* Sets focus to the editbox as well
*/
@@ -309,20 +304,12 @@ addInitEvent(function (){
addEvent(editform, 'change', checkfunc);
addEvent(editform, 'keydown', checkfunc);
- // add change check for links
- var links = document.getElementsByTagName('a');
- for(var i=0; i < links.length; i++){
- if(links[i].className.indexOf('JSnocheck') == -1){
- addEvent(links[i], 'click', changeCheck);
- }
- }
- // add change check for forms
- var forms = document.forms;
- for(i=0; i < forms.length; i++){
- if(forms[i].className.indexOf('JSnocheck') == -1){
- addEvent(forms[i], 'submit', changeCheck);
+ window.onbeforeunload = function(){
+ if(textChanged) {
+ return LANG.notsavedyet;
}
}
+ window.onunload = deleteDraft;
// reset change memory var on submit
addEvent($('edbtn__save'), 'click', function(){ textChanged = false; });
diff --git a/lib/scripts/tw-sack.js b/lib/scripts/tw-sack.js
index cfcbe0ea9..b5a5c8861 100644
--- a/lib/scripts/tw-sack.js
+++ b/lib/scripts/tw-sack.js
@@ -10,6 +10,7 @@ function sack(file){
this.URLString = "";
this.encodeURIString = true;
this.execute = false;
+ this.asynchronous = true;
this.onLoading = function() { };
this.onLoaded = function() { };
@@ -86,9 +87,9 @@ function sack(file){
var self = this;
if (this.method == "GET") {
var totalurlstring = this.requestFile + "?" + this.URLString;
- this.xmlhttp.open(this.method, totalurlstring, true);
+ this.xmlhttp.open(this.method, totalurlstring, this.asynchronous);
} else {
- this.xmlhttp.open(this.method, this.requestFile, true);
+ this.xmlhttp.open(this.method, this.requestFile, this.asynchronous);
}
if (this.method == "POST"){
try {