Daniel Kinzler has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/49633


Change subject: (bug 44744) copyright tooltip will now always be shown
......................................................................

(bug 44744) copyright tooltip will now always be shown

Even if an error tooltip appears on the save button, the copyright tooltip will 
still be shown.
For this to work, the copyright tooltip now is appended to a new toolbar 
element, only appended
whenever global edit mode gets triggered.

patch set 4: some cleanup

Change-Id: Ic0ecf1b75717cf3a6eb7f6cfe2df3be50126a297
---
M lib/resources/wikibase.ui.PropertyEditTool.EditableValue.Interface.js
M lib/resources/wikibase.ui.Toolbar.Label.js
M lib/resources/wikibase.ui.Tooltip.Extension.js
M lib/resources/wikibase.ui.Tooltip.js
M repo/resources/wikibase.ui.entityViewInit.js
5 files changed, 49 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/33/49633/1

diff --git 
a/lib/resources/wikibase.ui.PropertyEditTool.EditableValue.Interface.js 
b/lib/resources/wikibase.ui.PropertyEditTool.EditableValue.Interface.js
index 9060f7c..443bf81 100644
--- a/lib/resources/wikibase.ui.PropertyEditTool.EditableValue.Interface.js
+++ b/lib/resources/wikibase.ui.PropertyEditTool.EditableValue.Interface.js
@@ -562,7 +562,7 @@
 // add tooltip functionality to EditableValue:
 wb.ui.Tooltip.Extension.useWith( 
wb.ui.PropertyEditTool.EditableValue.Interface, {
        // overwrite required functions:
-       _getTooltipParent: function() {
+       getTooltipParent: function() {
                return this._subject;
        }
 } );
diff --git a/lib/resources/wikibase.ui.Toolbar.Label.js 
b/lib/resources/wikibase.ui.Toolbar.Label.js
index ad8919c..4f60a22 100644
--- a/lib/resources/wikibase.ui.Toolbar.Label.js
+++ b/lib/resources/wikibase.ui.Toolbar.Label.js
@@ -53,7 +53,7 @@
        },
 
        _initElem: function( content ) {
-               if ( typeof content == String ) {
+               if ( typeof content === 'string' ) {
                        content = $.trim( content );
                }
                this._elem = $( '<span/>', {
@@ -78,7 +78,7 @@
         */
        setContent: function( content ) {
                this._elem.empty();
-               if ( typeof content == 'string' ) {
+               if ( typeof content === 'string' ) {
                        content = $.trim( content );
                }
                this._elem.append( content );
@@ -96,10 +96,22 @@
                if( contents.length === 1 && contents[0].nodeType === 3 ) {
                        // return the text
                        return contents.text();
-               } else {
-                       // return jQuery object
-                       return contents;
                }
+               // return jQuery object
+               return contents;
+       },
+
+       /**
+        * Returns the DOM node representing the toolbar element.
+        * Allows for adding additional styles to the element. Should not be 
abused to remove the
+        * element from the toolbar, for doing this, 
wb.ui.Toolbar.removeElement should be used.
+        *
+        * @since 0.4
+        *
+        * @return jQuery
+        */
+       getElement: function() {
+               return this._elem;
        },
 
        /**
@@ -173,7 +185,7 @@
 // add tooltip functionality to EditableValue:
 wb.ui.Tooltip.Extension.useWith( wb.ui.Toolbar.Label, {
        // overwrite required functions:
-       _getTooltipParent: function() {
+       getTooltipParent: function() {
                return this._elem;
        }
 } );
diff --git a/lib/resources/wikibase.ui.Tooltip.Extension.js 
b/lib/resources/wikibase.ui.Tooltip.Extension.js
index 0c56359..f1e9187 100644
--- a/lib/resources/wikibase.ui.Tooltip.Extension.js
+++ b/lib/resources/wikibase.ui.Tooltip.Extension.js
@@ -20,7 +20,7 @@
  * @example:
  * var SomeConstructor = wb.utilities.inherit( Object, function() {...} );
  * wb.ui.Tooltip.Ext.extend( SomeConstructor ); // makes setTooltip and other 
functions available
- * SomeConstructor.prototype._getTooltipParent = function() { return 
this.someNode };
+ * SomeConstructor.prototype.getTooltipParent = function() { return 
this.someNode };
  * SomeConstructor.setTooltip( someTooltip );
  *
  * @since 0.1
@@ -39,7 +39,7 @@
         *
         * @see wb.utilities.abstractFunction
         */
-       _getTooltipParent: wb.utilities.abstractFunction,
+       getTooltipParent: wb.utilities.abstractFunction,
 
        /**
         * Attaches a tooltip message to the extended element.
@@ -59,12 +59,12 @@
                }
                if ( typeof tooltip === 'string' || tooltip instanceof $ ) {
                        // build new tooltip from string:
-                       this._getTooltipParent().attr( 'title', tooltip );
-                       this._tooltip = new wb.ui.Tooltip( 
this._getTooltipParent(), {}, tooltip );
+                       this.getTooltipParent().attr( 'title', tooltip );
+                       this._tooltip = new wb.ui.Tooltip( 
this.getTooltipParent(), {}, tooltip );
                } else if ( tooltip instanceof wb.ui.Tooltip ) {
                        this._tooltip = tooltip;
                } else if ( tooltip instanceof wb.RepoApiError ) {
-                       this._tooltip = new wb.ui.Tooltip( 
this._getTooltipParent(), {}, tooltip, { gravity: 'nw' } );
+                       this._tooltip = new wb.ui.Tooltip( 
this.getTooltipParent(), {}, tooltip, { gravity: 'nw' } );
                } else {
                        throw new Error( 'Insufficient tooltip message given' );
                }
diff --git a/lib/resources/wikibase.ui.Tooltip.js 
b/lib/resources/wikibase.ui.Tooltip.js
index 7328aac..8451c5d 100644
--- a/lib/resources/wikibase.ui.Tooltip.js
+++ b/lib/resources/wikibase.ui.Tooltip.js
@@ -97,13 +97,10 @@
                                this._DomContent = tooltipContent;
                        }
                }
-               if (  tipsyConfig !== undefined ) {
-                       this._tipsyConfig = tipsyConfig;
-               }
-               if ( this._tipsyConfig == null || typeof 
this._tipsyConfig.gravity == undefined ) {
-                       this._tipsyConfig = {};
-                       this.setGravity( 'ne' );
-               }
+
+               this._tipsyConfig = tipsyConfig || {};
+               this.setGravity( this._tipsyConfig.gravity || 'ne' );
+
                this._initTooltip();
 
                jQuery.data( this._subject[0], 'wikibase.ui.tooltip', this );
@@ -233,7 +230,7 @@
        show: function( permanent ) {
                if ( !this._isVisible ) {
                        this._tipsy.show();
-                       if ( this._error != null ) {
+                       if ( this._error !== null ) {
                                this._tipsy.tip().addClass( 'wb-error' );
 
                                // hide error tooltip when clicking outside of 
it
@@ -246,7 +243,7 @@
 
                                // will lose inner click event on resizing 
(Details link) when not re-constructed on show
                                this._tipsy.tip().find( '.tipsy-inner' 
).empty().append( this._buildErrorTooltip() );
-                       } else if ( this._DomContent != null ) {
+                       } else if ( this._DomContent !== null ) {
                                this._tipsy.tip().find( '.tipsy-inner' 
).empty().append( this._DomContent );
                        }
                        this._isVisible = true;
@@ -286,15 +283,15 @@
         */
        setGravity: function( gravity ) {
                // flip horizontal direction in rtl language
-               if ( document.documentElement.dir == 'rtl' ) {
-                       if ( gravity.search( /e/ ) != -1) {
+               if ( document.documentElement.dir === 'rtl' ) {
+                       if ( gravity.search( /e/ ) !== -1) {
                                gravity = gravity.replace( /e/g, 'w' );
                        } else {
                                gravity = gravity.replace( /w/g, 'e' );
                        }
                }
                this._tipsyConfig.gravity = gravity;
-               if ( this._tipsy != null ) {
+               if ( this._tipsy !== null ) {
                        this._tipsy.options.gravity = gravity;
                }
        },
@@ -306,7 +303,7 @@
         */
        setContent: function( content ) {
                this._DomContent = null;
-               if ( typeof content == 'string' ) {
+               if ( typeof content === 'string' ) {
                        this._tipsy.$element.attr( 'original-title', content );
                } else {
                        this._DomContent = content;
diff --git a/repo/resources/wikibase.ui.entityViewInit.js 
b/repo/resources/wikibase.ui.entityViewInit.js
index 77a906c..000976a 100644
--- a/repo/resources/wikibase.ui.entityViewInit.js
+++ b/repo/resources/wikibase.ui.entityViewInit.js
@@ -167,6 +167,9 @@
 
                        // add copyright warning to 'save' button if there is 
one:
                        if( mw.config.exists( 'wbCopyrightWarning' ) ) {
+
+                               var $message = $( '<span>' + mw.config.get( 
'wbCopyrightWarning' ) + '</span>' );
+
                                var $activeToolbar = $( '.wb-edit' )
                                        // label/description of EditableValue 
always in edit mode if empty, 2nd '.wb-edit'
                                        // on PropertyEditTool only appended 
when really being edited by the user though
@@ -178,21 +181,29 @@
                                }
 
                                var toolbar = $activeToolbar.data( 'wb-toolbar' 
);
+
                                var tooltip = new wb.ui.Tooltip(
-                                       // TODO: make _getTooltipParent public 
or add a Toolbar.Label.getElement()
-                                       toolbar.btnSave._getTooltipParent(),
+                                       toolbar.btnSave.getTooltipParent(), // 
adjust tooltip to save button
                                        {},
-                                       $( '<span>' + mw.config.get( 
'wbCopyrightWarning' ) + '</span>' ),
+                                       $message,
                                        // assuming the toolbar is used on the 
right side of some edit UI, we want to
                                        // point the tooltip away from that so 
it won't overlap with it:
                                        { gravity: 'nw' }
                                );
-                               toolbar.btnSave.setTooltip( tooltip );
+
+                               // Tooltip gets its own anchor since other 
elements might have their own tooltip.
+                               // we don't even have to add this new toolbar 
element to the toolbar, we only use it
+                               // to manage the tooltip which will have the 
'save' button as element to point to.
+                               // The 'save' button can still have its own 
tooltip though.
+                               var messageAnchor = new wb.ui.Toolbar.Label( $( 
'<span/>' ) );
+                               messageAnchor.setTooltip( tooltip );
+
                                tooltip.show( true ); // show permanently, not 
just on hover!
 
                                // destroy tooltip after edit mode gets closed 
again:
                                $( wb ).one( 'stopItemPageEditMode', function( 
event ) {
                                        tooltip.destroy();
+                                       toolbar.removeElement( messageAnchor );
                                } );
                        }
                } );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic0ecf1b75717cf3a6eb7f6cfe2df3be50126a297
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: mw1.21-wmf10
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to