"Visual", no-hassle navigation in HTML using IR remote / arrow keys
“Visual”, no-hassle navigation in HTML using IR remote / arrow keys.
Intended for HTML5 applications where arrow keys or IR remote control is essential:
SmartTV applications, set-top box UI, etc.
Many current devices are able to use mouse pointer: LG Magic Remote, Samsung Smart Touch Remote,
USB Wireless mouse, etc. Implementing two different navigation schemes is hard.
FreeFocus lets you stick with the easy one (pointer device, we used to it in Web UI)
and handles the hard one (direction keys) in the most unobtrusive way.
No need to operate separate logical navigation structures (lists, grids, etc).
Just use HTML for UI and let FreeFocus navigate it “visually” — using positions of
focusable elements on page. If user pressed “right”, just move focus to focusable
element placed to the right of the current focused one. It’s that easy.
It can be used as a polyfill for CSS3 UI nav-*
directional focus navigation.
Uses W3C WICD Current Focus Point Algorithm for focus traversal.
VanillaJS core:
jQuery plugin:
<script src="jquery.js"></script>
<script src="jquery.freefocus.min.js"></script>
<script>
$(function() {
$.freefocus({hoverFocus: true});
});
</script>
That’s it, now you have it all set up.
TBD, sorry. See Source for now.
$.freefocus({options...}, {moveOptions...})
Set up keyboard navigation.
Options:
focusedSelector
- selector for currently focused (or active) element. default: ':focus'
hoverFocus
- focus target elements on mouse enter. default: false
throttle
- throttle key input for specified time (in milliseconds).false
Move options are passed to $.fn.freefocus
$.freefocus('remove')
Remove previously set keyboard navigation.
$.freefocus('cache', options)
Compute and cache dimension information for focusable elements. Options: focusablesSelector
, focusablesFilter
, focusablesContext
$.fn.freefocus({options...})
Move “focus” from active element to one of the targets by triggering specified event.
Options:
move
- move direction: left
| right
| up
| down
. no defaultfocusablesSelector
- selector for navigation targets. default: a long selector describing all focusable options in web browsers.:focusable
from jQuery UI.focusablesFilter
— selector that filters targets after they were selected using focusablesSelector
.':visible'
focusablesContext
— element or selector, conext for navigation targets search. default: undefined
targets
- jQuery object containing “focusable” elements. no defaultdebug
- print weighting information over targets. default: false
trigger
- event to trigger on selected target. default: 'focus'
preTrigger
- event to trigger on selected target before the trigger
one. default: false
(don’t trigger)trigger
is focus
to move the next focused element into view to avoid native behavior.maxDistance
- maximum distance to element to still consider moving to it. default: Infinity
cache
- cache dimension information for element. default: false
$(element).freefocus('moved')
$.fn.freefocus('dimensions')
Get element dimensions {top, left, width, height}
. Uses cache, if it’s enabled.
$.fn.freefocus('moved')
Clear cached dimension info for element. Should be triggered for every element that is moved, if using cache
.
$.fn.freefocus('nav', hints)
Set hints (see next chapter for details).
Hints argument is either:
{ left: 'none', right: '#someId' }
. no defaultclear
- special string value, clear all nav hints from the elementAllows for fine-grained control over focus movements.
FreeFocus implements CSS3 UI nav-*
directional focus navigation specification with few differences:
none
, which disables focus movement in the specified direction. e.g. nav-left: none;
means that pressing left arrow does nothingnavLeft
, navRight
, navUp
, navDown
. e.g. domNode.navLeft = '#someId';
focusablesSelector
and focusablesFilter
);
allows to set priorities: they will be matched in a listed order one by one. first that matches any vaild tagret would be takenHints could be specified using
style
attribute: nav-left
, nav-right
, nav-up
, nav-down
navLeft
, navRight
, navUp
, navDown
<button data-nav-left="selector">
$.fn.freefocus('nav')
setHint
(true
by default) freefocus.js
freefocus('cache')
targets
option to be a function that returns focusable elements instead of using focusablesSelector
and focusablesFilter
focusablesContext
;
data-nav-*
attributes support$.fn.freefocus('nav')
methodfocusablesContext
option. Moved focusables*
options from setupOptions
to moveOptions
.focusablesFilter
setup option. Added optional focusablesSelector
and focusablesFilter
move options which has better performance over targets
when used with nav-*
props.none
value for nav-* properties.preTrigger
event.nav-*
directional focus navigation properties. Changed naming style from under_scores to camelCase.