jenkins-bot has submitted this change and it was merged.
Change subject: Replace IframeTransport callbacks with OOJS events
......................................................................
Replace IframeTransport callbacks with OOJS events
Bug: T77124
Change-Id: Ic6d9f9dc4098c28de2d0e79af6ca91929d239bf2
---
M UploadWizard.php
M resources/mw.ApiUploadHandler.js
M resources/mw.IframeTransport.js
3 files changed, 97 insertions(+), 95 deletions(-)
Approvals:
Gilles: Looks good to me, approved
jenkins-bot: Verified
diff --git a/UploadWizard.php b/UploadWizard.php
index 1f5dc63..0b49595 100644
--- a/UploadWizard.php
+++ b/UploadWizard.php
@@ -103,6 +103,9 @@
$wgResourceModules['ext.uploadWizard.iFrameTransport'] = array(
'scripts' => 'mw.IframeTransport.js',
+ 'dependencies' => array(
+ 'oojs',
+ ),
) + $uploadWizardModuleInfo;
$wgResourceModules['ext.uploadWizard.apiUploadHandler'] = array(
diff --git a/resources/mw.ApiUploadHandler.js b/resources/mw.ApiUploadHandler.js
index f35816f..d0e42c6 100644
--- a/resources/mw.ApiUploadHandler.js
+++ b/resources/mw.ApiUploadHandler.js
@@ -24,16 +24,12 @@
this.configureForm();
this.transport = new mw.IframeTransport(
- this.$form,
- function ( fraction ) {
- handler.upload.setTransportProgress( fraction );
- },
-
- function ( result ) {
- handler.upload.setTransported( result );
- }
- );
-
+ this.$form
+ ).on( 'progress', function ( fraction ) {
+ handler.upload.setTransportProgress( fraction );
+ } ).on( 'transported', function ( result ) {
+ handler.upload.setTransported( result );
+ } );
};
mw.ApiUploadHandler.prototype = {
diff --git a/resources/mw.IframeTransport.js b/resources/mw.IframeTransport.js
index 858e2bc..a2cb1f1 100644
--- a/resources/mw.IframeTransport.js
+++ b/resources/mw.IframeTransport.js
@@ -1,17 +1,20 @@
-( function ( mw, $ ) {
+( function ( mw, $, oo ) {
+ var ITP;
+
/**
+ * @class mw.IframeTransport
* Represents a "transport" for files to upload; in this case an iframe.
* XXX dubious whether this is really separated from
"ApiUploadHandler", which does a lot of form config.
- *
* The iframe is made to be the target of a form so that the existing
page does not reload, even though it's a POST.
- * @param form jQuery selector for HTML form
- * @param progressCb callback to execute when we've started. (does
not do float here because iframes can't
- * monitor fractional
progress).
- * @param transportedCb callback to execute when we've finished the
upload
+ * @mixins OO.EventEmitter
+ * @constructor
+ * @param {jQuery} $form HTML form with the upload data.
*/
- mw.IframeTransport = function ( $form, progressCb, transportedCb ) {
+ mw.IframeTransport = function ( $form ) {
var iframe,
transport = this;
+
+ oo.EventEmitter.call( this );
function setupFormCallback() {
transport.configureForm();
@@ -23,8 +26,6 @@
}
this.$form = $form;
- this.progressCb = progressCb;
- this.transportedCb = transportedCb;
this.setUpStatus = $.Deferred();
this.iframeId = 'f_' + ( $( 'iframe' ).length + 1 );
@@ -57,82 +58,84 @@
$( 'body' ).append( this.$iframe );
};
- mw.IframeTransport.prototype = {
- /**
- * Accessor function
- * @return {jQuery.Deferred}
- */
- getSetUpStatus: function () {
- return this.setUpStatus;
- },
+ oo.mixinClass( mw.IframeTransport, oo.EventEmitter );
- /**
- * Configure a form with a File Input so that it submits to the
iframe
- * Ensure callback on completion of upload
- */
- configureForm: function () {
- var transport = this;
+ ITP = mw.IframeTransport.prototype;
- // Set the form target to the iframe
- 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 () {
- return true;
- } );
-
- // Set up the completion callback
- this.$iframe.load( function () {
- transport.progressCb( 1.0 );
- transport.processIframeResult( this );
- } );
- },
-
- /**
- * Process the result of the form submission, returned to an
iframe.
- * This is the iframe's onload event.
- *
- * @param {Element} iframe iframe to extract result from
- */
- processIframeResult: function ( iframe ) {
- var response, json,
- doc = iframe.contentDocument ||
frames[iframe.id].document;
-
- // Fix for Opera 9.26
- if ( doc.readyState && doc.readyState !== 'complete' ) {
- return;
- }
-
- // Fix for Opera 9.64
- if ( doc.body && doc.body.innerHTML === 'false' ) {
- return;
- }
-
- if ( doc.XMLDocument ) {
- // The response is a document property in IE
- response = doc.XMLDocument;
- } else if ( doc.body ) {
- // Get the json string
- // We're actually searching through an HTML doc
here --
- // according to mdale we need to do this
- // because IE does not load JSON properly in an
iframe
- json = $( doc.body ).find( 'pre' ).text();
-
- // 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)
- if ( json && json.substring(0, 5) !== '<?xml' )
{
- response = $.parseJSON( json );
- } else {
- response = {};
- }
- } else {
- // Response is a xml document
- response = doc;
- }
-
- // Process the API result
- this.transportedCb( response );
- }
+ /**
+ * Accessor function
+ * @return {jQuery.Deferred}
+ */
+ ITP.getSetUpStatus = function () {
+ return this.setUpStatus;
};
-}( mediaWiki, jQuery ) );
+
+ /**
+ * Configure a form with a File Input so that it submits to the iframe
+ * Ensure callback on completion of upload
+ */
+ ITP.configureForm = function () {
+ var transport = this;
+
+ // Set the form target to the iframe
+ 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 () {
+ return true;
+ } );
+
+ // Set up the completion callback
+ this.$iframe.load( function () {
+ transport.emit( 'progress', 1.0 );
+ transport.processIframeResult( this );
+ } );
+ };
+
+ /**
+ * Process the result of the form submission, returned to an iframe.
+ * This is the iframe's onload event.
+ *
+ * @param {Element} iframe iframe to extract result from
+ */
+ ITP.processIframeResult = function ( iframe ) {
+ var response, json,
+ doc = iframe.contentDocument ||
frames[iframe.id].document;
+
+ // Fix for Opera 9.26
+ if ( doc.readyState && doc.readyState !== 'complete' ) {
+ return;
+ }
+
+ // Fix for Opera 9.64
+ if ( doc.body && doc.body.innerHTML === 'false' ) {
+ return;
+ }
+
+ if ( doc.XMLDocument ) {
+ // The response is a document property in IE
+ response = doc.XMLDocument;
+ } else if ( doc.body ) {
+ // Get the json string
+ // We're actually searching through an HTML doc here --
+ // according to mdale we need to do this
+ // because IE does not load JSON properly in an iframe
+ json = $( doc.body ).find( 'pre' ).text();
+
+ // 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)
+ if ( json && json.substring(0, 5) !== '<?xml' ) {
+ response = $.parseJSON( json );
+ } else {
+ response = {};
+ }
+ } else {
+ // Response is a xml document
+ response = doc;
+ }
+
+ // Process the API result
+ this.emit( 'transported', response );
+ };
+}( mediaWiki, jQuery, OO ) );
--
To view, visit https://gerrit.wikimedia.org/r/178223
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic6d9f9dc4098c28de2d0e79af6ca91929d239bf2
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits