class Playhead
smx. Playhead
The Playhead class is a Document
navigation controller.
Provides a plain interface to navigate along a Document tree, keeps a navigation registry and emits useful events for listening to any movement.
Constructor
new Playhead(document)
Parameters
-
document
{smx.Document}
:The document to navigate through
Members
_document:smx.Document
- private
The document to navigate through
_selection:Array.<smx.Node>
- private
Contains all currently selected nodes ordered from outter to inner.
selection:Array.<smx.Node>
- readonly
Gets all currently selected nodes ordered from outter to inner.
head:smx.Node
- readonly
Gets the head node, which is the last node in selection.
root:smx.Node
- readonly
Gets the root node, which is the first node selection.
Methods
play([ref])
Performs play action
Parameters
-
[ref]
{String|smx.Node}
:target reference
enter()
Navigates to an inner node, moves the head to current head's first child.
exit()
Navigates to an outter node, moves the head to current head's parent.
previous()
Navigates to current head's previous sibling node.
forward()
Navigates to current head's next node in flat tree mode.
backward()
Navigates to current head's previous node in flat tree mode.
exec(keyword)
Executes a playhead command based on the given action keyword. keywords are basically some playhead's method names.
List of valid commands:
reset
, play
, next
, previous
,
enter
, exit
, forward
, backward
.
Parameters
-
keyword
{String}
navigate(target)
Navigates to a given target node or executes a playhead command.
If target
is a node will navigate to it, if target
is a string will
try to find a node identified as target
and will navigate to it. If
target
is a !
preffixed string will execute it as a playhead command.
See .exec()
for a list of valid commands.
Parameters
-
target
{String|smx.Node}
Example
//instance a new Playhead
var playhead = new smx.Playhead(doc);
//navigate by node identifier
playhead.navigate('a42');
//to to given node
playhead.navigate(node);
//using commands
playhead.navigate('!next')
//same as
playhead.exec('next')
// or
playhead.next();
on(name, callback, context)
Binds an event to a callback
function. Passing "all"
will bind
the callback to all events fired.
Parameters
-
name
{String}
-
callback
{function}
-
context
{Object}
once(name, callback, context)
Binds an event to only be triggered a single time. After the first time the callback is invoked, it will be removed.
Parameters
-
name
{String}
-
callback
{function}
-
context
{Object}
off(name, callback, context)
Remove one or many callbacks. If context
is null, removes all
callbacks with that function. If callback
is null, removes all
callbacks for the event. If name
is null, removes all bound
callbacks for all events.
Parameters
-
name
{String}
-
callback
{function}
-
context
{Object}