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,33 +617,31 @@ 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) { parseURL(url, function(state) {
pushState(state, title, url); pushState(state, title, url);
} else { });
parseURL(url, function(state) {
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;
history.pushState(Ox.extend(state, {title: title}), '', url); if (url != self.previousURL) {
document.title = title; history.pushState(Ox.extend(state, {title: title}), '', url);
callback && callback(state); document.title = title;
callback && callback(state);
}
} }
} }
@ -651,22 +649,20 @@ Ox.URL = function(options) {
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) { parseURL(url, function(state) {
replaceState(state, title, url); replaceState(state, title, url);
} else { });
parseURL(url, function(state) {
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,22 +648,26 @@ Ox.Dialog = function(options, self) {
}; };
that.close = function(callback) { that.close = function(callback) {
that.animate({ if (self.isOpen) {
opacity: 0 self.isOpen = false;
}, 250, function() { that.animate({
// that.remove(); opacity: 0
that.hide(); }, 250, function() {
callback && callback(); // that.remove();
}); that.hide();
if (self.maximized) { callback && callback();
self.$maximizeButton.toggleTitle(); });
self.maximized = false; if (self.maximized) {
self.$maximizeButton.toggleTitle();
self.maximized = false;
}
if (self.options.focus) {
self.$layer.hide();
that.loseFocus();
}
that.triggerEvent('close');
self.options.removeOnClose && that.remove();
} }
if (self.options.focus) {
self.$layer.hide();
that.loseFocus();
}
that.triggerEvent('close');
return that; return that;
}; };
@ -689,35 +694,38 @@ Ox.Dialog = function(options, self) {
}; };
that.open = function() { that.open = function() {
self.initialHeight = self.options.height; if (!self.isOpen) {
self.initialWidth = self.options.width; self.isOpen = true;
setMinAndMax(); self.initialHeight = self.options.height;
center(); self.initialWidth = self.options.width;
reset(); setMinAndMax();
that.css({ center();
opacity: 0 reset();
}).show().animate({ that.css({
opacity: 1 opacity: 0
}, 250); }).show().animate({
if (self.options.focus) { opacity: 1
self.$layer.show(); }, 250);
that.gainFocus(); if (self.options.focus) {
} self.$layer.show();
Ox.UI.$window.bind({ that.gainFocus();
resize: function() {
var offset = that.offset();
setMinAndMax();
if (self.centered) {
center();
} else {
that.css({
left: Math.min(offset.left, self.maxLeft) + 'px',
top: Math.min(offset.top, self.maxTop) + 'px'
});
}
} }
}); Ox.UI.$window.bind({
that.triggerEvent('open'); resize: function() {
var offset = that.offset();
setMinAndMax();
if (self.centered) {
center();
} else {
that.css({
left: Math.min(offset.left, self.maxLeft) + 'px',
top: Math.min(offset.top, self.maxTop) + 'px'
});
}
}
});
that.triggerEvent('open');
}
return that; return that;
}; };