Ox.URL: add 'getHash' option

This commit is contained in:
rolux 2013-02-20 10:21:43 +05:30
parent 1c3af5e352
commit 61cb8b8dcc

View file

@ -7,6 +7,8 @@ Ox.URL <f> URL controller
findKeys <[o]> Find keys
id <s> Find key id
type <s> Value type (like "string" or "integer")
getHash <f> Takes a state object and normalizes its "hash" property
(o) -> <o> State object
getItem <f> Tests if a string matches an item
(string, callback) -> <u> undefined
string <s> The string to be tested
@ -372,6 +374,7 @@ Ox.URL = function(options) {
// fixme: find keys are also per type/list|item/view
// since one can search for layer properties in some item views
findKeys: [],
getHash: null,
getItem: null,
getSpan: null,
pages: [],
@ -705,11 +708,11 @@ Ox.URL = function(options) {
state = split.length ? {hash: parseHash(split.join('#'))} : {};
if (parts[0] == '') {
// empty URL
callback(state);
getHash();
} else if (self.options.pages.indexOf(parts[0]) > -1) {
// page
state.page = parts[0];
callback(state);
getHash();
} else {
if (self.options.types.indexOf(parts[0]) > -1) {
// type
@ -741,7 +744,7 @@ Ox.URL = function(options) {
state.item = '';
// set to default view
state.view = self.options.views[state.type].list[0];
callback(state);
getHash();
}
}
function parseBeyondItem() {
@ -812,7 +815,7 @@ Ox.URL = function(options) {
// set to default item view
state.view = self.options.views[state.type].item[0];
}
callback(state);
getHash();
}
}
function parseBeyondSpan() {
@ -858,6 +861,12 @@ Ox.URL = function(options) {
// find
state.find = parseFind(parts.join('/'));
}
getHash();
}
function getHash(callback) {
if (self.options.getHash) {
state = self.options.getHash(state);
}
callback(state);
}
}