Matthias Mullie has uploaded a new change for review.

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

Change subject: Make it possible to add interactiveHandlers to elements on focus
......................................................................

Make it possible to add interactiveHandlers to elements on focus

We have things automatically happening on focus already (topic reply form
expanding, for example), but no way to hook into that with interactiveHandler

Change-Id: I319afee108891e9589ff4893f104c1126879c9db
---
M modules/engine/components/common/flow-component-events.js
1 file changed, 42 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/25/173325/1

diff --git a/modules/engine/components/common/flow-component-events.js 
b/modules/engine/components/common/flow-component-events.js
index 1de9eee..a9f3daf 100644
--- a/modules/engine/components/common/flow-component-events.js
+++ b/modules/engine/components/common/flow-component-events.js
@@ -46,6 +46,11 @@
                                _getDispatchCallback( this, 
'interactiveHandler' )
                        )
                        .on(
+                               'focus.FlowBoardComponent',
+                               'a, input, button, .flow-click-interactive',
+                               _getDispatchCallback( this, 
'interactiveHandlerFocus' )
+                       )
+                       .on(
                                'click.FlowBoardComponent 
focusin.FlowBoardComponent focusout.FlowBoardComponent',
                                '.flow-menu',
                                _getDispatchCallback( this, 'toggleHoverMenu' )
@@ -418,19 +423,14 @@
        FlowComponentEventsMixin.eventHandlers.loadHandler = 
flowLoadHandlerCallback;
 
        /**
-        * Triggers both API and interactive handlers.
+        * Executes interactive handlers.
+        *
+        * @param {array} args
+        * @param {jQuery} $context
+        * @param {string} interactiveHandlerName
+        * @param {string} apiHandlerName
         */
-       function flowInteractiveHandlerCallback( event ) {
-               // Only trigger with enter key, if keypress
-               if ( event.type === 'keypress' && ( event.charCode !== 13 || 
event.metaKey || event.shiftKey || event.ctrlKey || event.altKey )) {
-                       return;
-               }
-
-               var args = Array.prototype.slice.call( arguments, 0 ),
-                       $context = $( event.currentTarget || 
event.delegateTarget || event.target ),
-                       interactiveHandlerName = $context.data( 
'flow-interactive-handler' ),
-                       apiHandlerName = $context.data( 'flow-api-handler' );
-
+       function flowExecuteInteractiveHandler( args, $context, 
interactiveHandlerName, apiHandlerName ) {
                // Call any matching interactive handlers
                if ( this.UI.events.interactiveHandlers[interactiveHandlerName] 
) {
                        $.each( 
this.UI.events.interactiveHandlers[interactiveHandlerName], function ( i, fn ) {
@@ -447,10 +447,40 @@
                        this.debug( 'Failed to find apiHandler', 
apiHandlerName, arguments );
                }
        }
+
+       /**
+        * Triggers both API and interactive handlers, on click/enter.
+        */
+       function flowInteractiveHandlerCallback( event ) {
+               // Only trigger with enter key, if keypress
+               if ( event.type === 'keypress' && ( event.charCode !== 13 || 
event.metaKey || event.shiftKey || event.ctrlKey || event.altKey )) {
+                       return;
+               }
+
+               var args = Array.prototype.slice.call( arguments, 0 ),
+                       $context = $( event.currentTarget || 
event.delegateTarget || event.target ),
+                       interactiveHandlerName = $context.data( 
'flow-interactive-handler' ),
+                       apiHandlerName = $context.data( 'flow-api-handler' );
+
+               return flowExecuteInteractiveHandler.call( this, args, 
$context, interactiveHandlerName, apiHandlerName );
+       }
        FlowComponentEventsMixin.eventHandlers.interactiveHandler = 
flowInteractiveHandlerCallback;
        FlowComponentEventsMixin.eventHandlers.apiRequest = 
flowInteractiveHandlerCallback;
 
        /**
+        * Triggers both API and interactive handlers, on focus.
+        */
+       function flowInteractiveHandlerFocusCallback( event ) {
+               var args = Array.prototype.slice.call( arguments, 0 ),
+                       $context = $( event.currentTarget || 
event.delegateTarget || event.target ),
+                       interactiveHandlerName = $context.data( 
'flow-interactive-handler-focus' ),
+                       apiHandlerName = $context.data( 
'flow-api-handler-focus' );
+
+               return flowExecuteInteractiveHandler.call( this, args, 
$context, interactiveHandlerName, apiHandlerName );
+       }
+       FlowComponentEventsMixin.eventHandlers.interactiveHandlerFocus = 
flowInteractiveHandlerFocusCallback;
+
+       /**
         * When the whole class has been instantiated fully (after every 
constructor has been called).
         * @param {FlowComponent} component
         */

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I319afee108891e9589ff4893f104c1126879c9db
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>

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

Reply via email to