diff --git a/source/Ox.UI/js/Core/Ox.URL.js b/source/Ox.UI/js/Core/Ox.URL.js index e04d4a46..769a7a4e 100644 --- a/source/Ox.UI/js/Core/Ox.URL.js +++ b/source/Ox.UI/js/Core/Ox.URL.js @@ -91,9 +91,9 @@ k!=v:w k [v,w] != is not between (number), is not (string) All parts of the URL can be omitted, as long as the order is preserved. example.com/foo - If "foo" is not a type, item (of the default type), view (of the default - type), span id (of the default type's default view) or sort key (of the - default type's default view), then this means find *=foo + If "foo" is not a type, item (of the default type), list view (of the + default type), span id (of any list view of the default type) or sort key + (of any list view of the default type), then this means find *=foo example.com/title, or example.com/+title or example.com/-title If this neither matches a type or default type item, then this will be sort example.com/clip/+duration/title=foo @@ -132,6 +132,9 @@ example.com/@renaissance/renaissance -> example.com/calendar/ABC/renaissance example.com/@foo/foo -> example.com/map/@foo/foo foo doesn't match a place or event name, but getSpan() sets the map query to foo and returns @foo, so we get map view, zoomed to Foo, with find *=foo +example.com/clip:duration -> example.com/clip/clip:duration + clip:duration is not a sort key of the default view (grid), so the view is + set to the first list view that accepts this sort key */ @@ -407,8 +410,6 @@ Ox.URL = function(options) { } function parseURL(str, callback) { - str = str || document.location.pathname - + document.location.search + document.location.hash; var parts = str.substr(1).split('/'), state = {}; if (parts.length == 0) { @@ -448,6 +449,7 @@ Ox.URL = function(options) { } } function parseBeyondItem() { + Ox.print('pBI', state, parts.join('/')); var span, spanType, spanTypes; if ( parts.length && state.item @@ -457,7 +459,6 @@ Ox.URL = function(options) { state.view = parts[0]; parts.shift(); } - Ox.print('pBI', state, parts.join('/')); if (parts.length) { if (isNumericalSpan(parts[0])) { // test for numerical span @@ -473,7 +474,10 @@ Ox.URL = function(options) { if (spanType) { span = parseSpan(parts[0], spanType); if (span) { - if (!state.view) { + if (state.view) { + state.span = span; + parts.shift(); + } else { // if no view is given then switch to the first // view that supports a span of this type Ox.forEach(self.options.views[state.type][ @@ -486,9 +490,6 @@ Ox.URL = function(options) { return false; } }); - } else { - state.span = span; - parts.shift(); } } } @@ -514,25 +515,44 @@ Ox.URL = function(options) { } } function parseBeyondSpan() { + Ox.print('pBS', state) + var sortKeyIds, sortParts; + if (parts.length) { + sortParts = parts[0].split(','); + sortKeyIds = Ox.map(self.options.sortKeys[state.type][ + !state.item ? 'list' : 'item' + ], function(sortKeys) { + return sortKeys.map(function(sortKey) { + return sortKey.id; + }); + }); + // test if sort keys match the given view, + // or any view if no view is given + Ox.forEach( + state.view ? [state.view] + : self.options.views[state.type][!state.item ? 'list' : 'item'], + function(view) { + if (sortKeyIds[view] && sortParts.every(function(part) { + return sortKeyIds[view].indexOf(part.replace(/^[\+-]/, '')) > -1; + })) { + if (!state.view) { + // set list or item view + state.view = view; + } + // sort + state.sort = parseSort(parts[0], state); + parts.shift(); + return false; + } + } + ); + } if (!state.view) { // set to default list or item view state.view = self.options.views[state.type][ !state.item ? 'list' : 'item' ][0]; } - Ox.print('pBS', state) - var sortKeyIds = (self.options.sortKeys[state.type][ - !state.item ? 'list' : 'item' - ][state.view] || []).map(function(sortKey) { - return sortKey.id; - }); - if (parts.length && parts[0].split(',').every(function(str) { - return sortKeyIds.indexOf(str.replace(/^[\+-]/, '')) > -1; - })) { - // sort - state.sort = parseSort(parts[0], state); - parts.shift(); - } if (parts.length) { // find state.find = parseFind(parts.join('/')); @@ -545,7 +565,13 @@ Ox.URL = function(options) { return constructURL(state); }; - that.parse = function(str, callback) { + that.parse = function() { + var str = arguments.length == 2 ? arguments[0] + : document.location.pathname + + document.location.search + + document.location.hash, + callback = arguments[arguments.length - 1]; + Ox.print(str, callback) parseURL(str, callback); }