Henning Snater has uploaded a new change for review.

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

Change subject: Added "encapsulate" option to TemplatedWidget
......................................................................

Added "encapsulate" option to TemplatedWidget

Prevents events from bubbling up the DOM tree unnecessarily. ->78149

Change-Id: Iee90bfa54e8fdb0692d4bbe21ef2fd2d60aaccb8
---
M lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgrouplistview.js
M lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgroupview.js
M lib/resources/jquery.wikibase/jquery.wikibase.sitelinklistview.js
M lib/resources/jquery.wikibase/jquery.wikibase.sitelinkview.js
M repo/resources/jquery.ui/jquery.ui.EditableTemplatedWidget.js
M repo/resources/jquery.ui/jquery.ui.TemplatedWidget.js
6 files changed, 66 insertions(+), 21 deletions(-)


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

diff --git 
a/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgrouplistview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgrouplistview.js
index 0e9ffd5..f394465 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgrouplistview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgrouplistview.js
@@ -76,7 +76,8 @@
        },
 
        _createListview: function() {
-               var self = this;
+               var self = this,
+                       prefix = 
$.wikibase.sitelinkgroupview.prototype.widgetEventPrefix;
 
                this.$listview = this.element.find( '.wb-listview' );
 
@@ -98,7 +99,11 @@
                                        };
                                }
                        } ),
-                       value: self.options.value || null
+                       value: self.options.value || null,
+                       encapsulate: true
+               } )
+               .on( prefix + 'disable.' + this.widgetName, function( event ) {
+                       event.stopPropagation();
                } );
        },
 
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgroupview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgroupview.js
index c275f48..4e1068f 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgroupview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgroupview.js
@@ -156,25 +156,11 @@
 
                this.$sitelinklistview
                .on( prefix + 'change.' + this.widgetName, function( event ) {
-                       event.stopPropagation();
                        self._trigger( 'change' );
                } )
                .on( prefix + 'toggleerror.' + this.widgetName, function( 
event, error ) {
-                       event.stopPropagation();
                        self.setError( error );
                } )
-               .on(
-                       [
-                               prefix + 'create.' + this.widgetName,
-                               prefix + 'afterstartediting.' + this.widgetName,
-                               prefix + 'stopediting.' + this.widgetName,
-                               prefix + 'afterstopediting.' + this.widgetName,
-                               prefix + 'disable.' + this.widgetName
-                       ].join( ' ' ),
-                       function( event ) {
-                               event.stopPropagation();
-                       }
-               )
                .sitelinklistview( {
                        value: this._getSiteLinksOfGroup(),
                        allowedSiteIds: this.options.value
@@ -183,7 +169,8 @@
                        entityStore: this.options.entityStore,
                        siteLinksChanger: this.options.siteLinksChanger,
                        eventSingleton: this._eventSingleton,
-                       $counter: this.$counter
+                       $counter: this.$counter,
+                       encapsulate: true
                } );
        },
 
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.sitelinklistview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.sitelinklistview.js
index 6474e84..8b88a79 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.sitelinklistview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.sitelinklistview.js
@@ -137,7 +137,8 @@
                                }
                        } ),
                        value: self.options.value || null,
-                       listItemNodeName: 'LI'
+                       listItemNodeName: 'LI',
+                       encapsulate: true
                } )
                .on( prefix + 'change.' + this.widgetName, function( event ) {
                        event.stopPropagation();
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkview.js
index 72bf6ba..ad49e37 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkview.js
@@ -153,7 +153,8 @@
                                'badge-placeholder-title': mw.msg(
                                        
'wikibase-badgeselector-badge-placeholder-title'
                                )
-                       }
+                       },
+                       encapsulate: true
                } )
                .on( 'badgeselectorchange', function( event ) {
                        // Adding/removing badges decreases/increases available 
space:
diff --git a/repo/resources/jquery.ui/jquery.ui.EditableTemplatedWidget.js 
b/repo/resources/jquery.ui/jquery.ui.EditableTemplatedWidget.js
index 39cf045..4ba7f00 100644
--- a/repo/resources/jquery.ui/jquery.ui.EditableTemplatedWidget.js
+++ b/repo/resources/jquery.ui/jquery.ui.EditableTemplatedWidget.js
@@ -263,7 +263,9 @@
         */
        notification: function( $content, additionalCssClasses ) {
                if( !this._$notification ) {
-                       this._$notification = $( '<div/>' ).closeable();
+                       this._$notification = $( '<div/>' ).closeable( {
+                               encapsulate: true
+                       } );
                }
                this._$notification.data( 'closeable' ).setContent( $content, 
additionalCssClasses );
                return this._$notification;
diff --git a/repo/resources/jquery.ui/jquery.ui.TemplatedWidget.js 
b/repo/resources/jquery.ui/jquery.ui.TemplatedWidget.js
index 11703aa..0d19c56 100644
--- a/repo/resources/jquery.ui/jquery.ui.TemplatedWidget.js
+++ b/repo/resources/jquery.ui/jquery.ui.TemplatedWidget.js
@@ -35,6 +35,10 @@
         *         of a custom template. The used fields should stick to what 
is defined in the widget's
         *         default options definition.
         *
+        * @option [encapsulate=false] {boolean} Whether non-native 
`jQuery.Widget` events shall be
+        *         triggered on the widget's node only and not bubble up the 
DOM tree (using
+        *         `jQuery.triggerHandler()` instead of `jQuery.trigger()`).
+        *
         * NOTE: the template options have been fields in the prototype before. 
It makes kind of sense
         *       to make them available in the options though. An issue with 
having 'templateShortCuts'
         *       as a field was that inheritance would not be possible with the 
jQuery Widget system
@@ -62,7 +66,8 @@
                         * @descr this.$preview will hold the DOM node (wrapped 
inside a jQuery object) which
                         *        matches above expression.
                         */
-                       templateShortCuts: {}
+                       templateShortCuts: {},
+                       encapsulate: false
                } ),
 
                /**
@@ -158,6 +163,50 @@
                 */
                focus: function() {
                        this.element.focus();
+               },
+
+               /**
+                * Clone of jQuery.Widget._trigger with the difference that 
`$.triggerHandler()` instead of
+                * `$.trigger()` is used to trigger the event on `this.element` 
if `encapsulate` option is
+                * `true`.
+                * @see jQuery.Widget._trigger
+                * @protected
+                *
+                * @param {string} type
+                * @param {jQuery.Event|string} event
+                * @param {*} data
+                * @return {boolean}
+                */
+               _trigger: function( type, event, data ) {
+                       var prop,
+                               orig,
+                               callback = this.options[type];
+
+                       data = data || {};
+                       event = $.Event( event );
+                       event.type = (
+                               type === this.widgetEventPrefix ? type : 
this.widgetEventPrefix + type
+                       ).toLowerCase();
+                       // The original event may come from any element, so we 
need to reset the target on the
+                       // new event:
+                       event.target = this.element[0];
+
+                       // Copy original event properties over to the new event:
+                       orig = event.originalEvent;
+                       if( orig ) {
+                               for( prop in orig ) {
+                                       if( !( prop in event ) ) {
+                                               event[prop] = orig[prop];
+                                       }
+                               }
+                       }
+
+                       this.element[this.options.encapsulate ? 
'triggerHandler' : 'trigger']( event, data );
+                       return !(
+                               $.isFunction( callback )
+                                       && callback.apply( this.element[0], [ 
event ].concat( data ) ) === false
+                               || event.isDefaultPrevented()
+                       );
                }
        } );
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iee90bfa54e8fdb0692d4bbe21ef2fd2d60aaccb8
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

Reply via email to