From 010cbcf01b37781fb94f89aec239135145b2ed5f Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 29 Mar 2008 08:31:34 +0000 Subject: [PATCH] Now issuing a *synchronous* save_note() call on page unload. When this call was done asynchronously, and a Luminotes Firefox window was closed, sometimes save_note() didn't get called. This didn't occur in IE. --- static/js/Invoker.js | 7 +++++-- static/js/Wiki.js | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/static/js/Invoker.js b/static/js/Invoker.js index 00af342..c40a07b 100644 --- a/static/js/Invoker.js +++ b/static/js/Invoker.js @@ -5,7 +5,7 @@ function Invoker() { // Invoke the given URL with a remote scripting call, providing the data args as an associative // array of key/value pairs. Optionally, the name of a form to scrape for args can also be provided. // http_type should be 'POST' or 'GET'. -Invoker.prototype.invoke = function ( url, http_type, args, callback, form, fire_and_forget ) { +Invoker.prototype.invoke = function ( url, http_type, args, callback, form, synchronous, fire_and_forget ) { if ( form ) { var form = formContents( getElement( form ) ); var arg_names = form[ 0 ]; @@ -18,6 +18,9 @@ Invoker.prototype.invoke = function ( url, http_type, args, callback, form, fire extend( arg_names, keys( args ) ); extend( arg_values, values( args ) ); + if ( synchronous ) + fire_and_forget = true; + if ( !fire_and_forget ) { if ( this.pending_count == 0 ) { var loading = createDOM( "span", { "class": "status_text" }, "loading" ); @@ -29,7 +32,7 @@ Invoker.prototype.invoke = function ( url, http_type, args, callback, form, fire if ( http_type == 'POST' ) { // HTTP POST request = getXMLHttpRequest(); - request.open( http_type, url, true ); + request.open( http_type, url, synchronous != true ); request.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' ); if ( arg_names.length > 0 ) var doc = sendXMLHttpRequest( request, queryString( arg_names, arg_values ) ); diff --git a/static/js/Wiki.js b/static/js/Wiki.js index c6466a5..2e7ead7 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -792,7 +792,7 @@ Wiki.prototype.display_link_pulldown = function ( editor, link ) { } } -Wiki.prototype.editor_focused = function ( editor, fire_and_forget ) { +Wiki.prototype.editor_focused = function ( editor, synchronous ) { if ( editor ) addElementClass( editor.iframe, "focused_note_frame" ); @@ -808,7 +808,7 @@ Wiki.prototype.editor_focused = function ( editor, fire_and_forget ) { this.display_empty_message(); } else { // when switching editors, save the one being left - this.save_editor( null, fire_and_forget ); + this.save_editor( null, null, null, synchronous ); } } @@ -1234,7 +1234,7 @@ Wiki.prototype.compare_versions = function( event, editor, previous_revision ) { this.load_editor( editor.title, editor.id, null, null, editor.closed ? null : editor.iframe ); } -Wiki.prototype.save_editor = function ( editor, fire_and_forget, callback ) { +Wiki.prototype.save_editor = function ( editor, fire_and_forget, callback, synchronous ) { if ( !editor ) editor = this.focused_editor; @@ -1252,7 +1252,7 @@ Wiki.prototype.save_editor = function ( editor, fire_and_forget, callback ) { editor.mark_clean(); if ( callback ) callback(); - }, null, fire_and_forget ); + }, null, synchronous, fire_and_forget ); } else { if ( callback ) callback();