cablegates/static/js/pandora/URL.js

128 lines
4.5 KiB
JavaScript
Raw 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() {
var old = {
user: {
ui: {}
}
},
regexps = {
'^\\?': function(url) {
pandora.Query.fromString(url);
pandora.UI.set({
section: 'items',
item: ''
});
},
'^(|about|archives|faq|help|license|home|news|preferences|software|terms|tour)$': function(url) {
pandora.UI.set({
section: 'site',
sitePage: url || 'home'
});
},
'^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
},
'^(find)$': function() {
pandora.Query.fromString('?find='); // fixme: silly hack
pandora.UI.set({
section: 'items',
item: ''
});
},
'^(calendar|calendars|clips|icons|flow|map|maps|timelines)$': function() {
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
},
'^[0-9A-Z]': function(url) {
var split = url.split('/'),
item = split[0],
view = new RegExp(
2011-06-06 15:48:11 +00:00
'^(' + $.map(pandora.site.itemViews, function(v) {
2011-05-28 11:18:28 +00:00
return v.id;
2011-05-25 19:42:45 +00:00
}).join('|') + ')$'
).exec(split[1]);
2011-06-06 15:48:11 +00:00
view = view ? view[0] : pandora.user.ui.itemView;
2011-05-25 19:42:45 +00:00
pandora.UI.set({
section: 'items',
item: item,
itemView: view
});
},
'^texts$': function() {
pandora.UI.set({
section: 'texts'
});
}
};
return {
set: function(title, url) {
if (arguments.length == 1) { // fixme: remove later
url = title;
}
2011-06-06 15:48:11 +00:00
history.pushState({}, pandora.site.site.name + (title ? ' - ' + title : ''), '/' + url);
old.user.ui = $.extend({}, pandora.user.ui); // make a clone
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;
$.each(regexps, function(re, fn) {
//Ox.print(url, 're', re)
re = new RegExp(re);
if (re.test(url)) {
Ox.print('URL re ' + re);
fn(url);
return false;
}
});
},
update: function() {
this.parse();
2011-06-06 15:48:11 +00:00
if (pandora.user.ui.section != old.user.ui.section) {
pandora.$ui.appPanel.replaceElement(1, pandora.$ui.mainPanel = pandora.ui.mainPanel());
} else if (pandora.user.ui.sitePage != old.user.ui.sitePage) {
pandora.$ui.mainPanel.replaceElement(1, pandora.$ui.rightPanel = pandora.ui.rightPanel());
} else if (!pandora.user.ui.item || !old.user.ui.item) {
pandora.$ui.mainPanel.replaceElement(1, pandora.$ui.rightPanel = pandora.ui.rightPanel());
pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info());
2011-05-25 19:42:45 +00:00
} else {
2011-06-06 15:48:11 +00:00
pandora.$ui.contentPanel.replaceElement(1, pandora.ui.item());
pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info());
2011-05-25 19:42:45 +00:00
}
if (
old.user.ui.item &&
['player', 'timeline'].indexOf(old.user.ui.itemView) > -1
) {
pandora.UI.set(
'videoPosition|' + old.user.ui.item,
2011-06-06 15:48:11 +00:00
pandora.$ui[
2011-05-25 19:42:45 +00:00
old.user.ui.itemView == 'player' ? 'player' : 'editor'
].options('position')
);
}
2011-06-20 18:34:23 +00:00
//delete old.user.ui;
2011-05-25 19:42:45 +00:00
}
2011-06-20 18:34:23 +00:00
};
2011-05-25 19:42:45 +00:00
}());