History

Singleton class for managing browser history/state changes.

Summary
Singleton class for managing browser history/state changes.
This event fires when the history changes state.
Retrieves the hash of the current page url.
Sets the hash of the current page url.
Sets the default application state of the History object.
Retrieves an object representation of the current state of the History object, containing any hash name/value pairs as properties of the object.
Retrieves the current topic of the History object.
Static function--Retrieves a Mojo History instance.

Events

onChange

This event fires when the history changes state.

Functions

getHash

getHash: function()

Retrieves the hash of the current page url.

Returns

{string} Hash

Example

// if current location is: http://localhost/main#topic=news
var currentHash = mojo.History.getInstance().getHash(); //returns "topic=news"

setHash

setHash: function(newHash)

Sets the hash of the current page url.

Parameters

newHash{string} Hash.

Example

// if current location is: http://localhost/main
mojo.History.getInstance().setHash("topic=news"); //sets location to: http://localhost/main#topic=news

setDefault

setDefault: function(defaultHashObj)

Sets the default application state of the History object.

Parameters

defaultHashObj{string|object}

Example

// set default state as a string
mojo.History.getInstance().setDefault("topic=news&id=1234");

// OR set default state as a JS object
mojo.History.getInstance().setDefault({topic: "news", id: 1234});

getParams

getParams: function()

Retrieves an object representation of the current state of the History object, containing any hash name/value pairs as properties of the object.

Returns

{object} Parameter Object

Example

// if current location is: http://localhost/main#topic=news&id=1234
var params = mojo.History.getInstance().getParams(); // returns {topic: "news", id:1234}
var topic = mojo.History.getInstance().getParams().topic; // returns "news"
var id = mojo.History.getInstance().getParams().id; // returns 1234

getTopic

getTopic: function()

Retrieves the current topic of the History object.  The “topic” keyword is used in conjunction with mojo.Messaging, and will broadcast a message based on the topic whenever it is set in the History object.

Returns

{object} Topic

Example

// if current location is: http://localhost/main#topic=news&id=1234
var topic = mojo.History.getInstance().getTopic(); // returns "news"
// message topic will be triggered. Ie. mojo.Messaging.publish("news", historyParams)

getInstance

mojo.History.getInstance = function()

Static function--Retrieves a Mojo History instance.

Example

var myHistoryObj = mojo.History.getInstance();

Returns

{object} mojo.History

getHash: function()
Retrieves the hash of the current page url.
setHash: function(newHash)
Sets the hash of the current page url.
setDefault: function(defaultHashObj)
Sets the default application state of the History object.
getParams: function()
Retrieves an object representation of the current state of the History object, containing any hash name/value pairs as properties of the object.
getTopic: function()
Retrieves the current topic of the History object.
mojo.History.getInstance = function()
Static function--Retrieves a Mojo History instance.