Henning Snater has uploaded a new change for review.

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

Change subject: Suppress redrawing when initializing toolbar on existing nodes
......................................................................

Suppress redrawing when initializing toolbar on existing nodes

Change-Id: Id3e6273c233030afb35731da3b95c34768bf3257
---
M lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js
M lib/resources/jquery.wikibase/toolbar/jquery.wikibase.singlebuttontoolbar.js
M 
lib/resources/jquery.wikibase/toolbar/themes/default/jquery.wikibase.toolbarbutton.css
M repo/includes/View/SectionEditLinkGenerator.php
4 files changed, 65 insertions(+), 50 deletions(-)


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

diff --git 
a/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js 
b/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js
index 327c94f..0d12ae0 100644
--- a/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js
+++ b/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.edittoolbar.js
@@ -100,9 +100,16 @@
 
                this._buttons = {};
 
-               this._initSubToolbar();
+               var $scrapedSubToolbar = this._getContainer().children( 
'.wikibase-toolbar' );
+
+               this._initSubToolbar( $scrapedSubToolbar );
                this._attachEventHandlers();
-               this._toNonEditMode();
+
+               if( $scrapedSubToolbar.length ) {
+                       this.toNonEditMode();
+               } else {
+                       this._toNonEditMode();
+               }
        },
 
        /**
@@ -156,18 +163,21 @@
 
        /**
         * Initializes the sub toolbar encapsulating the toolbar buttons 
excluding the tooltip anchor.
+        *
+        * @param {jQuery} $subToolbar
         */
-       _initSubToolbar: function() {
-               var $container = this._getContainer(),
-                       $subToolbar = $container.children( '.wikibase-toolbar' 
);
+       _initSubToolbar: function( $subToolbar ) {
+               var $content = $();
 
                if( !$subToolbar.length ) {
-                       $subToolbar = $( '<span/>' ).appendTo( $container );
+                       $subToolbar = $( '<span/>' ).appendTo( 
this._getContainer() );
                } else {
                        this._scrapeButtons( $subToolbar );
+                       $content = $subToolbar.children();
                }
 
                $subToolbar.toolbar( {
+                       $content: $content,
                        renderItemSeparators: true
                } );
        },
@@ -251,27 +261,22 @@
 
                this._getContainer()
                .on( 'toolbarbuttonaction.' + this.widgetName, function( event 
) {
-                       switch( event.target ) {
-                               case self._buttons.edit.get( 0 ):
-                                       
self.options.interactionWidget.element.one(
-                                               prefix + 'afterstartediting.' + 
self.widgetName,
-                                               function() {
-                                                       self._trigger( 'edit' );
-                                               }
-                                       );
-                                       
self.options.interactionWidget.startEditing();
-                                       break;
-                               case self._buttons.save.get( 0 ):
-                                       
self.options.interactionWidget.stopEditing();
-                                       break;
-                               case self.options.onRemove && 
self._buttons.remove.get( 0 ):
-                                       self.disable();
-                                       self.toggleActionMessage( mw.msg( 
'wikibase-remove-inprogress' ) );
-                                       self.options.onRemove();
-                                       break;
-                               case self._buttons.cancel.get( 0 ):
-                                       
self.options.interactionWidget.cancelEditing();
-                                       break;
+                       if( self._buttons.edit && event.target === 
self._buttons.edit.get( 0 ) ) {
+                               self.options.interactionWidget.element.one(
+                                       prefix + 'afterstartediting.' + 
self.widgetName,
+                                       function() {
+                                               self._trigger( 'edit' );
+                                       }
+                               );
+                               self.options.interactionWidget.startEditing();
+                       } else if( self._buttons.save && event.target === 
self._buttons.save.get( 0 ) ) {
+                               self.options.interactionWidget.stopEditing();
+                       } else if( self._buttons.remove && event.target === 
self._buttons.remove.get( 0 ) ) {
+                               self.disable();
+                               self.toggleActionMessage( mw.msg( 
'wikibase-remove-inprogress' ) );
+                               self.options.onRemove();
+                       } else if( self._buttons.cancel && event.target === 
self._buttons.cancel.get( 0 ) ) {
+                               self.options.interactionWidget.cancelEditing();
                        }
                } );
        },
diff --git 
a/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.singlebuttontoolbar.js 
b/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.singlebuttontoolbar.js
index 7b016b6..d51e409 100644
--- 
a/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.singlebuttontoolbar.js
+++ 
b/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.singlebuttontoolbar.js
@@ -42,29 +42,21 @@
                PARENT.prototype._create.call( this );
 
                if( !this.options.$content.length ) {
-                       this.options.$content = this._initDefaultButton();
-                       this.draw();
+                       var $scrapedButton = this._scrapeButton();
+                       this.options.$content = this._initDefaultButton( 
$scrapedButton );
+                       if( !$scrapedButton ) {
+                               this.draw();
+                       }
                }
        },
 
        /**
+        * @param {jQuery|null} $scrapedButton
         * @return {jQuery}
         */
-       _initDefaultButton: function() {
+       _initDefaultButton: function( $scrapedButton ) {
                var self = this,
-                       $container = this._getContainer(),
-                       $defaultButton = null;
-
-               // Scrape button from existing DOM if there is:
-               $container.children( '.wikibase-toolbar-button' ).each( 
function() {
-                       var $button = $( this );
-                       if( $button.text() === self.options.label ) {
-                               $defaultButton = $button;
-                               return false;
-                       }
-               } );
-
-               $defaultButton = $defaultButton || $( '<span/>' ).appendTo( 
$container );
+                       $defaultButton = $scrapedButton || $( '<span/>' );
 
                return $defaultButton.toolbarbutton( {
                        $label: this.options.label
@@ -74,6 +66,24 @@
                } );
        },
 
+       /**
+        * @return {jQuery}
+        */
+       _scrapeButton: function() {
+               var self = this,
+                       $defaultButton = null;
+
+               this._getContainer().children( '.wikibase-toolbar-button' 
).each( function() {
+                       var $button = $( this );
+                       if( $button.text() === self.options.label ) {
+                               $defaultButton = $button;
+                               return false;
+                       }
+               } );
+
+               return $defaultButton;
+       },
+
        focus: function() {
                var button = this.options.$content.first().data( 
'toolbarbutton' );
                if( button ) {
diff --git 
a/lib/resources/jquery.wikibase/toolbar/themes/default/jquery.wikibase.toolbarbutton.css
 
b/lib/resources/jquery.wikibase/toolbar/themes/default/jquery.wikibase.toolbarbutton.css
index 8732ce1..614b3ec 100644
--- 
a/lib/resources/jquery.wikibase/toolbar/themes/default/jquery.wikibase.toolbarbutton.css
+++ 
b/lib/resources/jquery.wikibase/toolbar/themes/default/jquery.wikibase.toolbarbutton.css
@@ -3,18 +3,18 @@
  * @author H. Snater < mediaw...@snater.com >
  */
 
-.wikibase-toolbarbutton.ui-state-disabled a {
+.wikibase-toolbarbutton-disabled a {
        cursor: default;
 }
 
-.wikibase-toolbarbutton.ui-state-disabled a:link,
-.wikibase-toolbarbutton.ui-state-disabled a:hover,
-.wikibase-toolbarbutton.ui-state-disabled a:active,
-.wikibase-toolbarbutton.ui-state-disabled a:visited {
+.wikibase-toolbarbutton-disabled a:link,
+.wikibase-toolbarbutton-disabled a:hover,
+.wikibase-toolbarbutton-disabled a:active,
+.wikibase-toolbarbutton-disabled a:visited {
        color: grey;
        text-decoration: none;
 }
 
-.wikibase-toolbarbutton.ui-state-disabled .ui-icon {
+.wikibase-toolbarbutton-disabled .ui-icon {
        background-image: 
url(../../../../../../../../resources/lib/jquery.ui/themes/smoothness/images/ui-icons_888888_256x240.png);
 }
diff --git a/repo/includes/View/SectionEditLinkGenerator.php 
b/repo/includes/View/SectionEditLinkGenerator.php
index f3dd661..522f96d 100644
--- a/repo/includes/View/SectionEditLinkGenerator.php
+++ b/repo/includes/View/SectionEditLinkGenerator.php
@@ -124,7 +124,7 @@
                        );
                } else {
                        return wfTemplate( 'wikibase-toolbar-button',
-                               'ui-state-disabled',
+                               'wikibase-toolbarbutton-disabled 
ui-state-disabled',
                                '#',
                                $buttonLabel
                        );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id3e6273c233030afb35731da3b95c34768bf3257
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <henning.sna...@wikimedia.de>

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

Reply via email to