History Events  page     

plugin: jquery/controller/history

The jquery/controller/history plugin adds browser hash (#) based history support.

It allows you to listen to hashchange events with OpenAjax.hub.

Typically you subscribe to a history event in your controllers:

$.Controller("MyHistory",{
  "history.pagename subscribe" : function(called, data){
    //called when hash = #pagename
  }
})

Event Names

When a history event happens, an OpenAjax message is produced that starts with "history.". The remainder of the message name depends on the value of the "hash".

The following shows hash values and the corresponding published message and data.

"#foo=bar" -> "history.index" {foo: bar}
"#foo/bar" -> "history.foo.bar" {}
"#foo&bar=baz" -> "history.foo" {bar: baz}

Essentially, if the hash starts with something like #foo/bar, this gets added to the message name as "foo.bar". Once "&" is found, it adds the remainder as name-value pairs to the message data.

Controller Helper Functions

The methods on the left are added to Controller.prototype and make it easier to make changes to history.

© Jupiter IT - JavaScriptMVC Training and Support