rewrite history, again

This commit is contained in:
rlx 2011-11-09 22:32:45 +00:00
parent bb59e0a3b4
commit 724561a373

View file

@ -159,8 +159,16 @@ Ox.URL = function(options) {
Ox.Log('Core', 'Ox.URL options', self.options) Ox.Log('Core', 'Ox.URL options', self.options)
self.previousTitle = '';
self.previousURL = ''; self.previousURL = '';
window.onpopstate = function() {
self.previousTitle = document.title;
self.previousURL = document.location.pathname
+ document.location.search
+ document.location.hash;
};
function constructCondition(condition) { function constructCondition(condition) {
var key = condition.key == '*' ? '' : condition.key, var key = condition.key == '*' ? '' : condition.key,
operator = condition.operator, operator = condition.operator,
@ -585,22 +593,12 @@ Ox.URL = function(options) {
} }
that._construct = function(state) {
return constructURL(state);
};
that.parse = function() { that.parse = function() {
var str = arguments.length == 2 ? arguments[0] var str = arguments.length == 2 ? arguments[0]
: document.location.pathname : document.location.pathname
+ document.location.search + document.location.search
+ document.location.hash, + document.location.hash,
callback = arguments[arguments.length - 1]; callback = arguments[arguments.length - 1];
/*
parseURL(str, function(state) {
that.replace(constructURL(state));
callback(state);
});
*/
parseURL(str, callback); parseURL(str, callback);
return that; return that;
} }
@ -609,8 +607,11 @@ Ox.URL = function(options) {
pop <f> Sets the URL to the previous URL pop <f> Sets the URL to the previous URL
@*/ @*/
that.pop = function() { that.pop = function() {
history.pushState({}, '', self.previousURL); if (self.previousURL) {
return that; history.pushState({}, self.previousTitle, self.previousURL);
document.title = self.previousTitle;
}
return !!self.previousURL;
}; };
/*@ /*@
@ -634,6 +635,7 @@ Ox.URL = function(options) {
pushState(state, title, url); pushState(state, title, url);
} }
function pushState(state, title, url) { function pushState(state, title, url) {
self.previousTitle = document.title;
self.previousURL = document.location.pathname self.previousURL = document.location.pathname
+ document.location.search + document.location.search
+ document.location.hash; + document.location.hash;