You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-8Lines changed: 26 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ A javascript-based implementation of Spatial Navigation.
7
7
*[Documentation](#documentation)
8
8
+[API Reference](#api-reference)
9
9
+[Configuration](#configuration)
10
+
+[Custom Attributes](#custom-attributes)
10
11
+[Selector](#selector-1)
11
12
+[Events](#events)
12
13
*[Browser Support](#browser-support)
@@ -81,7 +82,7 @@ Documentation
81
82
82
83
#### `SpatialNavigation.init()`
83
84
84
-
Initializes SpatialNavigation and binds event listeners to the global object. It is a synchronous function so you don't need to await ready state.
85
+
Initializes SpatialNavigation and binds event listeners to the global object. It is a synchronous function, so you don't need to await ready state.
85
86
86
87
**Note:** It should be called before using any other methods of SpatialNavigation!
87
88
@@ -102,7 +103,7 @@ Adds a section to SpatialNavigation with its own configuration. The `config` has
102
103
103
104
A section is a conceptual scope to define a set of elements no matter where they are in DOM structure. You can group elements based on their functions or behaviors (e.g. main, menu, dialog, etc.) into a section.
104
105
105
-
Giving a `sectionId` to a section enables you to refer to it in other methods but is not required. SpatialNavigation allows you to set it by `config.id`, but beware that you cannot change it via [`set()`](#spatialnavigationsetsectionid-config) later.
106
+
Giving a `sectionId` to a section enables you to refer to it in other methods but is not required. SpatialNavigation allows you to set it by `config.id` alternatively, yet it is not allowed in [`set()`](#spatialnavigationsetsectionid-config).
106
107
107
108
#### `SpatialNavigation.remove(sectionId)`
108
109
@@ -137,7 +138,7 @@ Makes SpatialNavigation pause until [`resume()`](#spatialnavigationresume) is ca
137
138
138
139
#### `SpatialNavigation.resume()`
139
140
140
-
Resumes SpatialNavigation so it can react to key events and trigger events which paused because of [`pause()`](#spatialnavigationpause).
141
+
Resumes SpatialNavigation, so it can react to key events and trigger events which paused because of [`pause()`](#spatialnavigationpause).
@@ -259,11 +260,11 @@ If the focus comes from another section, you can define which element in this se
259
260
+ Type: `null` or PlainObject
260
261
+ Default: `null`
261
262
262
-
This property specifies which element should be focused next when a user presses the specified arrow key and intends to leave the current section.
263
+
This property specifies which element should be focused next when a user presses the corresponding arrow key and intends to leave the current section.
263
264
264
-
It should be a PlainObject consists of four properties: `'left'`, `'right'`, `'up'` and `'down'`. Each property should be a [selector](#selector-1). Any of these properties can be omitted and SpatialNavigation will follow the original rule to navigate.
265
+
It should be a PlainObject consists of four properties: `'left'`, `'right'`, `'up'` and `'down'`. Each property should be a [Selector](#selector-1). Any of these properties can be omitted, and SpatialNavigation will follow the original rule to navigate.
265
266
266
-
**Note:**If you assign an empty string to any of these properties, it makes SpatialNavigation go nowhere at that direction.
267
+
**Note:**Assigning an empty string to any of these properties makes SpatialNavigation go nowhere at that direction.
267
268
268
269
#### `restrict`
269
270
@@ -292,6 +293,21 @@ A callback function that accepts a DOM element as the first argument.
292
293
293
294
SpatialNavigation calls this function every time when it tries to traverse every single candidate. You can ignore arbitrary elements by returning `false`.
294
295
296
+
### Custom Attributes
297
+
298
+
SpatialNavigation supports HTML `data-*` attributes as follows:
299
+
300
+
+`data-sn-left`
301
+
+`data-sn-right`
302
+
+`data-sn-up`
303
+
+`data-sn-down`
304
+
305
+
They specifies which element should be focused next when a user presses the corresponding arrow key on an element with these attributes. This setting overrides any other settings in [`enterTo`](#enterto) and [`leaveFor`](#leavefor).
306
+
307
+
The value of each attribute should be a [Selector](#selector-1). However, it only accepts **valid selector string** and **`@` syntax** for now. Any of these attributes can be omitted, and SpatialNavigation will follow the original rule to navigate.
308
+
309
+
**Note:** Assigning an empty string to any of these attributes makes SpatialNavigation go nowhere at that direction.
310
+
295
311
### Selector
296
312
297
313
The type "Selector" can be any of the following types.
@@ -309,7 +325,7 @@ The type "Selector" can be any of the following types.
309
325
310
326
Following custom events are triggered by SpatialNavigation. You can bind them by `addEventListener()`.
311
327
312
-
Focus-related events are wrappers of the native `focus`/`blur` events so they are triggered as well even SpatialNavigation is not involved. In this case, some properties in `event.detail` may be omitted. This kind of properties is marked **"Navigation Only"** below.
328
+
Focus-related events are also wrappers of the native `focus`/`blur` events, so they are triggered as well even SpatialNavigation is not involved. In this case, some properties in `event.detail` may be omitted. This kind of properties is marked **"Navigation Only"** below.
313
329
314
330
**Note:** If you bind events via jQuery's [`.on()`](http://api.jquery.com/on/) API, you must change to `event.originalEvent.detail` to access the `detail` objects.
315
331
@@ -324,12 +340,14 @@ Focus-related events are wrappers of the native `focus`/`blur` events so they ar
324
340
325
341
Fired when SpatialNavigation is about to move the focus.
326
342
327
-
`cause` indicates why this event happens. `'keydown'` means triggered by key events while `'api'` means triggered by calling [`move()`](#spatialnavigationmovedirection-selector)) directly.
343
+
`cause` indicates why this move happens. `'keydown'` means triggered by key events while `'api'` means triggered by calling [`move()`](#spatialnavigationmovedirection-selector)) directly.
328
344
329
345
`sectionId` indicates the currently focused section.
330
346
331
347
`direction` indicates the direction given by arrow keys or [`move()`](#spatialnavigationmovedirection-selector) method.
332
348
349
+
**Note:** Cancelling this event makes the default action be taken normally, i.e. key events will be handled by browser as usual.
0 commit comments