From 489cc08783a8ee8d68ed6e77446eed1410386a8f Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 8 Oct 2008 17:09:13 -0700 Subject: [PATCH] Safari/Chrome: Uploading files now works reliably instead of just once. Apparently WebKit caches iframe src URLs! --- NEWS | 3 ++- static/js/Wiki.js | 32 ++++++++++++++++---------------- view/Progress_bar.py | 8 ++++---- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/NEWS b/NEWS index 267fdc8..4bfb92c 100644 --- a/NEWS +++ b/NEWS @@ -4,7 +4,8 @@ * Underline and strikethrough now work. * Pulldowns for search suggestions, importing, and exporting show up. * Pulldowns on inline images are now positioned correctly. - * Note resizing (growing and shrinking) works as expected. + * Uploading files now works reliably instead of just once. + * Note resizing (growing and shrinking) works (mostly) as expected. * Improved page loading speed and fixed a rare session locking timeout bug by removing all implicit session locking. * Fixed a bug that broke that Luminotes Desktop product download page if diff --git a/static/js/Wiki.js b/static/js/Wiki.js index b2396c6..06b6fe8 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -3271,14 +3271,17 @@ function Upload_pulldown( wiki, notebook_id, invoker, editor, link, ephemeral ) Pulldown.call( this, wiki, notebook_id, "upload_" + editor.id, this.link, editor.iframe, ephemeral ); wiki.down_image_button( "attachFile" ); + var vaguely_random = new Date().getTime(); this.invoker = invoker; this.editor = editor; this.iframe = createDOM( "iframe", { "src": "/files/upload_page?notebook_id=" + notebook_id + "¬e_id=" + editor.id, "frameBorder": "0", "scrolling": "no", - "id": "upload_frame", - "name": "upload_frame", + // if a new iframe has an id/name that WebKit has already seen, then it will just use its + // previous src value and ignore our new src value here. workaround: don't use the same id! + "id": "upload_frame_" + vaguely_random, + "name": "upload_frame_" + vaguely_random, "class": "upload_frame" } ); this.iframe.pulldown = this; @@ -3293,8 +3296,8 @@ function Upload_pulldown( wiki, notebook_id, invoker, editor, link, ephemeral ) this.progress_iframe = createDOM( "iframe", { "frameBorder": "0", "scrolling": "no", - "id": "progress_frame", - "name": "progress_frame", + "id": "progress_frame_" + vaguely_random, + "name": "progress_frame_" + vaguely_random, "class": "upload_frame" } ); addElementClass( this.progress_iframe, "undisplayed" ); @@ -3339,10 +3342,7 @@ Upload_pulldown.prototype.upload_started = function ( file_id ) { removeElementClass( this.progress_iframe, "undisplayed" ); var progress_url = "/files/progress?file_id=" + file_id + "&filename=" + escape( filename ); - if ( frames[ "progress_frames" ] ) - frames[ "progress_frame" ].location.href = progress_url; - else - this.progress_iframe.src = progress_url; + this.progress_iframe.src = progress_url; } Upload_pulldown.prototype.upload_complete = function () { @@ -3439,13 +3439,16 @@ function Import_pulldown( wiki, notebook_id, invoker, anchor ) { Pulldown.call( this, wiki, notebook_id, "import_pulldown", anchor, null, false ); + var vaguely_random = new Date().getTime(); this.invoker = invoker; this.iframe = createDOM( "iframe", { "src": "/files/import_page?notebook_id=" + notebook_id, "frameBorder": "0", "scrolling": "no", - "id": "upload_frame", - "name": "upload_frame", + // if a new iframe has an id/name that WebKit has already seen, then it will just use its + // previous src value and ignore our new src value here. workaround: don't use the same id! + "id": "upload_frame_" + vaguely_random, + "name": "upload_frame_" + vaguely_random, "class": "upload_frame" } ); this.iframe.pulldown = this; @@ -3460,8 +3463,8 @@ function Import_pulldown( wiki, notebook_id, invoker, anchor ) { this.progress_iframe = createDOM( "iframe", { "frameBorder": "0", "scrolling": "no", - "id": "progress_frame", - "name": "progress_frame", + "id": "progress_frame_" + vaguely_random, + "name": "progress_frame_" + vaguely_random, "class": "upload_frame" } ); addElementClass( this.progress_iframe, "undisplayed" ); @@ -3497,10 +3500,7 @@ Import_pulldown.prototype.upload_started = function ( file_id ) { removeElementClass( this.progress_iframe, "undisplayed" ); var progress_url = "/files/progress?file_id=" + file_id + "&filename=" + escape( filename ); - if ( frames[ "progress_frames" ] ) - frames[ "progress_frame" ].location.href = progress_url; - else - this.progress_iframe.src = progress_url; + this.progress_iframe.src = progress_url; } Import_pulldown.prototype.upload_complete = function () { diff --git a/view/Progress_bar.py b/view/Progress_bar.py index 037954b..a73a0a3 100644 --- a/view/Progress_bar.py +++ b/view/Progress_bar.py @@ -37,7 +37,7 @@ def stream_progress( uploading_file, filename, fraction_reported ): 0%% - + @@ -83,13 +83,13 @@ def stream_progress( uploading_file, filename, fraction_reported ): general_error_script = \ """ - withDocument( window.parent.document, function () { var frame = getElement( 'upload_frame' ); if ( frame && frame.pulldown ) frame.pulldown.cancel_due_to_error( "%s" ); } ); + withDocument( window.parent.document, function () { var frame = getFirstElementByTagAndClassName( "iframe", "upload_frame" ); if ( frame && frame.pulldown ) frame.pulldown.cancel_due_to_error( "%s" ); } ); """ quota_error_script = \ """ - withDocument( window.parent.document, function () { var frame = getElement( 'upload_frame' ); if ( frame && frame.pulldown ) frame.pulldown.cancel_due_to_quota(); } ); + withDocument( window.parent.document, function () { var frame = getFirstElementByTagAndClassName( "iframe", "upload_frame" ); if ( frame && frame.pulldown ) frame.pulldown.cancel_due_to_quota(); } ); """