addBeforeKeydownHandler

jQuery.caph.focus.controllerProvider. 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 take two parameters. The first parameter is an object which contains current 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 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
$(document).ready(function() {
 	$.caph.focus.init(function(nearestFocusableFinderProvider, controllerProvider) {
 		controllerProvider.addBeforeKeydownHandler(function(context, controller) {
 			if (context.code === $.caph.focus.Constant.DEFAULT.KEY_MAP.RIGHT) {
 				controller.setGroup('test');
 				return false;
				}
			});
 	});
 });