update URL controller

This commit is contained in:
rlx 2011-11-09 17:39:06 +00:00
parent 6c231c5cd5
commit bb59e0a3b4
3 changed files with 72 additions and 68 deletions

View file

@ -27,7 +27,7 @@ Ox.Focus = (function() {
//$elements[id].removeClass('OxFocus'); //$elements[id].removeClass('OxFocus');
$('.OxFocus').removeClass('OxFocus'); // fixme: the above is better, and should work $('.OxFocus').removeClass('OxFocus'); // fixme: the above is better, and should work
stack.length && Ox.UI.elements[stack[stack.length - 1]] stack.length && Ox.UI.elements[stack[stack.length - 1]]
.addClass('OxFocus').triggerEvent('focus'); .addClass('OxFocus')/*.triggerEvent('focus')*/;
Ox.Log('Core', 'blur', id, stack); Ox.Log('Core', 'blur', id, stack);
} }
}, },
@ -43,7 +43,7 @@ Ox.Focus = (function() {
$('.OxFocus').removeClass('OxFocus'); // fixme: see above $('.OxFocus').removeClass('OxFocus'); // fixme: see above
Ox.Log('Core', 'focus', id, stack); Ox.Log('Core', 'focus', id, stack);
Ox.UI.elements[id] Ox.UI.elements[id]
.addClass('OxFocus').triggerEvent('focus'); .addClass('OxFocus')/*.triggerEvent('focus')*/;
} }
}, },
/*@ /*@

View file

@ -617,56 +617,52 @@ Ox.URL = function(options) {
push <f> Pushes a new URL push <f> Pushes a new URL
(state, title, url, callback) -> <o> URL controller (state, title, url, callback) -> <o> URL controller
state <o> State for the new URL state <o> State for the new URL
If state is null, it will be derived from url
title <s> Title for the new 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
This state object can be different from the first one If url is null, it will be derived from state
(for example: save full state, create URL from reduced state)
callback <f> callback function callback <f> callback function
state <o> New state state <o> New state
@*/ @*/
that.push = function(state, title, url, callback) { that.push = function(state, title, url, callback) {
if (Ox.isString(url)) { if (!state) {
if (state) {
pushState(state, title, url);
} else {
parseURL(url, function(state) { parseURL(url, function(state) {
pushState(state, title, url); pushState(state, title, url);
}); });
}
} else { } else {
url = constructURL(url); url = url || constructURL(state);
pushState(state, title, url); pushState(state, title, url);
} }
function pushState(state, title, url) { function pushState(state, title, url) {
self.previousURL = document.location.pathname self.previousURL = document.location.pathname
+ document.location.search + document.location.search
+ document.location.hash; + document.location.hash;
if (url != self.previousURL) {
history.pushState(Ox.extend(state, {title: title}), '', url); history.pushState(Ox.extend(state, {title: title}), '', url);
document.title = title; document.title = title;
callback && callback(state); callback && callback(state);
} }
} }
}
/*@ /*@
replace <f> Replaces the URL with a new URL replace <f> Replaces the URL with a new URL
(state, title, url, callback) -> <o> URL controller (state, title, url, callback) -> <o> URL controller
state <o> State for the new URL state <o> State for the new URL
If state is null, it will be derived from url
title <s> Title for the new 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 callback <f> callback function
state <o> New state state <o> New state
@*/ @*/
that.replace = function(state, title, url, callback) { that.replace = function(state, title, url, callback) {
if (Ox.isString(url)) { if (!state) {
if (state) {
replaceState(state, title, url);
} else {
parseURL(url, function(state) { parseURL(url, function(state) {
replaceState(state, title, url); replaceState(state, title, url);
}); });
}
} else { } else {
url = constructURL(url); url = url || constructURL(state);
replaceState(state, title, url); replaceState(state, title, url);
} }
function replaceState(state, title, url) { function replaceState(state, title, url) {

View file

@ -38,6 +38,7 @@ Ox.Dialog = function(options, self) {
maxWidth: Infinity, maxWidth: Infinity,
minHeight: 64, minHeight: 64,
minWidth: 128, minWidth: 128,
removeOnClose: false,
title: '', title: '',
width: 400 width: 400
}) })
@ -647,6 +648,8 @@ Ox.Dialog = function(options, self) {
}; };
that.close = function(callback) { that.close = function(callback) {
if (self.isOpen) {
self.isOpen = false;
that.animate({ that.animate({
opacity: 0 opacity: 0
}, 250, function() { }, 250, function() {
@ -663,6 +666,8 @@ Ox.Dialog = function(options, self) {
that.loseFocus(); that.loseFocus();
} }
that.triggerEvent('close'); that.triggerEvent('close');
self.options.removeOnClose && that.remove();
}
return that; return that;
}; };
@ -689,6 +694,8 @@ Ox.Dialog = function(options, self) {
}; };
that.open = function() { that.open = function() {
if (!self.isOpen) {
self.isOpen = true;
self.initialHeight = self.options.height; self.initialHeight = self.options.height;
self.initialWidth = self.options.width; self.initialWidth = self.options.width;
setMinAndMax(); setMinAndMax();
@ -718,6 +725,7 @@ Ox.Dialog = function(options, self) {
} }
}); });
that.triggerEvent('open'); that.triggerEvent('open');
}
return that; return that;
}; };