From 61cb8b8dcc4f1e9103203eaabab2cbe2e4217b16 Mon Sep 17 00:00:00 2001 From: rolux Date: Wed, 20 Feb 2013 10:21:43 +0530 Subject: [PATCH] Ox.URL: add 'getHash' option --- source/Ox.UI/js/Core/URL.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/source/Ox.UI/js/Core/URL.js b/source/Ox.UI/js/Core/URL.js index 7eb19661..8d22a2ae 100644 --- a/source/Ox.UI/js/Core/URL.js +++ b/source/Ox.UI/js/Core/URL.js @@ -7,6 +7,8 @@ Ox.URL URL controller findKeys <[o]> Find keys id Find key id type Value type (like "string" or "integer") + getHash Takes a state object and normalizes its "hash" property + (o) -> State object getItem Tests if a string matches an item (string, callback) -> undefined string 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); } }