registerDistanceCalculationStrategy

jQuery.caph.focus.nearestFocusableFinderProvider. registerDistanceCalculationStrategy

Registers a custom distance calculation strategy.

(static) registerDistanceCalculationStrategy(name, strategy, overrideopt) → {jQuery.caph.focus.nearestFocusableFinderProvider}

Parameters:
Name Type Attributes Description
name string

The strategy name.

strategy function

A function which calculates distance between elements. This function takes three arguments. The first and second parameters are an object which contains element's coordinates (left, top) and dimensions (width, height); the former is a comparison target, and the latter is one of the nearest candidates. The last parameter is a direction of the distance calculation.
This function should return a calculated distance between first and second parameter.

override boolean <optional>

A boolean determines whether override the existing strategy or not.

Returns:
Type
jQuery.caph.focus.nearestFocusableFinderProvider
Example
$document.ready(function() {
 	$.caph.focus.init(function(nearestFocusableFinderProvider) {
 		nearestFocusableFinderProvider.registerDistanceCalculationStrategy('sample', function(from, to, direction) {
 			return Math.sqrt(Math.pow(from.left - to.left, 2) + Math.pow(from.top - to.top, 2));
 		});
 	});
 });