Henning Snater has uploaded a new change for review.
https://gerrit.wikimedia.org/r/72529
Change subject: Limiting number of registered event handlers in toolbar button
widget
......................................................................
Limiting number of registered event handlers in toolbar button widget
Change-Id: I111e61f2505da49598a854b034bae3055271aba1
---
M lib/resources/jquery.wikibase/toolbar/toolbarbutton.js
1 file changed, 31 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/29/72529/1
diff --git a/lib/resources/jquery.wikibase/toolbar/toolbarbutton.js
b/lib/resources/jquery.wikibase/toolbar/toolbarbutton.js
index f3eb040..486a2ba 100644
--- a/lib/resources/jquery.wikibase/toolbar/toolbarbutton.js
+++ b/lib/resources/jquery.wikibase/toolbar/toolbarbutton.js
@@ -11,9 +11,8 @@
var PARENT = $.wikibase.toolbarlabel;
/**
- * Represents a button within wikibase scope.
+ * Represents a toolbar button within wikibase scope.
*
- * @constructor
* @extends jQuery.wikibase.toolbarlabel
* @since 0.4
*
@@ -39,18 +38,34 @@
return true;
} );
- // disable button and attach tooltip when editing is restricted
- $( wb ).on( 'restrictEntityPageActions blockEntityPageActions',
function( event ) {
- self.disable();
+ // Disable button and attach tooltip when editing is
restricted. Registering the event
+ // handler once is enough.
+ // TODO: Disabling "edit" actions/buttons should be done from
out of the PropertyEditTool.
+ if( $( '.' + this.widgetBaseClass ).length === 0 ) {
+ // Can only find buttons that are in the DOM. However,
the event handler is not needed
+ // more than one. At least, remove previously attached
handler to not have it registered
+ // twice.
+ $( wb )
+ .off( 'restrictEntityPageActions.' +
this.widgetName
+ + ' blockEntityPageActions.' +
this.widgetName )
+ .on( 'restrictEntityPageActions.' +
this.widgetName
+ + ' blockEntityPageActions.' +
this.widgetName, function( event ) {
- var messageId = ( event.type ===
'blockEntityPageActions' )
- ? 'wikibase-blockeduser-tooltip-message'
- : 'wikibase-restrictionedit-tooltip-message';
+ $( '.' + self.widgetBaseClass ).each(
function( i, node ) {
+ var toolbarButton = $( node
).data( self.widgetName );
- self.setTooltip( mw.message( messageId ).escaped() );
+ toolbarButton.disable();
- self._tooltip.setGravity( 'nw' );
- } );
+ var messageId = ( event.type
=== 'blockEntityPageActions' )
+ ?
'wikibase-blockeduser-tooltip-message'
+ :
'wikibase-restrictionedit-tooltip-message';
+
+ toolbarButton.setTooltip(
mw.message( messageId ).escaped() );
+
+
toolbarButton._tooltip.setGravity( 'nw' );
+ } );
+ } );
+ }
},
/**
@@ -58,6 +73,11 @@
*/
destroy: function() {
PARENT.prototype.destroy.call( this );
+
+ if( $( '.' + this.widgetBaseClass ).length === 0 ) {
+ $( wb ).off( 'restrictEntityPageActions.' +
this.widgetName
+ + 'blockEntityPageActions.' + this.widgetName );
+ }
},
/**
--
To view, visit https://gerrit.wikimedia.org/r/72529
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I111e61f2505da49598a854b034bae3055271aba1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits