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 = $( '<span/>', {
-                       'class': 'mw-help-field-hint',
-                       style: 
'display:inline-block;text-decoration:none;width:8px;', // TODO: Get rid of 
inline styles.
-                       html: '&nbsp;' // 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;
+               }
+
+               this._$tooltipAnchor = $( '<span/>', {
+                       'class': 'mw-help-field-hint',
+                       style: 
'display:inline-block;text-decoration:none;width:8px;', // TODO: Get rid of 
inline styles.
+                       html: '&nbsp;' // 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 );
+               }
+
+               return this._$tooltipAnchor;
+       },
+
+       /**
         * Returns a button by its name creating the button if it has not yet 
been created.
         *
         * @param {string} buttonName "edit"|"save"|"remove"|"cancel"

-- 
To view, visit https://gerrit.wikimedia.org/r/161927
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I46772ea8cbb9457654070b2405c2b30428e37c53
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <henning.sna...@wikimedia.de>
Gerrit-Reviewer: Adrian Lang <adrian.l...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to