forked from 0x2620/oxjs
update URL controller
This commit is contained in:
parent
6c231c5cd5
commit
bb59e0a3b4
3 changed files with 72 additions and 68 deletions
|
|
@ -617,33 +617,31 @@ Ox.URL = function(options) {
|
|||
push <f> Pushes a new URL
|
||||
(state, title, url, callback) -> <o> URL controller
|
||||
state <o> State for the new URL
|
||||
If state is null, it will be derived from 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)
|
||||
url <s|o> New URL
|
||||
If url is null, it will be derived from state
|
||||
callback <f> callback function
|
||||
state <o> New state
|
||||
@*/
|
||||
that.push = function(state, title, url, callback) {
|
||||
if (Ox.isString(url)) {
|
||||
if (state) {
|
||||
if (!state) {
|
||||
parseURL(url, function(state) {
|
||||
pushState(state, title, url);
|
||||
} else {
|
||||
parseURL(url, function(state) {
|
||||
pushState(state, title, url);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
url = constructURL(url);
|
||||
url = url || constructURL(state);
|
||||
pushState(state, title, url);
|
||||
}
|
||||
function pushState(state, title, url) {
|
||||
self.previousURL = document.location.pathname
|
||||
+ document.location.search
|
||||
+ document.location.hash;
|
||||
history.pushState(Ox.extend(state, {title: title}), '', url);
|
||||
document.title = title;
|
||||
callback && callback(state);
|
||||
if (url != self.previousURL) {
|
||||
history.pushState(Ox.extend(state, {title: title}), '', url);
|
||||
document.title = title;
|
||||
callback && callback(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -651,22 +649,20 @@ Ox.URL = function(options) {
|
|||
replace <f> Replaces the URL with a new URL
|
||||
(state, title, url, callback) -> <o> URL controller
|
||||
state <o> State for the new URL
|
||||
If state is null, it will be derived from url
|
||||
title <s> Title for the new URL
|
||||
url <s|o> New URL, or state object to construct it from
|
||||
url <s|o> New URL
|
||||
If url is null, it will be derived from state
|
||||
callback <f> callback function
|
||||
state <o> New state
|
||||
@*/
|
||||
that.replace = function(state, title, url, callback) {
|
||||
if (Ox.isString(url)) {
|
||||
if (state) {
|
||||
if (!state) {
|
||||
parseURL(url, function(state) {
|
||||
replaceState(state, title, url);
|
||||
} else {
|
||||
parseURL(url, function(state) {
|
||||
replaceState(state, title, url);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
url = constructURL(url);
|
||||
url = url || constructURL(state);
|
||||
replaceState(state, title, url);
|
||||
}
|
||||
function replaceState(state, title, url) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue