From 2277651f44dd1e07286befd675e5c0e069472a74 Mon Sep 17 00:00:00 2001 From: WMDE-Fisch Date: Wed, 31 Aug 2016 17:03:57 +0200 Subject: [PATCH] Avoid having multiple revision tooltips at once When rendering several RevisionListView items e.g. by loading and adding more revisions each one had its own 'currentTooltip' so the elements where not exclusive. This patch fixes that by looking for the class objects when closing tooltips or changing wrapper highlighting. Tooltip timeouts are still per-list but that should not affect the behavior with multiple lists. Bug: T143090 Change-Id: I23c61547e1a925da1c0b7e7a475ad61e6ed1b1b6 --- .../ext.RevisionSlider.RevisionListView.js | 34 ++++++------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/modules/ext.RevisionSlider.RevisionListView.js b/modules/ext.RevisionSlider.RevisionListView.js index f441a28b..dc618d5a 100644 --- a/modules/ext.RevisionSlider.RevisionListView.js +++ b/modules/ext.RevisionSlider.RevisionListView.js @@ -23,16 +23,6 @@ */ tooltipTimeout: -1, - /** - * @type {OO.ui.PopupWidget} - */ - currentTooltip: null, - - /** - * @type {jQuery} - */ - $highlightedRevisionWrapper: null, - /** * @param {number} revisionTickWidth * @param {number} positionOffset @@ -105,15 +95,16 @@ * Hides the current tooltip immediately */ hideCurrentTooltip: function () { + var $highlightedRevisionWrapper = $( '.mw-revslider-revision-wrapper-hovered' ), + $currentTooltip = $( '.mw-revslider-revision-tooltip' ); if ( this.tooltipTimeout !== -1 ) { window.clearTimeout( this.tooltipTimeout ); } - if ( this.$highlightedRevisionWrapper !== null ) { - this.$highlightedRevisionWrapper.removeClass( 'mw-revslider-revision-wrapper-hovered' ); + if ( $highlightedRevisionWrapper.length !== 0 ) { + $highlightedRevisionWrapper.removeClass( 'mw-revslider-revision-wrapper-hovered' ); } - if ( this.currentTooltip !== null ) { - this.currentTooltip.toggle( false ); - this.currentTooltip.$element.remove(); + if ( $currentTooltip.length !== 0 ) { + $currentTooltip.remove(); } }, @@ -123,14 +114,13 @@ * @param {jQuery} $rev */ hideTooltip: function ( $rev ) { - var self = this; + var $currentTooltip = $( '.mw-revslider-revision-tooltip' ); this.tooltipTimeout = window.setTimeout( function () { - if ( $rev !== null ) { + if ( $rev.length !== 0 ) { $rev.removeClass( 'mw-revslider-revision-wrapper-hovered' ); } - if ( self.currentTooltip !== null ) { - self.currentTooltip.toggle( false ); - self.currentTooltip.$element.remove(); + if ( $currentTooltip.length !== 0 ) { + $currentTooltip.remove(); } }, 500 ); }, @@ -160,8 +150,6 @@ tooltip.toggle( true ); $rev.addClass( 'mw-revslider-revision-wrapper-hovered' ); - this.$highlightedRevisionWrapper = $rev; - this.currentTooltip = tooltip; }, /** @@ -189,7 +177,7 @@ window.clearTimeout( self.tooltipTimeout ); } ) .on( 'mouseleave', '.mw-revslider-revision-tooltip', function () { - self.hideTooltip( self.$highlightedRevisionWrapper ); + self.hideTooltip( $( '.mw-revslider-revision-wrapper-hovered' ) ); } ); },