[MediaWiki-commits] [Gerrit] Deferred edittoolbar tooltip init to when switching to edit ... - change (mediawiki...Wikibase)
jenkins-bot has submitted this change and it was merged. Change subject: Deferred edittoolbar tooltip init to when switching to edit mode .. Deferred edittoolbar tooltip init to when switching to edit mode Change-Id: I46772ea8cbb9457654070b2405c2b30428e37c53 --- M lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js 1 file changed, 53 insertions(+), 37 deletions(-) Approvals: Adrian Lang: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js b/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js index 9a09df2..279ef59 100644 --- a/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js +++ b/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js @@ -74,8 +74,8 @@ _buttons: null, /** -* Node holding the tooltips image with the tooltip itself attached. -* @type {jQuery} +* Node holding the tooltip image with the tooltip itself attached. +* @type {null|jQuery} */ _$tooltipAnchor: null, @@ -111,13 +111,15 @@ this.options.interactionWidget.element.off( '.' + this.widgetName ); - var $wbtooltip = this._$tooltipAnchor.find( ':wikibase-wbtooltip' ), - wbtooltip = $wbtooltip.data( 'wbtooltip' ); - if( wbtooltip ) { - wbtooltip.destroy(); - } + if( this._$tooltipAnchor ) { + var $wbtooltip = this._$tooltipAnchor.find( ':wikibase-wbtooltip' ), + wbtooltip = $wbtooltip.data( 'wbtooltip' ); + if( wbtooltip ) { + wbtooltip.destroy(); + } - this._$tooltipAnchor.data( 'wikibase-toolbaritem' ).destroy(); + this._$tooltipAnchor.data( 'wikibase-toolbaritem' ).destroy(); + } this._getContainer().off( '.' + this.widgetName ); @@ -151,8 +153,7 @@ }, _initToolbar: function() { - var self = this, - $container = this._getContainer(), + var $container = this._getContainer(), $toolbar = $container.children( '.wikibase-toolbar' ); if( !$toolbar.length ) { @@ -162,31 +163,6 @@ $toolbar.toolbar( { renderItemSeparators: true } ); - - this._$tooltipAnchor = $( '', { - 'class': 'mw-help-field-hint', - style: 'display:inline-block;text-decoration:none;width:8px;', // TODO: Get rid of inline styles. - html: ' ' // TODO find nicer way to hack Webkit browsers to display tooltip image (see also css) - } ).toolbaritem(); - - // Support promises instead of strings, too, since $.wikibase.claimview does not know - // immediately after creation which help message to show. - // TODO: This should be replaced by a dynamic getter so that views can arbitrarily - // change their help messages anywhere in their lifecycle. - function addTooltip( helpMessage ) { - if( self._$tooltipAnchor ) { - self._$tooltipAnchor.wbtooltip( { - content: helpMessage - } ); - } - } - - var helpMessage = this.options.interactionWidget.option( 'helpMessage' ); - if( helpMessage.done && typeof helpMessage !== 'string' ) { - helpMessage.done( addTooltip ); - } else { - addTooltip( helpMessage ); - } this._attachEventHandlers(); @@ -297,7 +273,7 @@ editGroup.option( '$content', $buttons ); this._getContainer() - .append( this._$tooltipAnchor ) + .append( this._getTooltipAnchor() ) .addClass( this.widgetBaseClass + '-ineditmode' ); }, @@ -317,7 +293,9 @@ return; } - this._$tooltipAnchor.detach(); + if( this._$tooltipAnchor ) { + this._$tooltipAnchor.detach(); + } var $editGroup = this._getContainer().children( ':wikibase-toolbar' ), editGroup = $editGroup.data( 'toolbar' ); @@ -343,6 +321,44 @@ }, /** +* @return {jQuery} +*/ + _getTooltipAnchor: function() { + var self = this; + + if( this._$tooltipAnchor ) { + return this._$tooltipAnchor; + } + +
[MediaWiki-commits] [Gerrit] Deferred edittoolbar tooltip init to when switching to edit ... - change (mediawiki...Wikibase)
Henning Snater has uploaded a new change for review. https://gerrit.wikimedia.org/r/161927 Change subject: Deferred edittoolbar tooltip init to when switching to edit mode .. Deferred edittoolbar tooltip init to when switching to edit mode Change-Id: I46772ea8cbb9457654070b2405c2b30428e37c53 --- M lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js 1 file changed, 45 insertions(+), 31 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/27/161927/1 diff --git a/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js b/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js index 930d7fc..13ef76b 100644 --- a/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js +++ b/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js @@ -74,8 +74,8 @@ _buttons: null, /** -* Node holding the tooltips image with the tooltip itself attached. -* @type {jQuery} +* Node holding the tooltip image with the tooltip itself attached. +* @type {null|jQuery} */ _$tooltipAnchor: null, @@ -151,8 +151,7 @@ }, _initToolbar: function() { - var self = this, - $container = this._getContainer(), + var $container = this._getContainer(), $toolbar = $container.children( '.wikibase-toolbar' ); if( !$toolbar.length ) { @@ -162,31 +161,6 @@ $toolbar.toolbar( { renderItemSeparators: true } ); - - this._$tooltipAnchor = $( '', { - 'class': 'mw-help-field-hint', - style: 'display:inline-block;text-decoration:none;width:8px;', // TODO: Get rid of inline styles. - html: ' ' // TODO find nicer way to hack Webkit browsers to display tooltip image (see also css) - } ).toolbaritem(); - - // Support promises instead of strings, too, since $.wikibase.claimview does not know - // immediately after creation which help message to show. - // TODO: This should be replaced by a dynamic getter so that views can arbitrarily - // change their help messages anywhere in their lifecycle. - function addTooltip( helpMessage ) { - if( self._$tooltipAnchor ) { - self._$tooltipAnchor.wbtooltip( { - content: helpMessage - } ); - } - } - - var helpMessage = this.options.interactionWidget.option( 'helpMessage' ); - if( helpMessage.done && typeof helpMessage !== 'string' ) { - helpMessage.done( addTooltip ); - } else { - addTooltip( helpMessage ); - } this._attachEventHandlers(); @@ -297,7 +271,7 @@ editGroup.option( '$content', $buttons ); this._getContainer() - .append( this._$tooltipAnchor ) + .append( this._getTooltipAnchor() ) .addClass( this.widgetBaseClass + '-ineditmode' ); }, @@ -317,7 +291,9 @@ return; } - this._$tooltipAnchor.detach(); + if( this._$tooltipAnchor ) { + this._$tooltipAnchor.detach(); + } var $editGroup = this._getContainer().children( ':wikibase-toolbar' ), editGroup = $editGroup.data( 'toolbar' ); @@ -343,6 +319,44 @@ }, /** +* @return {jQuery} +*/ + _getTooltipAnchor: function() { + var self = this; + + if( this._$tooltipAnchor ) { + return this._$tooltipAnchor; + } + + this._$tooltipAnchor = $( '', { + 'class': 'mw-help-field-hint', + style: 'display:inline-block;text-decoration:none;width:8px;', // TODO: Get rid of inline styles. + html: ' ' // TODO find nicer way to hack Webkit browsers to display tooltip image (see also css) + } ).toolbaritem(); + + // Support promises instead of strings, too, since $.wikibase.claimview does not know + // immediately after creation which help message to show. + // TODO: This should be replaced by a dynamic getter so that views can arbitrarily + // change their help messages anywhere in their lifecycle. + function addTooltip( helpMessage ) { + if( self._$tooltipAnchor ) { + self._$tooltipAnchor.wbto