Daniel Werner has uploaded a new change for review.
https://gerrit.wikimedia.org/r/79153
Change subject: Got rid of ugly "private" callback parameter in
jQuery.ui.inputextender's draw
......................................................................
Got rid of ugly "private" callback parameter in jQuery.ui.inputextender's draw
This also introduces a "toggle" event and function for the inputextender. The
event will always be
triggered when toggle is called or when the showExtension or hideExtension
functions result into
the status of the extension being toggled.
Change-Id: I5ee0e3320153a81d00fd55d6435395ce267bdf0d
---
M ValueView/resources/jquery.ui/jquery.ui.inputextender.js
1 file changed, 42 insertions(+), 22 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues
refs/changes/53/79153/1
diff --git a/ValueView/resources/jquery.ui/jquery.ui.inputextender.js
b/ValueView/resources/jquery.ui/jquery.ui.inputextender.js
index e897667..5ac6c50 100644
--- a/ValueView/resources/jquery.ui/jquery.ui.inputextender.js
+++ b/ValueView/resources/jquery.ui/jquery.ui.inputextender.js
@@ -26,6 +26,9 @@
* event bubbles up to the input extender's extension node, then this
will trigger the
* "contentanimation" event on the widget node.
*
+ * @event toggle: Triggered when the visibility of the extended content is
toggled.
+ * (1) {jQuery.Event}
+ *
* @event animation: Triggered at the beginning of an animation of the input's
extension.
* (1) {jQuery.AnimationEvent} animationEvent
*
@@ -228,9 +231,8 @@
* @param {Function} [callback] Invoked as soon as the
extension's show animation is done.
*/
showExtension: function( callback ) {
- if( !this._isExtended ) {
- this._isExtended = true;
- this.draw( callback );
+ if( !this.extensionIsActive() ) {
+ this.toggleExtension( callback );
}
},
@@ -240,11 +242,37 @@
* @param {Function} [callback] Invoked as soon as the
extension's hide animation is done.
*/
hideExtension: function( callback ) {
- if( this._isExtended ) {
- this._isExtended = false;
- this.draw( callback );
+ if( this.extensionIsActive() ) {
+ this.toggleExtension( callback );
}
},
+
+ /**
+ * Toggles the extension's state. Will hide the extension if it
is currently shown or
+ * show it if it is currently hidden.
+ *
+ * @param {Function} [callback] Invoked as soon as the
extension's toggle animation is done.
+ */
+ toggleExtension: $.NativeEventHandler( 'toggle', function( e,
callback ) {
+ this._isExtended = !this._isExtended;
+
+ if( callback ) {
+ var animationJob = this._isExtended ?
'extensionexpansion' : 'extensionremoval';
+ var $element = this.element;
+ var callbackRegistration = function(
animationEvent ) {
+ if( animationEvent.animationPurpose ===
animationJob ) {
+ $element.off(
this.widgetEventPrefix + 'animation', callbackRegistration );
+
animationEvent.animationCallbacks.add( 'done', function() {
+ callback();
+ } );
+ }
+ };
+ $element.on(
+ this.widgetEventPrefix + 'animation.' +
this.widgetName,
+ callbackRegistration );
+ }
+ this.draw();
+ } ),
/**
* Returns the input extension's node or null in case the
extension is currently not in its
@@ -281,14 +309,14 @@
/**
* Draws the widget.
*/
- draw: function( /* private: */ callback ) {
+ draw: function() {
this.element[ this._isExtended ? 'addClass' :
'removeClass' ](
this.widgetBaseClass + '-extended' );
- this._drawExtension( callback );
+ this._drawExtension();
},
- _drawExtension: function( callback ) {
+ _drawExtension: function() {
var extensionIsVisible = this.extensionIsVisible(),
$extension = this.$extension;
@@ -320,14 +348,14 @@
if( extensionIsVisible !== this._isExtended ) {
// Represent actual expansion status:
if( this._isExtended ) {
- this._drawExtensionExpansion( callback
);
+ this._drawExtensionExpansion();
} else {
- this._drawExtensionRemoval( callback );
+ this._drawExtensionRemoval();
}
}
},
- _drawExtensionExpansion: function( callback ) {
+ _drawExtensionExpansion: function() {
var self = this;
// When blurring the browser viewport and an
re-focusing, Chrome is firing the "focus"
@@ -341,12 +369,7 @@
'extensionexpansion',
'fadeIn',
{
- duration: 150,
- complete: function() {
- if( $.isFunction( callback ) ) {
- callback();
- }
- }
+ duration: 150
},
function( animationEvent ) {
self._trigger( 'animation',
animationEvent );
@@ -355,7 +378,7 @@
inputExtendersWithVisibleExtension.add( this );
},
- _drawExtensionRemoval: function( callback ) {
+ _drawExtensionRemoval: function() {
var self = this;
this.$extension.stop( true ).animateWithEvent(
@@ -365,9 +388,6 @@
duration: 150,
complete: function() {
inputExtendersWithVisibleExtension.remove( self );
- if( $.isFunction( callback ) ) {
- callback();
- }
}
},
function( animationEvent ) {
--
To view, visit https://gerrit.wikimedia.org/r/79153
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5ee0e3320153a81d00fd55d6435395ce267bdf0d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits