MarkTraceur has uploaded a new change for review.
https://gerrit.wikimedia.org/r/86811
Change subject: jquery audit on mw.IframeTransport.js
......................................................................
jquery audit on mw.IframeTransport.js
Also removed a jshint relaxing rule.
Bug: 53245
Change-Id: I74bbb0d4fab38385426520537a558a8a5ea82170
---
M resources/mw.IframeTransport.js
1 file changed, 25 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard
refs/changes/11/86811/1
diff --git a/resources/mw.IframeTransport.js b/resources/mw.IframeTransport.js
index 415f722..1017b56 100644
--- a/resources/mw.IframeTransport.js
+++ b/resources/mw.IframeTransport.js
@@ -1,4 +1,3 @@
-/* jshint scripturl: true */
( function ( mw, $ ) {
/**
* Represents a "transport" for files to upload; in this case an iframe.
@@ -11,6 +10,14 @@
* @param transportedCb callback to execute when we've finished the
upload
*/
mw.IframeTransport = function( $form, progressCb, transportedCb ) {
+ function setupFormCallback() {
+ transport.configureForm();
+ transport.$iframe.off( 'load', setupFormCallback );
+ }
+
+ var iframe,
+ transport = this;
+
this.$form = $form;
this.progressCb = progressCb;
this.transportedCb = transportedCb;
@@ -18,9 +25,6 @@
this.iframeId = 'f_' + ( $( 'iframe' ).length + 1 );
//IE only works if you "create element with the name" ( not jquery
style )
- var iframe,
- transport = this;
-
try {
iframe = document.createElement( '<iframe name="' +
this.iframeId + '">' );
} catch ( ex ) {
@@ -31,13 +35,14 @@
// we configure form on load, because the first time it loads, it's
blank
// then we configure it to deal with an API submission
- this.$iframe.attr( { 'src' : 'javascript:false;',
- 'id' : this.iframeId,
- 'name' : this.iframeId } )
- .load( function() { transport.configureForm(); } )
- .css( 'display', 'none' );
+ this.$iframe
+ .prop( 'src', '#' )
+ .prop( 'id', this.iframeId )
+ .prop( 'name', this.iframeId )
+ .load( setupFormCallback )
+ .addClass( 'hidden' );
- $( 'body' ).append( iframe );
+ $( 'body' ).append( this.$iframe );
};
mw.IframeTransport.prototype = {
@@ -49,20 +54,20 @@
var transport = this;
// Set the form target to the iframe
- this.$form.attr( 'target', this.iframeId );
+ this.$form.prop( 'target', this.iframeId );
// attach an additional handler to the form, so, when
submitted, it starts showing the progress
// XXX this is lame .. there should be a generic way to
indicate busy status...
- this.$form.submit( function() {
+ this.$form.submit( function () {
// mw.log( "mw.IframeTransport::configureForm>
submitting to iframe...", "debug" );
return true;
} );
// Set up the completion callback
- $( '#' + this.iframeId ).load( function() {
+ this.$iframe.load( function () {
// mw.log( "mw.IframeTransport::configureForm> received
result in iframe", "debug" );
transport.progressCb( 1.0 );
- transport.processIframeResult( $( this ).get( 0 ) );
+ transport.processIframeResult( this );
} );
},
@@ -72,9 +77,10 @@
*
* @param {Element} iframe iframe to extract result from
*/
- processIframeResult: function( iframe ) {
+ processIframeResult: function ( iframe ) {
var response, json,
- doc = iframe.contentDocument ? iframe.contentDocument :
frames[iframe.id].document;
+ doc = iframe.contentDocument ||
frames[iframe.id].document;
+
// Fix for Opera 9.26
if ( doc.readyState && doc.readyState !== 'complete' ) {
//mw.log( "mw.IframeTransport::processIframeResult>
not complete" );
@@ -86,6 +92,7 @@
//mw.log( "mw.IframeTransport::processIframeResult>
innerhtml" );
return;
}
+
if ( doc.XMLDocument ) {
// The response is a document property in IE
response = doc.XMLDocument;
@@ -95,6 +102,7 @@
// according to mdale we need to do this
// because IE does not load JSON properly in an iframe
json = $( doc.body ).find( 'pre' ).text();
+
// mw.log( "mw.IframeTransport::processIframeResult>
iframe:json::" + json );
// check that the JSON is not an XML error message
// (this happens when user aborts upload, we get the
API docs in XML wrapped in HTML)
@@ -107,6 +115,7 @@
// Response is a xml document
response = doc;
}
+
// Process the API result
this.transportedCb( response );
}
--
To view, visit https://gerrit.wikimedia.org/r/86811
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I74bbb0d4fab38385426520537a558a8a5ea82170
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits