cablegates/static/js/pandora/URL.js

214 lines
8.5 KiB
JavaScript
Raw Permalink Normal View History

2011-07-29 18:37:11 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
2011-06-20 18:34:23 +00:00
2011-05-25 19:42:45 +00:00
pandora.URL = (function() {
2011-08-07 17:05:49 +00:00
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();
},
2011-08-07 17:05:49 +00:00
'^\\?url=': function(url) {
Ox.print('URL', url)
document.location = decodeURIComponent(url.substr(5));
},
2011-05-25 19:42:45 +00:00
'^\\?': function(url) {
pandora.Query.fromString(url);
pandora.UI.set({
section: 'items',
item: ''
});
},
'^(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();
2011-05-25 19:42:45 +00:00
},
'^admin': function(url) {
var split = url.split('/'),
section = new RegExp(
'^ˆ(statistics|users)$'
).exec(split[1]);
section = section ? section[0] : 'users';
pandora.UI.set({
section: 'site',
sitePage: url
2011-05-28 11:18:28 +00:00
});
2011-05-25 19:42:45 +00:00
},
2011-08-07 17:05:49 +00:00
'^find$': function() {
2011-05-25 19:42:45 +00:00
pandora.Query.fromString('?find='); // fixme: silly hack
pandora.UI.set({
section: 'items',
item: ''
});
},
'^(calendar|calendars|clips|icons|flow|map|maps|timelines)$': function(url) {
2011-05-25 19:42:45 +00:00
pandora.UI.set({
section: 'items',
item: ''
});
2011-06-06 15:48:11 +00:00
pandora.UI.set(['lists', pandora.user.ui.list, 'listView'].join('|'), url);
2011-05-25 19:42:45 +00:00
},
2011-08-07 17:05:49 +00:00
'^texts$': function() {
pandora.UI.set({
section: 'texts'
});
},
2011-05-25 19:42:45 +00:00
'^[0-9A-Z]': function(url) {
var split = url.split('/'),
length = split.length,
2011-05-25 19:42:45 +00:00
item = split[0],
view = new RegExp(
'^(' + $.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(Ox.extend({
2011-05-25 19:42:45 +00:00
section: 'items',
item: item,
itemView: view
}, ['player', 'timeline'].indexOf(view) > -1 ? {
videoView: view
} : {}));
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, 3).replace(/\.000$/, '');
}).join('-');
pandora.URL.replace(split.join('/'))
}
2011-05-25 19:42:45 +00:00
}
};
return {
set: function(title, url) {
if (arguments.length == 1) { // fixme: remove later
url = title;
}
2011-08-07 17:05:49 +00:00
if (url[0] != '/') {
url = '/' + url;
}
history.pushState({}, pandora.site.site.name + (title ? ' - ' + title : ''), url);
2011-05-25 19:42:45 +00:00
this.update();
},
parse: function() {
var url = document.location.pathname.substr(1) +
document.location.search +
document.location.hash;
Ox.forEach(regexps, function(fn, re) {
2011-05-25 19:42:45 +00:00
//Ox.print(url, 're', re)
re = new RegExp(re);
if (re.test(url)) {
Ox.print('URL re ' + re);
fn(url);
return false;
}
});
},
push: function(title, url) {
if (arguments.length == 1) { // fixme: remove later
url = title;
}
if (url[0] != '/') {
url = '/' + url;
}
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);
},
2011-05-25 19:42:45 +00:00
update: function() {
var oldUserUI = Ox.clone(pandora.user.ui);
2011-08-17 15:35:30 +00:00
Ox.Request.cancel();
2011-08-19 20:38:19 +00:00
$('video').each(function() {
2011-08-19 20:55:02 +00:00
$(this).trigger('stop');
2011-08-19 20:38:19 +00:00
});
2011-05-25 19:42:45 +00:00
this.parse();
2011-08-07 17:05:49 +00:00
if (pandora.user.ui.section != oldUserUI.section) {
2011-06-06 15:48:11 +00:00
pandora.$ui.appPanel.replaceElement(1, pandora.$ui.mainPanel = pandora.ui.mainPanel());
2011-08-07 17:05:49 +00:00
} else if (pandora.user.ui.sitePage != oldUserUI.sitePage) {
2011-06-06 15:48:11 +00:00
pandora.$ui.mainPanel.replaceElement(1, pandora.$ui.rightPanel = pandora.ui.rightPanel());
} else if (!pandora.user.ui.item && !oldUserUI.item) {
// list to list
// fixme: isEqual doesn't work here
if (Ox.isEqual(pandora.user.ui.findQuery, oldUserUI.findQuery) && false) {
Ox.print('EQUAL', pandora.user.ui.findQuery, oldUserUI.findQuery)
pandora.$ui.contentPanel.replaceElement(1, pandora.ui.list());
} else {
pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info());
pandora.$ui.mainPanel.replaceElement(1, pandora.$ui.rightPanel = pandora.ui.rightPanel());
}
2011-08-07 17:05:49 +00:00
} else if (!pandora.user.ui.item || !oldUserUI.item) {
// list to item or item to list
2011-06-06 15:48:11 +00:00
pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info());
2011-08-08 13:58:28 +00:00
pandora.$ui.mainPanel.replaceElement(1, pandora.$ui.rightPanel = pandora.ui.rightPanel());
2011-05-25 19:42:45 +00:00
} else {
// item to item
2011-06-06 15:48:11 +00:00
pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info());
2011-08-08 13:58:28 +00:00
pandora.$ui.contentPanel.replaceElement(1, pandora.ui.item());
2011-05-25 19:42:45 +00:00
}
2011-08-07 17:05:49 +00:00
// fixme: should be 'editor', not 'timeline'
2011-05-25 19:42:45 +00:00
if (
2011-08-07 17:05:49 +00:00
oldUserUI.item &&
['player', 'timeline'].indexOf(oldUserUI.itemView) > -1
2011-05-25 19:42:45 +00:00
) {
var $item = pandora.$ui[
oldUserUI.itemView == 'player' ? 'player' : 'editor'
];
$item && pandora.UI.set(
2011-08-07 17:05:49 +00:00
'videoPosition|' + oldUserUI.item,
$item.options('position')
2011-05-25 19:42:45 +00:00
);
}
}
2011-06-20 18:34:23 +00:00
};
2011-05-25 19:42:45 +00:00
}());