From a2fb27d4694dc0566b9d7077197ac118c48633d6 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Thu, 11 Jul 2013 15:13:10 +0000 Subject: [PATCH] Ox.URL: add getPart option (page sections) --- source/Ox.UI/js/Core/URL.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/source/Ox.UI/js/Core/URL.js b/source/Ox.UI/js/Core/URL.js index 826a4d33..1f327497 100644 --- a/source/Ox.UI/js/Core/URL.js +++ b/source/Ox.UI/js/Core/URL.js @@ -19,6 +19,12 @@ Ox.URL URL controller state State object string The string to be tested callback callback function + getPart Tests if a string matches a part (page section) + May modify the state's part property + (state, string, callback) -> undefined + state State object + string The string to be tested + callback callback function getSpan Tests if a string matches a span May modify the state's view and span properties (state, string, callback) -> undefined @@ -298,7 +304,8 @@ example.com[/page][#hash] or example.com[/type][/item][/view][/span][/sort][/find][#hash] -page Special page, like "about" or "contact" +page Special page, like "about" or "contact". +part Part (section) of a page, like in "help/accounts". type Section a.k.a. item type, like "movies", "edits", "texts" etc. item Item id or title, like in '/movies/0060304', '/movies/inception' or 'texts/ABC'. Testing this is asynchonous. @@ -402,6 +409,7 @@ Ox.URL = function(options) { findKeys: [], getHash: null, getItem: null, + getPart: null, getSpan: null, pages: [], spanType: {}, @@ -516,6 +524,9 @@ Ox.URL = function(options) { var parts = []; if (state.page) { parts.push(state.page); + if (state.part) { + parts.push(state.part); + } } else { if (self.options.types.indexOf(state.type) > 0) { parts.push(state.type); @@ -581,6 +592,7 @@ Ox.URL = function(options) { canBeLocation = types.indexOf('location') > -1, canBeNumber = types.indexOf('number') > -1, length = str.split(',').length; + // !/^\d{7}$/.test(str) avoids matching imdb ids return canBeDate && /\d-/.test(str) ? 'date' : canBeDuration && /:/.test(str) ? 'duration' : canBeLocation && length == 4 ? 'location' @@ -590,7 +602,6 @@ Ox.URL = function(options) { : canBeLocation && length == 2 ? 'location' : canBeNumber && /^\d+$/.test(str) ? 'number' : ''; - // !/^\d{7}$/.test(str) avoids matching imdb ids } function parseCondition(str) { @@ -759,7 +770,13 @@ Ox.URL = function(options) { } else if (self.options.pages.indexOf(parts[0]) > -1) { // page state.page = parts[0]; - getHash(); + parts.shift(); + if (parts.length) { + // may modify state.part + self.options.getPart(state, parts[0], getHash); + } else { + getHash(); + } } else { if (self.options.types.indexOf(parts[0]) > -1) { // type @@ -906,14 +923,10 @@ Ox.URL = function(options) { getHash(); } function getHash() { - if (self.options.getHash) { - self.options.getHash(state, function() { - // may have modified state.hash - callback(state); - }); - } else { + self.options.getHash(state, function() { + // may have modified state.hash callback(state); - } + }); } }