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-09-20 00:10:35 +00:00
|
|
|
var previousUI = {},
|
|
|
|
previousURL = '',
|
2011-09-17 07:07:59 +00:00
|
|
|
regexps = {
|
|
|
|
'^$': function(pathname, search) {
|
2011-09-17 12:16:31 +00:00
|
|
|
if (/^\?url=/.test(search)) {
|
2011-09-17 07:07:59 +00:00
|
|
|
document.location = decodeURIComponent(search.substr(5));
|
|
|
|
} else {
|
2011-09-17 12:16:31 +00:00
|
|
|
if (!search && pandora.user.ui.showHome) {
|
|
|
|
pandora.$ui.home = pandora.ui.home().showScreen();
|
2011-09-17 15:43:18 +00:00
|
|
|
Ox.print('LIST', pandora.user.ui.list)
|
2011-09-17 13:04:10 +00:00
|
|
|
pandora.user.ui.list && pandora.Query.fromString(
|
|
|
|
'find=list:' + pandora.user.ui.list
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
pandora.Query.fromString(search);
|
|
|
|
pandora.UI.set({
|
|
|
|
section: 'items',
|
|
|
|
item: ''
|
|
|
|
});
|
2011-09-17 12:16:31 +00:00
|
|
|
}
|
2011-08-24 21:04:13 +00:00
|
|
|
}
|
|
|
|
},
|
2011-09-17 07:07:59 +00:00
|
|
|
'^home$': function(pathname, search) {
|
|
|
|
pandora.$ui.home = pandora.ui.home().showScreen();
|
2011-08-07 17:05:49 +00:00
|
|
|
},
|
2011-09-17 07:07:59 +00:00
|
|
|
'^(items|edits|texts)$': function(pathname, search) {
|
2011-05-25 19:42:45 +00:00
|
|
|
pandora.UI.set({
|
2011-09-17 07:07:59 +00:00
|
|
|
section: pathname
|
2011-05-25 19:42:45 +00:00
|
|
|
});
|
|
|
|
},
|
2011-09-17 07:07:59 +00:00
|
|
|
'^(about|contact|faq|news|software|terms|tour)$': function(pathname, search) {
|
|
|
|
pandora.$ui.siteDialog = pandora.ui.siteDialog(pathname).open();
|
2011-08-24 21:04:13 +00:00
|
|
|
},
|
2011-09-17 07:07:59 +00:00
|
|
|
'^help$': function(pathname, search) {
|
|
|
|
pandora.$ui.helpDialog = pandora.ui.helpDialog().open();
|
|
|
|
},
|
|
|
|
'^(signin|signout|signup)$': function(pathname, search) {
|
|
|
|
if ((pathname == 'signout') == (pandora.user.level != 'guest')) {
|
2011-08-24 21:04:13 +00:00
|
|
|
pandora.$ui.accountDialog = (
|
|
|
|
pandora.user.level == 'guest'
|
2011-09-17 07:07:59 +00:00
|
|
|
? pandora.ui.accountDialog(pathname)
|
2011-08-24 21:04:13 +00:00
|
|
|
: pandora.ui.accountSignoutDialog()
|
|
|
|
).open();
|
|
|
|
}
|
|
|
|
},
|
2011-09-17 07:07:59 +00:00
|
|
|
'^preferences$': function(pathname, search) {
|
2011-08-24 21:04:13 +00:00
|
|
|
pandora.$ui.preferencesDialog = pandora.ui.preferencesDialog().open();
|
|
|
|
},
|
2011-09-17 07:07:59 +00:00
|
|
|
'^(calendar|calendars|clip|clips|flow|grid|list|map|maps|timelines)$': function(pathname, search) {
|
2011-05-25 19:42:45 +00:00
|
|
|
pandora.UI.set({
|
|
|
|
section: 'items',
|
|
|
|
item: ''
|
|
|
|
});
|
2011-09-17 15:43:18 +00:00
|
|
|
pandora.UI.set('lists|' + pandora.user.ui.list + '|listView', pathname);
|
2011-09-17 07:07:59 +00:00
|
|
|
pandora.Query.fromString(search);
|
2011-08-07 17:05:49 +00:00
|
|
|
},
|
2011-09-17 07:07:59 +00:00
|
|
|
'^[0-9A-Z]': function(pathname, search) {
|
|
|
|
var split = pathname.split('/'),
|
2011-05-25 19:42:45 +00:00
|
|
|
item = split[0],
|
2011-09-17 07:07:59 +00:00
|
|
|
points,
|
|
|
|
time = split.length > 1
|
|
|
|
? /[\d\.:,-]+/.exec(split[split.length - 1])
|
|
|
|
: null,
|
2011-05-25 19:42:45 +00:00
|
|
|
view = new RegExp(
|
2011-09-17 18:36:30 +00:00
|
|
|
'^(' + pandora.site.itemViews.map(function(v) {
|
2011-08-24 21:04:13 +00:00
|
|
|
return v.id;
|
|
|
|
}).join('|') + ')$'
|
2011-09-17 07:07:59 +00:00
|
|
|
).exec(split[1]);
|
2011-08-24 21:04:13 +00:00
|
|
|
view = view ? view[0]
|
2011-09-17 07:07:59 +00:00
|
|
|
: time ? pandora.user.ui.videoView
|
2011-08-24 21:04:13 +00:00
|
|
|
: pandora.user.ui.itemView;
|
2011-08-24 21:57:07 +00:00
|
|
|
pandora.UI.set(Ox.extend({
|
2011-05-25 19:42:45 +00:00
|
|
|
section: 'items',
|
|
|
|
item: item,
|
|
|
|
itemView: view
|
2011-08-24 21:57:07 +00:00
|
|
|
}, ['player', 'timeline'].indexOf(view) > -1 ? {
|
|
|
|
videoView: view
|
|
|
|
} : {}));
|
2011-09-17 07:07:59 +00:00
|
|
|
if (time) {
|
|
|
|
points = time[0].split(',');
|
|
|
|
if (points.length == 2) {
|
|
|
|
points = Ox.flatten([points[0], points[1].split('-')]);
|
|
|
|
if (points[2] == '') {
|
|
|
|
points[2] = '-1';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fixme: this is duplicated, see Ox.VideoPlayer() parsePositionInput()
|
|
|
|
points = points.map(function(point, i) {
|
2011-08-24 21:04:13 +00:00
|
|
|
var parts = point.split(':').reverse();
|
|
|
|
while (parts.length > 3) {
|
|
|
|
parts.pop();
|
|
|
|
}
|
2011-09-17 07:07:59 +00:00
|
|
|
return parts.reduce(function(prev, curr, i) {
|
2011-08-24 21:04:13 +00:00
|
|
|
return prev + (parseFloat(curr) || 0) * Math.pow(60, i);
|
|
|
|
}, 0);
|
2011-09-17 07:07:59 +00:00
|
|
|
});
|
|
|
|
pandora.UI.set('videoPoints|' + item, {
|
|
|
|
'in': points.length == 1 ? 0 : points[points.length - 2],
|
|
|
|
out: points.length == 1 ? 0 : points[points.length - 1],
|
|
|
|
position: points[0],
|
|
|
|
});
|
|
|
|
points = points.map(function(point) {
|
|
|
|
return point == -1 ? '' : Ox.formatDuration(point, 3).replace(/\.000$/, '');
|
|
|
|
});
|
|
|
|
split[split.length - 1] = points[0] + (
|
|
|
|
points.length == 1 ? '' : ',' + points[1] + '-' + points[2]
|
|
|
|
);
|
|
|
|
pandora.URL.replace(split.join('/'));
|
|
|
|
} else if (!pandora.user.ui.videoPoints[item]) {
|
|
|
|
pandora.UI.set('videoPoints|' + item, {
|
|
|
|
'in': 0, out: 0, position: 0
|
|
|
|
});
|
2011-08-24 21:04:13 +00:00
|
|
|
}
|
2011-09-17 07:07:59 +00:00
|
|
|
},
|
|
|
|
'.*': function(pathname, search) {
|
|
|
|
var query = search || 'find=' + pathname;
|
2011-09-17 09:15:24 +00:00
|
|
|
pandora.UI.set({
|
|
|
|
section: 'items',
|
|
|
|
item: ''
|
|
|
|
});
|
2011-09-17 07:07:59 +00:00
|
|
|
pandora.Query.fromString(query);
|
|
|
|
pandora.URL.replace('?' + query);
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-17 07:07:59 +00:00
|
|
|
function saveURL() {
|
|
|
|
previousURL = document.location.pathname + document.location.search;
|
|
|
|
}
|
|
|
|
|
2011-05-25 19:42:45 +00:00
|
|
|
return {
|
|
|
|
|
2011-09-17 07:07:59 +00:00
|
|
|
parse: function() {
|
|
|
|
var pathname = document.location.pathname.substr(1),
|
|
|
|
search = document.location.search.substr(1);
|
|
|
|
if (/\/$/.test(pathname)) {
|
|
|
|
pathname = pathname.substr(0, pathname.length - 1);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
var url = document.location.pathname.substr(1)
|
|
|
|
+ document.location.search
|
|
|
|
+ document.location.hash;
|
|
|
|
*/
|
|
|
|
Ox.forEach(regexps, function(fn, re) {
|
|
|
|
re = new RegExp(re);
|
|
|
|
if (re.test(pathname)) {
|
|
|
|
Ox.print('URL re ' + re);
|
|
|
|
fn(pathname, search);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2011-09-17 13:04:10 +00:00
|
|
|
pandora.Query.updateGroups();
|
2011-09-17 07:07:59 +00:00
|
|
|
pandora.user.ui.showHome = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
push: function(title, url) {
|
2011-05-25 19:42:45 +00:00
|
|
|
if (arguments.length == 1) { // fixme: remove later
|
|
|
|
url = title;
|
|
|
|
}
|
2011-08-07 17:05:49 +00:00
|
|
|
if (url[0] != '/') {
|
|
|
|
url = '/' + url;
|
|
|
|
}
|
2011-09-17 07:07:59 +00:00
|
|
|
saveURL();
|
2011-08-07 17:05:49 +00:00
|
|
|
history.pushState({}, pandora.site.site.name + (title ? ' - ' + title : ''), url);
|
2011-05-25 19:42:45 +00:00
|
|
|
},
|
|
|
|
|
2011-09-17 07:07:59 +00:00
|
|
|
pushPrevious: function() {
|
|
|
|
history.pushState({}, '', previousURL);
|
2011-05-25 19:42:45 +00:00
|
|
|
},
|
|
|
|
|
2011-09-17 07:07:59 +00:00
|
|
|
set: function(title, url) {
|
2011-08-17 13:23:17 +00:00
|
|
|
if (arguments.length == 1) { // fixme: remove later
|
|
|
|
url = title;
|
|
|
|
}
|
|
|
|
if (url[0] != '/') {
|
|
|
|
url = '/' + url;
|
|
|
|
}
|
|
|
|
history.pushState({}, pandora.site.site.name + (title ? ' - ' + title : ''), url);
|
2011-09-20 00:10:35 +00:00
|
|
|
this._update();
|
2011-08-17 13:23:17 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 21:04:13 +00:00
|
|
|
replace: function(title, url) {
|
|
|
|
if (arguments.length == 1) { // fixme: remove later
|
|
|
|
url = title;
|
|
|
|
}
|
|
|
|
if (url[0] != '/') {
|
|
|
|
url = '/' + url;
|
|
|
|
}
|
2011-09-17 07:07:59 +00:00
|
|
|
saveURL();
|
2011-08-24 21:04:13 +00:00
|
|
|
history.replaceState({}, pandora.site.site.name + (title ? ' - ' + title : ''), url);
|
|
|
|
},
|
|
|
|
|
2011-05-25 19:42:45 +00:00
|
|
|
update: function() {
|
2011-09-20 00:10:35 +00:00
|
|
|
this.set(pandora.Query.toString());
|
|
|
|
},
|
|
|
|
|
|
|
|
_update: function() {
|
|
|
|
// fixme: make this method private
|
|
|
|
var previousUI = pandora.UI.getPrevious();
|
|
|
|
Ox.print('now', pandora.user.ui, 'previously', previousUI)
|
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-09-20 00:10:35 +00:00
|
|
|
if (pandora.user.ui.section != previousUI.section) {
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.appPanel.replaceElement(1, pandora.$ui.mainPanel = pandora.ui.mainPanel());
|
2011-09-20 00:10:35 +00:00
|
|
|
} else if (!pandora.user.ui.item && !previousUI.item) {
|
2011-08-17 13:23:17 +00:00
|
|
|
// list to list
|
2011-09-20 00:10:35 +00:00
|
|
|
var isClipView = pandora.isClipView(),
|
|
|
|
list = pandora.user.ui.lists[pandora.user.ui.list],
|
|
|
|
previousList = previousUI.lists[previousUI.list],
|
|
|
|
wasClipView = pandora.isClipView(previousList.listView);
|
|
|
|
if (list.listView != previousList.listView) {
|
|
|
|
pandora.$ui.mainMenu.checkItem('viewMenu_movies_' + list.listView);
|
|
|
|
pandora.$ui.viewSelect.options({value: list.listView});
|
|
|
|
Ox.print('is', isClipView, 'was', wasClipView);
|
|
|
|
if (isClipView != wasClipView) {
|
|
|
|
pandora.$ui.mainMenu.replaceMenu('sortMenu', pandora.getSortMenu());
|
|
|
|
pandora.$ui.sortSelect.replaceWith(pandora.$ui.sortSelect = pandora.ui.sortSelect());
|
|
|
|
if (isClipView && !wasClipView) {
|
|
|
|
pandora.UI.set('lists|' + pandora.user.ui.list + '|selected', []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!Ox.isEqual(list.sort, previousList.sort)) {
|
|
|
|
pandora.$ui.mainMenu.checkItem('sortMenu_sortmovies_' + list.sort[0].key);
|
|
|
|
pandora.$ui.mainMenu.checkItem('sortMenu_ordermovies_' + (
|
|
|
|
list.sort[0].operator == '' ? pandora.getSortOperator(list.sort[0].key)
|
|
|
|
: list.sort[0].operator == '+' ? 'ascending' : 'descending'
|
|
|
|
));
|
|
|
|
pandora.$ui.sortSelect.options({value: list.sort[0].key});
|
|
|
|
}
|
|
|
|
pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info());
|
|
|
|
Ox.print('EQUAL?', pandora.user.ui.query, previousUI.query, Ox.isEqual(pandora.user.ui.query, previousUI.query))
|
|
|
|
if (Ox.isEqual(pandora.user.ui.query, previousUI.query)) {
|
|
|
|
pandora.$ui.contentPanel.replaceElement(1, pandora.$ui.list = pandora.ui.list());
|
2011-08-17 13:23:17 +00:00
|
|
|
} else {
|
2011-09-20 00:10:35 +00:00
|
|
|
pandora.$ui.mainPanel.replaceElement(1, pandora.$ui.rightPanel = pandora.ui.rightPanel());
|
2011-08-17 13:23:17 +00:00
|
|
|
}
|
2011-09-18 02:22:50 +00:00
|
|
|
// fixme: should list selection and deselection happen here?
|
|
|
|
// (home and menu may cause a list switch)
|
2011-09-20 00:10:35 +00:00
|
|
|
} else if (!pandora.user.ui.item || !previousUI.item) {
|
2011-08-17 13:23:17 +00:00
|
|
|
// 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 {
|
2011-08-17 13:23:17 +00:00
|
|
|
// item to item
|
2011-09-20 00:10:35 +00:00
|
|
|
if (pandora.user.ui.item != previousUI.item) {
|
2011-09-18 21:18:05 +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-09-17 07:07:59 +00:00
|
|
|
// fixme: should be 'video', not 'player'
|
2011-05-25 19:42:45 +00:00
|
|
|
if (
|
2011-09-20 00:10:35 +00:00
|
|
|
previousUI.item &&
|
|
|
|
['player', 'timeline'].indexOf(previousUI.itemView) > -1
|
2011-05-25 19:42:45 +00:00
|
|
|
) {
|
2011-08-17 09:29:42 +00:00
|
|
|
var $item = pandora.$ui[
|
2011-09-20 00:10:35 +00:00
|
|
|
previousUI.itemView == 'player' ? 'player' : 'editor'
|
2011-08-17 09:29:42 +00:00
|
|
|
];
|
|
|
|
$item && pandora.UI.set(
|
2011-09-20 00:10:35 +00:00
|
|
|
'videoPoints|' + previousUI.item + '|position',
|
2011-08-17 09:29:42 +00:00
|
|
|
$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
|
|
|
|
|
|
|
}());
|