From b70fa7251d5a9052ceef37a1aa7dd2fd76476bfd Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Tue, 9 Sep 2014 10:56:13 +0200 Subject: [PATCH] Replace addEventListener call with jQuery's .on() Bug: 70553 Change-Id: I24680e7b7759d30eca2a733d670e10c0b4bfe7ab Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/863 --- resources/mmv/ui/mmv.ui.canvas.js | 15 ++++----------- tests/qunit/mmv/ui/mmv.ui.canvas.test.js | 15 --------------- 2 files changed, 4 insertions(+), 26 deletions(-) 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,