diff --git a/demo/2.3_enter_to_last_focused.html b/demo/2.3_enter_to_last_focused.html index b712b71..f8bec9a 100644 --- a/demo/2.3_enter_to_last_focused.html +++ b/demo/2.3_enter_to_last_focused.html @@ -18,10 +18,10 @@ id: 'menu', selector: '.leftbox .focusable', - // Setting this to true means the last focused element in this section - // will be focused first whenever the focus jumps into this section - // from another section. - enterToLastFocused: true + // Setting this to "last-focused" means the last focused element in + // this section will be focused first whenever the focus jumps into + // this section from another section. + enterTo: 'last-focused' }); SN.add({ diff --git a/demo/2.4_enter_to_default_element.html b/demo/2.4_enter_to_default_element.html index 727f1ea..771614e 100644 --- a/demo/2.4_enter_to_default_element.html +++ b/demo/2.4_enter_to_default_element.html @@ -18,16 +18,16 @@ id: 'menu', selector: '.leftbox .focusable', - // Setting this to true means the default element will be focused - // first whenever the focus jumps into this section from another - // section. - enterToDefaultElement: true, + // Setting this to "default-element" means the default element will be + // focused first whenever the focus jumps into this section from + // another section. + enterTo: 'default-element', // Specify the default element. - // It will be focused first when calling "focus()" method - // as well no matter what value "enterToDefaultElement" is set. - // The valid value can be a jQuery selector string, jQuery object or - // standard DOM element. + // It will be focused as well when calling "focus()" method + // even if "enterTo" is not set to "default-element". The valid value + // can be a jQuery selector string, jQuery object or standard DOM + // element. defaultElement: '.leftbox .focusable:first' }); diff --git a/demo/2.5_restrict.html b/demo/2.5_restrict.html index 1fc1982..8bab27a 100644 --- a/demo/2.5_restrict.html +++ b/demo/2.5_restrict.html @@ -17,7 +17,7 @@ SN.add({ id: 'menu', selector: '.leftbox .focusable', - enterToLastFocused: true, + enterTo: 'last-focused', // The valid values are "none", "self-first" and "self-only". // diff --git a/demo/2.6_leave_current_section_for.html b/demo/2.6_leave_current_section_for.html index 8e11086..bccfa0b 100644 --- a/demo/2.6_leave_current_section_for.html +++ b/demo/2.6_leave_current_section_for.html @@ -17,7 +17,7 @@ SN.add({ id: 'menu', selector: '.leftbox .focusable', - enterToLastFocused: true, + enterTo: 'last-focused', // This config specifies which element will be focused next when user // press the specified key and intends to leave the current section. diff --git a/demo/3.1_put_all_together.html b/demo/3.1_put_all_together.html index 9c0f026..f3f3847 100644 --- a/demo/3.1_put_all_together.html +++ b/demo/3.1_put_all_together.html @@ -23,7 +23,7 @@ // Force to focus the "#button-settings" when entering this section. defaultElement: '#button-settings', - enterToDefaultElement: true + enterTo: 'default-element' }); // Add the second section "middlebox". @@ -32,7 +32,7 @@ selector: '#middlebox .focusable', // Focus the last focused element first then entering this section. - enterToLastFocused: true + enterTo: 'last-focused' }); // Add the third section "settings-dialog". @@ -47,9 +47,9 @@ // itself so the focus won't be moved to another section. restrict: 'self-only', - // Note that we don't set "enterToDefaultElement" in this section. - // That's because it's impossible to enter this section from another - // one by arrow keys. This default element will only affect the + // Note that we don't set "enterTo" to "default-element" in this + // section because it's impossible to enter this section from the + // others by arrow keys. This default element will only affect the // "focus('settings-dialog')" API call. defaultElement: '#button-cancel' }); diff --git a/jquery.SpatialNavigation.js b/jquery.SpatialNavigation.js index 107020c..cd9bffd 100644 --- a/jquery.SpatialNavigation.js +++ b/jquery.SpatialNavigation.js @@ -17,14 +17,13 @@ straightOnly: false, straightOverlapThreshold: 0.5, rememberSource: false, - enterToLastFocused: false, - enterToDefaultElement: false, defaultElement: '', + enterTo: '', // '', 'last-focused', 'default-element' + leaveFor: null, // {left: , right: , + // up: , down: } restrict: 'self-first', // 'self-first', 'self-only', 'none' tabIndexIgnoreList: 'a, input, select, textarea, button, iframe, [contentEditable=true]', - leaveFor: null, // {left: , right: , - // up: , down: } navigableFilter: null }; @@ -709,10 +708,11 @@ } var nextSection = _sections[nextSectionId]; - if (nextSection.enterToLastFocused && nextSection.lastFocusedElement && + if (nextSection.enterTo == 'last-focused' && + nextSection.lastFocusedElement && isNavigable(nextSection.lastFocusedElement, nextSectionId)) { next = nextSection.lastFocusedElement; - } else if (nextSection.enterToDefaultElement && + } else if (nextSection.enterTo == 'default-element' && nextSection.defaultElement && isNavigable(nextSection.defaultElement, nextSectionId)) { next = $(nextSection.defaultElement).get(0);