Replace addEventListener call with jQuery's .on()

Bug: 70553
Change-Id: I24680e7b7759d30eca2a733d670e10c0b4bfe7ab
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/863
This commit is contained in:
Gilles Dubuc 2014-09-09 10:56:13 +02:00
parent d4666c5715
commit b70fa7251d
2 changed files with 4 additions and 26 deletions

View file

@ -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' );

View file

@ -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,