better integration of home, about, preferences, login, etc, and support for /item/position urls

This commit is contained in:
rlx 2011-08-24 21:04:13 +00:00
commit c851db9d05
11 changed files with 402 additions and 322 deletions

View file

@ -4,6 +4,14 @@
pandora.URL = (function() {
var regexps = {
'^(|home)$': function(url) {
if (url == 'home' || pandora.user.ui.showHome) {
//$('.OxLoadingScreen').stop().remove();
pandora.$ui.home = pandora.ui.home().showScreen();
pandora.user.ui.showHome = false;
}
pandora.Query.updateGroups();
},
'^\\?url=': function(url) {
Ox.print('URL', url)
document.location = decodeURIComponent(url.substr(5));
@ -15,11 +23,27 @@ pandora.URL = (function() {
item: ''
});
},
'^(|about|archives|faq|help|license|home|news|preferences|software|terms|tour)$': function(url) {
pandora.UI.set({
section: 'site',
sitePage: url || 'home'
});
'^(about|faq|home|news|software|terms|tour)$': function(url) {
pandora.$ui.siteDialog = pandora.ui.siteDialog(url).open();
pandora.Query.updateGroups();
},
'^(signin|signout|signup)$': function(url) {
if ((url == 'signout') == (pandora.user.level != 'guest')) {
pandora.$ui.accountDialog = (
pandora.user.level == 'guest'
? pandora.ui.accountDialog(url)
: pandora.ui.accountSignoutDialog()
).open();
}
pandora.Query.updateGroups();
},
'^preferences$': function() {
pandora.$ui.preferencesDialog = pandora.ui.preferencesDialog().open();
pandora.Query.updateGroups();
},
'^help$': function() {
pandora.$ui.helpDialog = pandora.ui.helpDialog().open();
pandora.Query.updateGroups();
},
'^admin': function(url) {
var split = url.split('/'),
@ -53,18 +77,40 @@ pandora.URL = (function() {
},
'^[0-9A-Z]': function(url) {
var split = url.split('/'),
length = split.length,
item = split[0],
view = new RegExp(
'^(' + $.map(pandora.site.itemViews, function(v) {
return v.id;
}).join('|') + ')$'
).exec(split[1]);
view = view ? view[0] : pandora.user.ui.itemView;
'^(' + $.map(pandora.site.itemViews, function(v) {
return v.id;
}).join('|') + ')$'
).exec(split[1]),
position = length > 1
? /[\d\.:-]+/.exec(split[length - 1])
: null;
view = view ? view[0]
: position ? pandora.user.ui.videoView
: pandora.user.ui.itemView;
pandora.UI.set({
section: 'items',
item: item,
itemView: view
});
Ox.print('POSITION', position)
if (position) {
split[length - 1] = position[0].split('-').map(function(point, i) {
// fixme: this is duplicated, see Ox.VideoPlayer() parsePositionInput()
var parts = point.split(':').reverse();
while (parts.length > 3) {
parts.pop();
}
point = parts.reduce(function(prev, curr, i) {
return prev + (parseFloat(curr) || 0) * Math.pow(60, i);
}, 0);
i == 0 && pandora.UI.set(['videoPosition', item].join('|'), point);
return Ox.formatDuration(point);
}).join('-');
pandora.URL.replace(split.join('/'))
}
}
};
@ -85,7 +131,7 @@ pandora.URL = (function() {
var url = document.location.pathname.substr(1) +
document.location.search +
document.location.hash;
$.each(regexps, function(re, fn) {
Ox.forEach(regexps, function(fn, re) {
//Ox.print(url, 're', re)
re = new RegExp(re);
if (re.test(url)) {
@ -106,6 +152,16 @@ pandora.URL = (function() {
history.pushState({}, pandora.site.site.name + (title ? ' - ' + title : ''), url);
},
replace: function(title, url) {
if (arguments.length == 1) { // fixme: remove later
url = title;
}
if (url[0] != '/') {
url = '/' + url;
}
history.replaceState({}, pandora.site.site.name + (title ? ' - ' + title : ''), url);
},
update: function() {
var oldUserUI = Ox.clone(pandora.user.ui);
Ox.Request.cancel();