hashstate
Location hash manager for the web inspired by YUI3.
Installation
cortex install hashstate --save
Usage
var hashState = options;
- options
Object=
- prefix
String='!'
Prefix to prepend when setting the hash fragment. Default to'!'
- split
String=','
String to split the key-value pairs. - assign
String='='
String to join key and value of a key-value pair. - window
Window=
- prefix
The instance of hashState
is an EventEmitter.
.stringify(object)
Returns String
, excluding options.prefix
.
hashState; // 'a=1,b=c'
.parse(string)
Parses the given string
and returns Object
the parsed object according to options.split
and options.assign
.
// Will deal with the leading '#!'hashState; // {a: '1', b: 'c'}hashState; // {a: '1', b: 'c'}hashState; // {a: '1', b: 'c'} hashState; // {a: '1', b: 'c'}
.setHash(hash, options)
- hash
String
hash string. - options
Object
- mute
Boolean
iftrue
, calling this method will not emit a'hashchange'
event.
- mute
Changes the current location hash, which will add a new history entry.
.replaceHash(hash, options)
- hash
String
hash string. - options
Object
- mute
Boolean
iftrue
, calling this method will not emit a'hashchange'
event.
- mute
Changes location hash and replaces the current history entry instead of adding a new entry.
.getHash()
Returns the current hash string, excluding the leading '#'
and options.prefix
.
Event: hashchange
- e
Object
- newHash
String
the new(current) hash string. - oldHash
String
the old hash string.
- newHash
Emitted when hash changes.
hashState;