forked from 0x2620/oxjs
url controller updates, list bugfixes
This commit is contained in:
parent
ef9040ba24
commit
3965eed153
12 changed files with 98 additions and 48 deletions
|
|
@ -242,7 +242,7 @@ Ox.URL = function(options) {
|
|||
].indexOf(state.view) > -1) {
|
||||
parts.push(state.view);
|
||||
}
|
||||
if (state.span) {
|
||||
if (state.span && state.span.length) {
|
||||
parts.push(constructSpan(state.span, state));
|
||||
}
|
||||
if (state.sort && state.sort.length) {
|
||||
|
|
@ -444,7 +444,7 @@ Ox.URL = function(options) {
|
|||
parseBeyondItem();
|
||||
} else {
|
||||
// test for item id or name
|
||||
self.options.getItem(parts[0], function(item) {
|
||||
self.options.getItem(parts[0].replace(/%20/g, ' '), function(item) {
|
||||
state.item = item;
|
||||
if (item) {
|
||||
parts.shift();
|
||||
|
|
@ -585,10 +585,13 @@ Ox.URL = function(options) {
|
|||
+ document.location.search
|
||||
+ document.location.hash,
|
||||
callback = arguments[arguments.length - 1];
|
||||
/*
|
||||
parseURL(str, function(state) {
|
||||
that.replace(constructURL(state));
|
||||
callback(state);
|
||||
});
|
||||
*/
|
||||
parseURL(str, callback);
|
||||
return that;
|
||||
}
|
||||
|
||||
|
|
@ -602,34 +605,61 @@ Ox.URL = function(options) {
|
|||
|
||||
/*@
|
||||
push <f> Pushes a new URL
|
||||
(url, callback) -> <o> URL controller
|
||||
(state) -> <o> URL controller
|
||||
url <s> New URL
|
||||
(state, title, url, callback) -> <o> URL controller
|
||||
state <o> State for the new URL
|
||||
title <s> Title for the new URL
|
||||
url <s|o> New URL, or state object to construct it from
|
||||
This state object can be different from the first one
|
||||
(for example: save full state, create URL from reduced state)
|
||||
callback <f> callback function
|
||||
state <o> New state
|
||||
state <o> State to construct the new URL from
|
||||
@*/
|
||||
that.push = function(url, callback) {
|
||||
url = callback ? url : constructURL(url);
|
||||
saveURL();
|
||||
Ox.print('PUSH', url);
|
||||
history.pushState({}, '', url);
|
||||
callback && parseURL(url, callback);
|
||||
return that;
|
||||
};
|
||||
that.push = function(state, title, url, callback) {
|
||||
if (Ox.isString(url)) {
|
||||
if (state) {
|
||||
pushState(state, title, url);
|
||||
} else {
|
||||
parseURL(url, function(state) {
|
||||
pushState(state, title, url);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
url = constructURL(url);
|
||||
pushState(state, title, url);
|
||||
}
|
||||
function pushState(state, title, url) {
|
||||
history.pushState(state, title, url);
|
||||
callback && callback(state);
|
||||
}
|
||||
}
|
||||
|
||||
that.replace = function(url) {
|
||||
saveURL();
|
||||
history.replaceState({}, '', url);
|
||||
return that;
|
||||
};
|
||||
|
||||
that.update = function(state) {
|
||||
// pushes a new URL, constructed from state
|
||||
// state can have type, item, view, span, sort, find
|
||||
that.push(constructURL(state));
|
||||
return that;
|
||||
};
|
||||
/*@
|
||||
replace <f> Replaces the URL with a new URL
|
||||
(state, title, url, callback) -> <o> URL controller
|
||||
state <o> State for the new URL
|
||||
title <s> Title for the new URL
|
||||
url <s|o> New URL, or state object to construct it from
|
||||
callback <f> callback function
|
||||
state <o> New state
|
||||
@*/
|
||||
that.replace = function(state, title, url, callback) {
|
||||
if (Ox.isString(url)) {
|
||||
if (state) {
|
||||
replaceState(state, title, url);
|
||||
} else {
|
||||
parseURL(url, function(state) {
|
||||
replaceState(state, title, url);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
url = constructURL(url);
|
||||
replaceState(state, title, url);
|
||||
}
|
||||
function replaceState(state, title, url) {
|
||||
history.replaceState(state, title, url);
|
||||
callback && callback(state);
|
||||
}
|
||||
}
|
||||
|
||||
return that;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue