addBeforeKeydownHandler

caph.focus.focusController. addBeforeKeydownHandler

Adds a function to be called before key input processing. If one of them returns false, key input processing is stopped.

(static) addBeforeKeydownHandler(handler, orderopt) → {boolean}

Parameters:
Name Type Attributes Description
handler function

A function to be called before key input processing. This function can receive two parameters. The first parameter is an object which contains current focus controller's state including event object.

  • event: The current event object.
  • previousFocusedItem: The previous focused item.
  • currentFocusItem: The current focus item. The second parameter is focus controller itself.
order number <optional>

The order is used to sort the handlers before they are called. Order is defined as a number. Handlers with less numerical order are called first. The default order is 0.

Returns:

A boolean indicates whether success or not.

Type
boolean
Example
angular.module('myApp', ['caph.focus']).controller('myController', ['$scope', 'FocusConstant', 'focusController', function($scope, FocusConstant, focusController) {
 	focusController.addBeforeKeydownHandler(function(context) {
 		if (context.event.keyCode === FocusConstant.DEFAULT.KEY_MAP.RIGHT) {
 			focusController.setGroup('test');
 			return false;
 		}
 	});
 }]);