diff --git a/resources/mmv/ui/mmv.ui.canvas.js b/resources/mmv/ui/mmv.ui.canvas.js index 703182f42..5f9ad230c 100644 --- a/resources/mmv/ui/mmv.ui.canvas.js +++ b/resources/mmv/ui/mmv.ui.canvas.js @@ -172,13 +172,9 @@ C.attach = function() { var canvas = this; - // TODO: Try to use Element.handleEvent() instead ! - if ( !this.resizeListener ) { - this.resizeListener = function () { - canvas.$mainWrapper.trigger( $.Event( 'mmv-resize') ); - }; - window.addEventListener( 'resize', this.resizeListener ); - } + $( window ).on( 'resize.mmv-canvas', function () { + canvas.$mainWrapper.trigger( $.Event( 'mmv-resize' ) ); + } ); this.$imageDiv.on( 'click.mmv-canvas', 'img', function () { canvas.$mainWrapper.trigger( $.Event( 'mmv-image-click' ) ); @@ -191,10 +187,7 @@ C.unattach = function() { this.clearEvents(); - if ( this.resizeListener ) { - window.removeEventListener( 'resize', this.resizeListener ); - this.resizeListener = null; - } + $( window ).off( 'resize.mmv-canvas' ); this.$imageDiv.off( 'click.mmv-canvas' ); diff --git a/tests/qunit/mmv/ui/mmv.ui.canvas.test.js b/tests/qunit/mmv/ui/mmv.ui.canvas.test.js index 63d53edb1..0fead1bba 100644 --- a/tests/qunit/mmv/ui/mmv.ui.canvas.test.js +++ b/tests/qunit/mmv/ui/mmv.ui.canvas.test.js @@ -99,21 +99,6 @@ assert.strictEqual( canvas.$image.css( 'maxHeight' ), canvas.$imageDiv.height() + 'px', 'MaxHeight set correctly.' ); } ); - QUnit.test( 'attach and unattach', 3, function( assert ) { - var $qf = $( '#qunit-fixture' ), - canvas = new mw.mmv.ui.Canvas( $qf ); - - assert.ok( ! canvas.resizeListener, 'resize listener has not been set yet.' ); - - canvas.attach(); - - assert.ok( canvas.resizeListener, 'resize listener is set.' ); - - canvas.unattach(); - - assert.ok( ! canvas.resizeListener, 'resize listener has been removed.' ); - } ); - QUnit.test( 'maybeDisplayPlaceholder: Constrained area for SVG files', 4, function ( assert ) { var $image, blurredThumbnailShown,