Prtksxna has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/282207

Change subject: Add destroyInterface method to interactive tools
......................................................................

Add destroyInterface method to interactive tools

Change-Id: Ic15cf21cf33d22fa8a6c2259865ea7282d47efa9
---
M resources/lib/imageeditor/imageeditor.js
M resources/lib/imageeditor/imagetool.js
2 files changed, 38 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ImageTweaks 
refs/changes/07/282207/1

diff --git a/resources/lib/imageeditor/imageeditor.js 
b/resources/lib/imageeditor/imageeditor.js
index 6600c93..5710faa 100644
--- a/resources/lib/imageeditor/imageeditor.js
+++ b/resources/lib/imageeditor/imageeditor.js
@@ -158,12 +158,22 @@
  * Closes the editor.
  */
 mw.ImageEditor.prototype.close = function () {
+       this.cleanUpTools();
        this.$element.remove();
+};
 
-       // TODO hacky, standardize tool cleanup
-       if ( this.tools.crop && this.tools.crop.$cover ) {
-               this.tools.crop.$cover.remove();
-       }
+/**
+ * Cleans up interface loaded by interactive tools
+ */
+mw.ImageEditor.prototype.cleanUpTools = function () {
+       $.each( this.tools, function( name, tool ) {
+               if (
+                       tool.destroyInterface !== null &&
+                       tool.destroyInterface !== undefined
+               ) {
+                       tool.destroyInterface();
+               }
+       } );
 };
 
 /**
@@ -568,10 +578,7 @@
                        this.$cover.remove();
                }.bind( this ) );
 
-               this.cancel.on( 'click', function () {
-                       this.$cover.remove();
-                       this.deferred.reject();
-               }.bind( this ) );
+               this.cancel.on( 'click', this.destroyInterface.bind( this ) );
 
                controls = new OO.ui.HorizontalLayout( {
                        items: [
@@ -588,6 +595,11 @@
                this.drawCropTool( image );
        };
 
+       crop.destroyInterface = function () {
+               this.$cover.remove();
+               this.deferred.reject();
+       };
+
        crop.drawCropTool = function ( image ) {
                this.$canvas = $( image.canvas );
                this.xRatio = this.$canvas[ 0 ].width / ( this.$canvas.width() 
* 1.0 );
diff --git a/resources/lib/imageeditor/imagetool.js 
b/resources/lib/imageeditor/imagetool.js
index e88125f..8bacb12 100644
--- a/resources/lib/imageeditor/imagetool.js
+++ b/resources/lib/imageeditor/imagetool.js
@@ -86,10 +86,7 @@
  *                     this.deferred.resolve( this.doAction( image, action ) );
  *             }.bind( this ) );
  *
- *             this.cancel.on( 'click', function () {
- *                     // Reject the deferred if tool couldn't complete the 
action
- *                     this.deferred.reject();
- *             }.bind( this ) );
+ *             this.cancel.on( 'click', this.destroyInterface.bind( this ) );
  *
  *             controls = new OO.ui.HorizontalLayout( {
  *                     items: [
@@ -103,6 +100,13 @@
  *             } );
  *             panel.$element.append( controls.$element );
  *     };
+ *
+ *     crop.destroyInterface = function () {
+ *             this.$cover.remove();
+ *             // Reject the deferred if tool couldn't complete the action
+ *             this.deferred.reject();
+ *     };
+ *
  *
  *     crop.doAction = function ( image, action ) {
  *             // Save old image data before cropping, will need this for undo
@@ -208,6 +212,16 @@
  */
 ImageTool.prototype.setupInterface = null;
 
+/**
+ * Called by {@link #ImageEditor.cleanUpTools} while closing the tool.
+ * Could also be called within the tool to cancel the action and clean
+ * the interface elements.
+ *
+ * @abstract
+ * @method destroyInterface
+ */
+ImageTool.prototype.destroyInterface = null;
+
 window.ImageTool = ImageTool;
 
 }( jQuery, OO ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/282207
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic15cf21cf33d22fa8a6c2259865ea7282d47efa9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ImageTweaks
Gerrit-Branch: master
Gerrit-Owner: Prtksxna <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to