Henning Snater has uploaded a new change for review.

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


Change subject: (bug 48145) Improved input extender/list rotator hiding routine
......................................................................

(bug 48145) Improved input extender/list rotator hiding routine

Using jQuery's closest() instead of messing with stopPropagation().

Change-Id: I7aee23c767e54dc4916241df473cde68df357995
---
M ValueView/resources/jquery.ui/jquery.ui.inputextender.js
M ValueView/resources/jquery.ui/jquery.ui.listrotator.js
2 files changed, 28 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues 
refs/changes/78/64078/1

diff --git a/ValueView/resources/jquery.ui/jquery.ui.inputextender.js 
b/ValueView/resources/jquery.ui/jquery.ui.inputextender.js
index 577fe05..363a9c0 100644
--- a/ValueView/resources/jquery.ui/jquery.ui.inputextender.js
+++ b/ValueView/resources/jquery.ui/jquery.ui.inputextender.js
@@ -88,7 +88,6 @@
                        .addClass( this.widgetBaseClass + '-extension 
ui-widget-content' )
                        .on( 'click.' + this.widgetName, function( event ) {
                                clearTimeout( self._animationTimeout );
-                               event.stopPropagation();
                                self.showExtension();
                        } )
                        .on( 'toggleranimationstep.' + this.widgetName, 
function( event, now, tween ) {
@@ -128,21 +127,23 @@
                        }
 
                        // Blurring by clicking away from the widget (one 
handler is sufficient):
-                       if( $( ':' + this.widgetBaseClass ).length === 1 ) {
-                               $( 'html' ).on( 'click.' + this.widgetName, 
function( event ) {
-                                       // Loop through all widgets and hide 
content when having clicked out of it:
-                                       var $widgetNodes = $( ':' + 
self.widgetBaseClass );
-                                       $widgetNodes.each( function( i, 
widgetNode ) {
-                                               var widget = $( widgetNode 
).data( self.widgetName );
-                                               if(
-                                                       $( event.target 
).closest( widget.$container ).length === 0
-                                                       && !widget.element.is( 
':focus' )
-                                               ) {
-                                                       widget.hideExtension();
-                                               }
-                                       } );
+                       $( 'html' )
+                       .off( '.' + this.widgetName )
+                       .on( 'click.' + this.widgetName, function( event ) {
+                               // Loop through all widgets and hide content 
when having clicked out of it:
+                               var $widgetNodes = $( ':' + 
self.widgetBaseClass );
+                               $widgetNodes.each( function( i, widgetNode ) {
+                                       var widget = $( widgetNode ).data( 
self.widgetName ),
+                                               $target = $( event.target );
+
+                                       // Hide the extension neither it nor 
the corresponding input element is
+                                       // clicked:
+                                       if( !$target.closest( 
widget.element.add( widget.$extension ) ).length ) {
+                                               widget.hideExtension();
+                                       }
+
                                } );
-                       }
+                       } );
 
                        this._draw();
 
@@ -162,10 +163,12 @@
                 */
                destroy: function() {
                        this.$extension.remove();
+
+                       $.Widget.prototype.destroy.call( this );
+
                        if( $( ':' + this.widgetBaseClass ).length === 0 ) {
                                $( 'html' ).off( '.' + this.widgetName );
                        }
-                       $.Widget.prototype.destroy.call( this );
                },
 
                /**
diff --git a/ValueView/resources/jquery.ui/jquery.ui.listrotator.js 
b/ValueView/resources/jquery.ui/jquery.ui.listrotator.js
index 068276f..a4a87df 100644
--- a/ValueView/resources/jquery.ui/jquery.ui.listrotator.js
+++ b/ValueView/resources/jquery.ui/jquery.ui.listrotator.js
@@ -226,14 +226,16 @@
                        .off( '.' + this.widgetName )
                        .on( 'click.' + this.widgetBaseClass, function( event ) 
{
                                $( ':' + self.widgetBaseClass ).each( function( 
i, node ) {
-                                       $( node ).data( 'listrotator' 
).$menu.hide();
-                               } );
-                       } );
+                                       var $target = $( event.target ),
+                                               listrotator = $( node ).data( 
'listrotator' );
 
-                       // Prevent propagation of clicking on the "current" 
section as well as on the menu in
-                       // order to not trigger the event handler assigned to 
the html element.
-                       this.$menu.add( this.$curr ).on( 'click.' + 
this.widgetBaseClass, function( event ) {
-                               event.stopPropagation();
+                                       // Hide the menu if it is neither the 
"current" node nor the menu's node that
+                                       // has been clicked.
+                                       if( !$target.closest( 
listrotator.$curr.add( listrotator.$menu ) ).length ) {
+                                               listrotator.$menu.hide();
+                                       }
+
+                               } );
                        } );
 
                        // Focus on first element:

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7aee23c767e54dc4916241df473cde68df357995
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>

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

Reply via email to