jenkins-bot has submitted this change and it was merged.
Change subject: Suppress redrawing when initializing toolbar on existing nodes
......................................................................
Suppress redrawing when initializing toolbar on existing nodes
Improves performance of toggling edit mode by reusing any previously generated
button DOM nodes,
instead of recreating them.
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
3 files changed, 64 insertions(+), 49 deletions(-)
Approvals:
Thiemo Mättig (WMDE): 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 48ab3ec..19a07cb 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 &&
$scrapedSubToolbar.children().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 ac3b0dc..3fc2976 100644
---
a/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.singlebuttontoolbar.js
+++
b/lib/resources/jquery.wikibase/toolbar/jquery.wikibase.singlebuttontoolbar.js
@@ -46,29 +46,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,
@@ -79,6 +71,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 < [email protected] >
*/
-.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);
}
--
To view, visit https://gerrit.wikimedia.org/r/161959
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id3e6273c233030afb35731da3b95c34768bf3257
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits