new Address(aRoot)
A helper class for working with browser history and push state. This should be used for deep linking.
Parameters:
Name | Type | Description |
---|---|---|
aRoot |
string | The path to the main script on the server. Defult value is root: '/'. |
- Since:
- 1.0.0
- Source:
Fires:
Extends
Members
events :Object
Object storing all event types.
Each event type is an array of callback functions that get executed when an event of that type of dispatched.
Type:
- Object
- Inherited From:
- Source:
(private, inner) addressRoot :string
Root-relative address to the homepage
This variable holds the path to the root of the application. In case it's in the root of the domain the default value of '/' will be used.
In case the application is, however, in some subdirectory you'll need to overwrite this by passing an aRoot
argument to the class constructor.
Type:
- string
- Default Value:
- /
- Source:
- See:
(private, inner) hash :string
Copy of deep-linked address
The property is not to be mistaken with the window.location.hash
object (although it can contain it).
This will not always appear with "#" but can also be set as any path.
If you use setHath('#hash')
this will essentially match the window.location.hash
yet you can ommit the "#" symbol
when calling the method.
It gets updated through the updateHash()
private method each time a setHash()
call occurs.
There is a getHash()
getter and a setHath()
setter to allow you to control the property.
Type:
- string
- Source:
- See:
(private, inner, readonly) state :string
Holder of a state property for HTML5 history.pushState()
This will be updated when the setHash()
method is used.
You cannot directly set the value of state
without calling setHash()
but you can retrieve it with the getState()
getter.
Type:
- string
- Source:
- See:
Methods
addEventListener(eventType, callback) → {void}
Attaches an event handler to a specific event type
Parameters:
Name | Type | Description |
---|---|---|
eventType |
string | The type of the event you'd like to listen for |
callback |
function | The function to be executed when the event occurs |
- Inherited From:
- Source:
Returns:
- Type
- void
dispatchEvent(eventType, eventObj) → {void}
Fires an event on behalf of the object
Parameters:
Name | Type | Description |
---|---|---|
eventType |
string | The type of the event you'd like to fire |
eventObj |
Event | The actual event object that will be passed to listener functions. This can be used to store additional information for the situation. |
- Inherited From:
- Source:
Returns:
- Type
- void
getHash() → {string}
Getter for hash
- Source:
- See:
Returns:
The URL hash
- Type
- string
getState() → {object}
Getter for state
- Source:
- See:
-
- Address#state~state
- setHash
Returns:
The state object
- Type
- object
removeEventListener(eventType, callback) → {void}
Removes a previously attached event to a specific event type.
Parameters:
Name | Type | Description |
---|---|---|
eventType |
string | The type of the event you'd like to unbind a handler for |
callback |
function | This must be a reference to the same Function object that has been set as a listener. Otherwise the removal will not take place. |
- Inherited From:
- Source:
Returns:
- Type
- void
setHash(hash, title, state)
Sets the URL hash, the title and allows for a custom state to be saved.
This is an alias for history.pushState
that also performs some internal class handling and event triggering.
Parameters:
Name | Type | Description |
---|---|---|
hash |
string | The new value that would be set for the hash |
title |
string | The title argument to be passed to the history.pushstate function. As of February 8th, 2016 this is still simply ignored by all browsers. |
state |
object | An object storing additional information for the state itself |
- Source:
- See:
(private, inner) popStateHandler(e) → {void}
Auto handler of the window.popstate
event
Parameters:
Name | Type | Description |
---|---|---|
e |
Event | The |
- Source:
Returns:
- Type
- void
(private, inner) updateHash() → {void}
Stores the current hash as a property each time setHash()
is called.
- Source:
- See:
Returns:
- Type
- void
Events
change
Event dispatched when the URL of the page changes.
This is accompanied by a native window.popstate event.
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
previousHash |
string | The previous page hash |
previousState |
Object | The previous page state |
- Source: