Skip to content

Commit 59269fd

Browse files
committed
Add "Custom Attributes" section to README.md
1 parent 9285e0a commit 59269fd

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ A javascript-based implementation of Spatial Navigation.
77
* [Documentation](#documentation)
88
+ [API Reference](#api-reference)
99
+ [Configuration](#configuration)
10+
+ [Custom Attributes](#custom-attributes)
1011
+ [Selector](#selector-1)
1112
+ [Events](#events)
1213
* [Browser Support](#browser-support)
@@ -81,7 +82,7 @@ Documentation
8182

8283
#### `SpatialNavigation.init()`
8384

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.
8586

8687
**Note:** It should be called before using any other methods of SpatialNavigation!
8788

@@ -102,7 +103,7 @@ Adds a section to SpatialNavigation with its own configuration. The `config` has
102103

103104
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.
104105

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).
106107

107108
#### `SpatialNavigation.remove(sectionId)`
108109

@@ -137,7 +138,7 @@ Makes SpatialNavigation pause until [`resume()`](#spatialnavigationresume) is ca
137138

138139
#### `SpatialNavigation.resume()`
139140

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).
141142

142143
#### `SpatialNavigation.focus([sectionId/selector], [silent])`
143144

@@ -259,11 +260,11 @@ If the focus comes from another section, you can define which element in this se
259260
+ Type: `null` or PlainObject
260261
+ Default: `null`
261262

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.
263264

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.
265266

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.
267268

268269
#### `restrict`
269270

@@ -292,6 +293,21 @@ A callback function that accepts a DOM element as the first argument.
292293

293294
SpatialNavigation calls this function every time when it tries to traverse every single candidate. You can ignore arbitrary elements by returning `false`.
294295

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+
295311
### Selector
296312

297313
The type "Selector" can be any of the following types.
@@ -309,7 +325,7 @@ The type "Selector" can be any of the following types.
309325

310326
Following custom events are triggered by SpatialNavigation. You can bind them by `addEventListener()`.
311327

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.
313329

314330
**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.
315331

@@ -324,12 +340,14 @@ Focus-related events are wrappers of the native `focus`/`blur` events so they ar
324340

325341
Fired when SpatialNavigation is about to move the focus.
326342

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.
328344

329345
`sectionId` indicates the currently focused section.
330346

331347
`direction` indicates the direction given by arrow keys or [`move()`](#spatialnavigationmovedirection-selector) method.
332348

349+
**Note:** Cancelling this event makes the default action be taken normally, i.e. key events will be handled by browser as usual.
350+
333351
#### `sn:willunfocus`
334352

335353
+ bubbles: `true`

0 commit comments

Comments
 (0)