Skip to content

Commit

Permalink
Merge "enterToLastFocused" and "enterToDefaultElement" into "enterTo"
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-chang committed Nov 7, 2015
1 parent a15e44f commit da87ef9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions demo/2.3_enter_to_last_focused.html
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
16 changes: 8 additions & 8 deletions demo/2.4_enter_to_default_element.html
Original file line number Diff line number Diff line change
Expand Up @@ -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(<sectionId>)" 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(<sectionId>)" 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'
});

Expand Down
2 changes: 1 addition & 1 deletion demo/2.5_restrict.html
Original file line number Diff line number Diff line change
Expand Up @@ -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".
//
Expand Down
2 changes: 1 addition & 1 deletion demo/2.6_leave_current_section_for.html
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions demo/3.1_put_all_together.html
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -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".
Expand All @@ -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'
});
Expand Down
12 changes: 6 additions & 6 deletions jquery.SpatialNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
straightOnly: false,
straightOverlapThreshold: 0.5,
rememberSource: false,
enterToLastFocused: false,
enterToDefaultElement: false,
defaultElement: '',
enterTo: '', // '', 'last-focused', 'default-element'
leaveFor: null, // {left: <selector>, right: <selector>,
// up: <selector>, down: <selector>}
restrict: 'self-first', // 'self-first', 'self-only', 'none'
tabIndexIgnoreList:
'a, input, select, textarea, button, iframe, [contentEditable=true]',
leaveFor: null, // {left: <selector>, right: <selector>,
// up: <selector>, down: <selector>}
navigableFilter: null
};

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit da87ef9

Please sign in to comment.