HistoryHTML5 Class
yui3/src/history/js/history-html5.js:9
Parent Module: history
<p> Provides browser history management using the HTML5 history API. </p>
<p> When calling the <code>add()</code>, <code>addValue()</code>, <code>replace()</code>, or <code>replaceValue()</code> methods on <code>HistoryHTML5</code>, the following additional options are supported: </p>
<dl> <dt><strong>title (String)</strong></dt> <dd> Title to use for the new history entry. Browsers will typically display this title to the user in the detailed history window or in a dropdown menu attached to the back/forward buttons. If not specified, the title of the current document will be used. </dd>
<dt><strong>url (String)</strong></dt> <dd> URL to display to the user for the new history entry. This URL will be visible in the browser's address bar and will be the bookmarked URL if the user bookmarks the page. It may be a relative path ("foo/bar"), an absolute path ("/foo/bar"), or a full URL ("http://example.com/foo/bar"). If you specify a full URL, the origin <i>must</i> be the same as the origin of the current page, or an error will occur. If no URL is specified, the current URL will not be changed. </dd> </dl>
Constructor
HistoryHTML5
-
config
Parameters:
-
config
Object(optional) Configuration object.
Methods
_change
-
src
-
state
-
options
<p>Changes the state. This method provides a common implementation shared by the public methods for changing state.</p>
Parameters:
-
src
String<p>Source of the change, for inclusion in event facades to facilitate filtering.</p>
-
state
Object<p>Object hash of key/value pairs.</p>
-
options
Object<p>(optional) Zero or more options. See <code>add()</code> for a list of supported options.</p>
_defChangeFn
-
e
<p>Default <code>history:change</code> event handler.</p>
Parameters:
-
e
EventFacade<p>state change event facade</p>
_fireChangeEvent
-
src
-
key
-
value
<p>Fires a dynamic "[key]Change" event.</p>
Parameters:
-
src
String<p>source of the change, for inclusion in event facades to facilitate filtering</p>
-
key
String<p>key of the item that was changed</p>
-
value
Object<p>object hash containing <i>newVal</i> and <i>prevVal</i> properties for the changed item</p>
_fireEvents
-
src
-
changes
-
options
<p>Called by _resolveChanges() when the state has changed. This method takes care of actually firing the necessary events.</p>
Parameters:
-
src
String<p>Source of the changes, for inclusion in event facades to facilitate filtering.</p>
-
changes
Object<p>Resolved changes.</p>
-
options
Object<p>Zero or more options. See <code>add()</code> for a list of supported options.</p>
_fireRemoveEvent
-
src
-
key
-
value
<p>Fires a dynamic "[key]Remove" event.</p>
Parameters:
-
src
String<p>source of the change, for inclusion in event facades to facilitate filtering</p>
-
key
String<p>key of the item that was removed</p>
-
value
Mixed<p>value of the item prior to its removal</p>
_init
-
config
<p>Initializes this HistoryBase instance. This method is called by the constructor.</p>
Parameters:
-
config
Object<p>configuration object</p>
_isSimpleObject
-
value
<p>Returns <code>true</code> if <i>value</i> is a simple object and not a function or an array.</p>
Parameters:
-
value
Mixed
Returns:
_resolveChanges
-
src
-
newState
-
options
<p>Resolves the changes (if any) between <i>newState</i> and the current state and fires appropriate events if things have changed.</p>
Parameters:
-
src
String<p>source of the changes, for inclusion in event facades to facilitate filtering</p>
-
newState
Object<p>object hash of key/value pairs representing the new state</p>
-
options
Object<p>Zero or more options. See <code>add()</code> for a list of supported options.</p>
_storeState
-
src
-
newState
-
options
Overrides HistoryBase's <code>_storeState()</code> and pushes or replaces a history entry using the HTML5 history API when necessary.
Parameters:
-
src
StringSource of the changes.
-
newState
ObjectNew state to store.
-
options
ObjectZero or more options.
add
-
state
-
options
<p>Adds a state entry with new values for the specified keys. By default, the new state will be merged into the existing state, and new values will override existing values. Specifying a <code>null</code> or <code>undefined</code> value will cause that key to be removed from the new state entry.</p>
Parameters:
-
state
Object<p>Object hash of key/value pairs.</p>
-
options
Object<p>(optional) Zero or more of the following options: <dl> <dt>merge (Boolean)</dt> <dd> <p> If <code>true</code> (the default), the new state will be merged into the existing state. New values will override existing values, and <code>null</code> or <code>undefined</code> values will be removed from the state. </p> <p> If <code>false</code>, the existing state will be discarded as a whole and the new state will take its place. </p> </dd> </dl></p>
addValue
-
key
-
value
-
options
<p>Adds a state entry with a new value for a single key. By default, the new value will be merged into the existing state values, and will override an existing value with the same key if there is one. Specifying a <code>null</code> or <code>undefined</code> value will cause the key to be removed from the new state entry.</p>
Parameters:
-
key
String<p>State parameter key.</p>
-
value
String<p>New value.</p>
-
options
Object<p>(optional) Zero or more options. See <code>add()</code> for a list of supported options.</p>
get
-
key
<p>Returns the current value of the state parameter specified by <i>key</i>, or an object hash of key/value pairs for all current state parameters if no key is specified.</p>
Parameters:
-
key
String<p>(optional) State parameter key.</p>
Returns:
<p>Value of the specified state parameter, or an object hash of key/value pairs for all current state parameters.</p>
replace
-
state
-
options
<p>Same as <code>add()</code> except that a new browser history entry will not be created. Instead, the current history entry will be replaced with the new state.</p>
Parameters:
-
state
Object<p>Object hash of key/value pairs.</p>
-
options
Object<p>(optional) Zero or more options. See <code>add()</code> for a list of supported options.</p>
replaceValue
-
key
-
value
-
options
<p>Same as <code>addValue()</code> except that a new browser history entry will not be created. Instead, the current history entry will be replaced with the new state.</p>
Parameters:
-
key
String<p>State parameter key.</p>
-
value
String<p>New value.</p>
-
options
Object<p>(optional) Zero or more options. See <code>add()</code> for a list of supported options.</p>
Properties
_config
Object
protected
<p>Configuration object provided by the user on instantiation, or an empty object if one wasn't provided.</p>
Default: {}
_initialState
Object | Null
protected
<p>Resolved initial state: a merge of the user-supplied initial state (if any) and any initial state provided by a subclass. This may differ from <code>_config.initialState</code>. If neither the config nor a subclass supplies an initial state, this property will be <code>null</code>.</p>
Default: {}
force
Boolean
<p>If <code>true</code>, a <code>history:change</code> event will be fired whenever the URL changes, even if there is no associated state change.</p>
Default: false
SRC_POPSTATE
String
final
static
Constant used to identify state changes originating from <code>popstate</code> events.
Events
[key]Change
<p><p> Dynamic event fired when an individual history item is added or changed. The name of this event depends on the name of the key that changed. To listen to change events for a key named "foo", subscribe to the <code>fooChange</code> event; for a key named "bar", subscribe to <code>barChange</code>, etc. </p></p> <p><p> Key-specific events are only fired for instance-level changes; that is, changes that were made via the same History instance on which the event is subscribed. To be notified of changes made by other History instances, subscribe to the global <code>history:change</code> event. </p></p>
Event Payload:
-
e
EventFacade<p>Event facade with the following additional properties:</p> <p><dl> <dt>newVal (mixed)</dt> <dd> The new value of the item after the change. </dd></p> <p><dt>prevVal (mixed)</dt> <dd> The previous value of the item before the change, or <code>undefined</code> if the item was just added and has no previous value. </dd></p> <p><dt>src (String)</dt> <dd> The source of the event. This can be used to selectively ignore events generated by certain sources. </dd> </dl></p>
[key]Remove
<p><p> Dynamic event fired when an individual history item is removed. The name of this event depends on the name of the key that was removed. To listen to remove events for a key named "foo", subscribe to the <code>fooRemove</code> event; for a key named "bar", subscribe to <code>barRemove</code>, etc. </p></p> <p><p> Key-specific events are only fired for instance-level changes; that is, changes that were made via the same History instance on which the event is subscribed. To be notified of changes made by other History instances, subscribe to the global <code>history:change</code> event. </p></p>
Event Payload:
-
e
EventFacade<p>Event facade with the following additional properties:</p> <p><dl> <dt>prevVal (mixed)</dt> <dd> The value of the item before it was removed. </dd></p> <p><dt>src (String)</dt> <dd> The source of the event. This can be used to selectively ignore events generated by certain sources. </dd> </dl></p>
history:change
<p>Fired when the state changes. To be notified of all state changes regardless of the History or YUI instance that generated them, subscribe to this event on <code>Y.Global</code>. If you would rather be notified only about changes generated by this specific History instance, subscribe to this event on the instance.</p>
Event Payload:
-
e
EventFacade<p>Event facade with the following additional properties:</p> <p><dl> <dt>changed (Object)</dt> <dd> Object hash of state items that have been added or changed. The key is the item key, and the value is an object containing <code>newVal</code> and <code>prevVal</code> properties representing the values of the item both before and after the change. If the item was newly added, <code>prevVal</code> will be <code>undefined</code>. </dd></p> <p><dt>newVal (Object)</dt> <dd> Object hash of key/value pairs of all state items after the change. </dd></p> <p><dt>prevVal (Object)</dt> <dd> Object hash of key/value pairs of all state items before the change. </dd></p> <p><dt>removed (Object)</dt> <dd> Object hash of key/value pairs of state items that have been removed. Values are the old values prior to removal. </dd></p> <p><dt>src (String)</dt> <dd> The source of the event. This can be used to selectively ignore events generated by certain sources. </dd> </dl></p>