2011-07-29 18:37:11 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-06-16 20:00:10 +00:00
|
|
|
|
2011-11-05 17:04:10 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-09-29 17:25:04 +00:00
|
|
|
pandora.addList = function() {
|
|
|
|
// addList(isSmart, isFrom) or addList(list) [=duplicate]
|
|
|
|
var $folderList = pandora.$ui.folderList.personal,
|
|
|
|
isDuplicate = arguments.length == 1,
|
|
|
|
isSmart, isFrom, list, listData, data;
|
|
|
|
if (!isDuplicate) {
|
|
|
|
isSmart = arguments[0];
|
|
|
|
isFrom = arguments[1];
|
|
|
|
data = {
|
|
|
|
name: 'Untitled',
|
|
|
|
status: 'private',
|
|
|
|
type: !isSmart ? 'static' : 'smart'
|
|
|
|
};
|
|
|
|
if (isFrom) {
|
|
|
|
if (!isSmart) {
|
|
|
|
data.items = pandora.user.ui.listSelection;
|
|
|
|
} else {
|
|
|
|
data.query = pandora.user.ui.find;
|
|
|
|
}
|
|
|
|
}
|
2012-04-19 08:53:22 +00:00
|
|
|
addList();
|
2011-09-29 17:25:04 +00:00
|
|
|
} else {
|
|
|
|
list = arguments[0];
|
|
|
|
listData = pandora.getListData();
|
|
|
|
data = {
|
|
|
|
name: listData.name,
|
|
|
|
status: listData.status,
|
|
|
|
type: listData.type
|
|
|
|
};
|
|
|
|
if (data.type == 'smart') {
|
|
|
|
data.query = listData.query;
|
|
|
|
}
|
2012-04-19 08:50:41 +00:00
|
|
|
pandora.api.findLists({
|
|
|
|
query: {conditions: [{key: 'id', value: list, operator: '=='}]},
|
|
|
|
keys: ['description']
|
2011-09-29 17:25:04 +00:00
|
|
|
}, function(result) {
|
2012-04-19 08:50:41 +00:00
|
|
|
data.description = result.data.items[0].description;
|
|
|
|
if (data.type == 'static') {
|
|
|
|
var query = {
|
|
|
|
conditions: [{key: 'list', value: list, operator: '=='}],
|
|
|
|
operator: '&'
|
|
|
|
};
|
2011-09-29 17:25:04 +00:00
|
|
|
pandora.api.find({
|
2012-04-19 08:50:41 +00:00
|
|
|
query: query
|
2011-09-29 17:25:04 +00:00
|
|
|
}, function(result) {
|
2012-04-19 08:50:41 +00:00
|
|
|
if (result.data.items) {
|
|
|
|
pandora.api.find({
|
|
|
|
query: query,
|
|
|
|
keys: ['id'],
|
|
|
|
sort: [{key: 'id', operator: ''}],
|
|
|
|
range: [0, result.data.items]
|
|
|
|
}, function(result) {
|
|
|
|
var items = result.data.items.map(function(item) {
|
|
|
|
return item.id;
|
|
|
|
});
|
|
|
|
addList(items);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
addList();
|
|
|
|
}
|
2012-03-10 00:23:44 +00:00
|
|
|
});
|
2011-09-29 17:25:04 +00:00
|
|
|
} else {
|
2012-04-19 08:50:41 +00:00
|
|
|
addList()
|
2011-09-29 17:25:04 +00:00
|
|
|
}
|
2012-03-10 00:23:44 +00:00
|
|
|
});
|
2011-09-29 17:25:04 +00:00
|
|
|
}
|
|
|
|
function addList(items) {
|
|
|
|
pandora.api.addList(data, function(result) {
|
|
|
|
var newList = result.data.id;
|
|
|
|
if (items) {
|
|
|
|
pandora.api.addListItems({
|
|
|
|
list: newList,
|
|
|
|
items: items
|
|
|
|
}, function() {
|
|
|
|
getPosterFrames(newList);
|
2012-03-10 00:23:44 +00:00
|
|
|
});
|
2011-09-29 17:25:04 +00:00
|
|
|
} else {
|
|
|
|
getPosterFrames(newList);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function getPosterFrames(newList) {
|
2011-12-04 12:44:15 +00:00
|
|
|
var sortKey = Ox.getObjectById(pandora.site.itemKeys, 'votes')
|
|
|
|
? 'votes'
|
|
|
|
: 'timesaccessed';
|
2011-09-29 17:25:04 +00:00
|
|
|
if (!isDuplicate) {
|
|
|
|
pandora.api.find({
|
|
|
|
query: {
|
|
|
|
conditions: [{key: 'list', value: newList, operator: '=='}],
|
|
|
|
operator: '&'
|
|
|
|
},
|
|
|
|
keys: ['id', 'posterFrame'],
|
2011-12-04 12:44:15 +00:00
|
|
|
sort: [{key: sortKey, operator: ''}],
|
2011-09-29 17:25:04 +00:00
|
|
|
range: [0, 4]
|
|
|
|
}, function(result) {
|
|
|
|
var posterFrames = result.data.items.map(function(item) {
|
|
|
|
return {item: item.id, position: item.posterFrame};
|
|
|
|
});
|
2011-10-29 17:46:46 +00:00
|
|
|
posterFrames = posterFrames.length == 1
|
2011-09-29 17:25:04 +00:00
|
|
|
? Ox.repeat([posterFrames[0]], 4)
|
|
|
|
: posterFrames.length == 2
|
|
|
|
? [posterFrames[0], posterFrames[1], posterFrames[1], posterFrames[0]]
|
|
|
|
: posterFrames.length == 3
|
|
|
|
? [posterFrames[0], posterFrames[1], posterFrames[2], posterFrames[0]]
|
|
|
|
: posterFrames;
|
|
|
|
setPosterFrames(newList, posterFrames);
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
pandora.api.findLists({
|
|
|
|
query: {
|
|
|
|
conditions: [{key: 'id', value: list, operator: '=='}],
|
|
|
|
operator: '&'
|
|
|
|
},
|
|
|
|
keys: ['posterFrames']
|
|
|
|
}, function(result) {
|
|
|
|
setPosterFrames(newList, result.data.items[0].posterFrames);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function setPosterFrames(newList, posterFrames) {
|
|
|
|
pandora.api.editList({
|
|
|
|
id: newList,
|
|
|
|
posterFrames: posterFrames
|
|
|
|
}, function() {
|
|
|
|
reloadFolder(newList);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function reloadFolder(newList) {
|
2012-01-27 18:29:26 +00:00
|
|
|
pandora.$ui.folder[0].options({collapsed: false});
|
2011-09-29 17:25:04 +00:00
|
|
|
Ox.Request.clearCache('findLists');
|
|
|
|
$folderList.bindEventOnce({
|
|
|
|
load: function(data) {
|
|
|
|
$folderList.gainFocus()
|
2011-11-07 18:45:06 +00:00
|
|
|
.options({selected: [newList]})
|
2012-02-15 20:57:56 +00:00
|
|
|
.editCell(newList, 'name', true);
|
2011-09-29 17:25:04 +00:00
|
|
|
pandora.UI.set({
|
|
|
|
find: {
|
|
|
|
conditions: [{key: 'list', value: newList, operator: '=='}],
|
|
|
|
operator: '&'
|
|
|
|
}
|
2011-10-29 17:46:46 +00:00
|
|
|
});
|
2011-09-29 17:25:04 +00:00
|
|
|
}
|
|
|
|
}).reloadList();
|
|
|
|
}
|
|
|
|
};
|
2013-02-20 11:29:29 +00:00
|
|
|
pandora.addText = function(options) {
|
2013-02-16 01:20:40 +00:00
|
|
|
var $folderList = pandora.$ui.folderList.personal;
|
2013-02-20 11:29:29 +00:00
|
|
|
options = options || {};
|
|
|
|
pandora.api.addText(options, function(result) {
|
2013-02-16 01:20:40 +00:00
|
|
|
reloadFolder(result.data.id);
|
|
|
|
});
|
|
|
|
function reloadFolder(newId) {
|
|
|
|
pandora.$ui.folder[0].options({collapsed: false});
|
|
|
|
Ox.Request.clearCache('findTexts');
|
|
|
|
$folderList.bindEventOnce({
|
|
|
|
load: function(data) {
|
|
|
|
$folderList.gainFocus()
|
|
|
|
.options({selected: [newId]})
|
|
|
|
.editCell(newId, 'name', true);
|
|
|
|
pandora.UI.set(pandora.user.ui.section.slice(0, -1), newId);
|
|
|
|
}
|
|
|
|
}).reloadList();
|
|
|
|
}
|
|
|
|
}
|
2011-09-29 17:25:04 +00:00
|
|
|
|
2013-02-16 01:20:40 +00:00
|
|
|
pandora.changeFolderItemStatus = function(id, status, callback) {
|
|
|
|
var ui = pandora.user.ui,
|
|
|
|
folderItems = ui.section == 'items' ? 'Lists' : Ox.toTitleCase(ui.section),
|
|
|
|
folderItem = folderItems.slice(0, -1);
|
2011-11-06 15:12:46 +00:00
|
|
|
if (status == 'private') {
|
2013-02-16 01:20:40 +00:00
|
|
|
pandora.api['find' + folderItems]({
|
2011-11-06 15:12:46 +00:00
|
|
|
query: {conditions: [{key: 'id', value: id, operator: '=='}]},
|
2011-11-06 18:36:22 +00:00
|
|
|
keys: ['name', 'subscribers']
|
2011-11-06 15:12:46 +00:00
|
|
|
}, function(result) {
|
2011-11-06 18:36:22 +00:00
|
|
|
var name = result.data.items[0].name,
|
|
|
|
subscribers = result.data.items[0].subscribers;
|
2011-11-06 15:12:46 +00:00
|
|
|
if (subscribers) {
|
2011-11-06 18:36:22 +00:00
|
|
|
pandora.ui.makeListPrivateDialog(name, subscribers, function(makePrivate) {
|
|
|
|
if (makePrivate) {
|
|
|
|
changeListStatus();
|
|
|
|
} else {
|
|
|
|
callback({data: {
|
|
|
|
id: id,
|
|
|
|
status: 'public'
|
|
|
|
}});
|
|
|
|
}
|
2011-11-06 15:12:46 +00:00
|
|
|
}).open();
|
|
|
|
} else {
|
2013-02-16 01:20:40 +00:00
|
|
|
changeFolderItemStatus();
|
2011-11-06 15:12:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2013-02-16 01:20:40 +00:00
|
|
|
changeFolderItemStatus();
|
2011-11-06 15:12:46 +00:00
|
|
|
}
|
2013-02-16 01:20:40 +00:00
|
|
|
function changeFolderItemStatus() {
|
|
|
|
pandora.api['edit' + folderItem]({
|
2011-11-06 18:36:22 +00:00
|
|
|
id: id,
|
2011-11-06 15:12:46 +00:00
|
|
|
status: status
|
|
|
|
}, callback);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-01 14:00:48 +00:00
|
|
|
pandora.clearIconCache = function(item) {
|
|
|
|
['poster', 'icon'].forEach(function(icon) {
|
|
|
|
['', 64, 128, 512].forEach(function(size) {
|
|
|
|
var url = '/' + item + '/' + icon + size + '.jpg',
|
|
|
|
xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('POST', url);
|
|
|
|
xhr.send();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-08-17 15:41:00 +00:00
|
|
|
pandora.clearListIconCache = function(list) {
|
|
|
|
['', 256].forEach(function(size) {
|
|
|
|
var url = '/list/' + list + '/icon' + size + '.jpg',
|
|
|
|
xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('POST', url);
|
|
|
|
xhr.send();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-10-27 18:47:52 +00:00
|
|
|
pandora.clickLink = function(e) {
|
2012-02-17 16:13:48 +00:00
|
|
|
if (
|
|
|
|
e.target.hostname == document.location.hostname
|
2012-06-04 09:23:01 +00:00
|
|
|
&& !Ox.startsWith(e.target.pathname, '/static')
|
2012-02-17 16:13:48 +00:00
|
|
|
) {
|
2012-02-19 14:15:24 +00:00
|
|
|
if (pandora.$ui.home && e.target.pathname != '/home') {
|
|
|
|
pandora.$ui.home.fadeOutScreen();
|
|
|
|
}
|
2011-10-27 18:47:52 +00:00
|
|
|
pandora.URL.push(e.target.pathname);
|
|
|
|
} else {
|
2012-01-17 15:44:09 +00:00
|
|
|
window.open('/url=' + encodeURIComponent(e.target.href), '_blank');
|
2011-10-27 18:47:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-10-09 10:04:30 +00:00
|
|
|
pandora.createLinks = function($element) {
|
2013-02-10 12:31:54 +00:00
|
|
|
function isExternalLink(target) {
|
2013-02-13 04:54:16 +00:00
|
|
|
return target.hostname != document.location.hostname
|
|
|
|
|| Ox.startsWith(target.pathname, '/static');
|
2013-02-10 12:31:54 +00:00
|
|
|
}
|
2011-10-27 18:47:52 +00:00
|
|
|
$element
|
2012-05-28 14:10:11 +00:00
|
|
|
.on({
|
2013-02-01 14:06:22 +00:00
|
|
|
click: function(e) {
|
2013-02-13 04:54:16 +00:00
|
|
|
if($(e.target).is('a') && isExternalLink(e.target)) {
|
2013-02-01 14:06:22 +00:00
|
|
|
e.preventDefault();
|
|
|
|
window.open('/url=' + encodeURIComponent(e.target.href), '_blank');
|
|
|
|
}
|
2011-10-27 18:47:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
singleclick: function(e) {
|
2013-02-13 04:54:16 +00:00
|
|
|
if($(e.target).is('a') && !isExternalLink(e.target)) {
|
2013-02-10 12:31:54 +00:00
|
|
|
pandora.clickLink(e);
|
|
|
|
}
|
2011-10-27 18:47:52 +00:00
|
|
|
}
|
|
|
|
});
|
2011-10-09 10:04:30 +00:00
|
|
|
};
|
|
|
|
|
2011-09-04 12:43:59 +00:00
|
|
|
pandora.enableDragAndDrop = function($list, canMove) {
|
|
|
|
|
2011-09-05 02:20:38 +00:00
|
|
|
var $tooltip = Ox.Tooltip({
|
2011-09-04 12:43:59 +00:00
|
|
|
animate: false
|
2011-09-05 02:20:38 +00:00
|
|
|
}),
|
|
|
|
drag = {},
|
|
|
|
scrollInterval;
|
2011-09-04 12:43:59 +00:00
|
|
|
|
|
|
|
$list.bindEvent({
|
|
|
|
draganddropstart: function(data) {
|
|
|
|
drag.action = 'copy';
|
|
|
|
drag.ids = $list.options('selected'),
|
|
|
|
drag.item = drag.ids.length == 1
|
|
|
|
? $list.value(drag.ids[0], 'title')
|
|
|
|
: drag.ids.length;
|
|
|
|
drag.source = pandora.getListData(),
|
|
|
|
drag.targets = {};
|
|
|
|
Ox.forEach(pandora.$ui.folderList, function($list) {
|
2012-05-22 13:15:16 +00:00
|
|
|
$list.addClass('OxDroppable').find('.OxItem').each(function() {
|
2011-09-04 12:43:59 +00:00
|
|
|
var $item = $(this),
|
|
|
|
id = $item.data('id'),
|
|
|
|
data = $list.value(id);
|
|
|
|
drag.targets[id] = Ox.extend({
|
|
|
|
editable: data.user == pandora.user.username
|
|
|
|
&& data.type == 'static',
|
|
|
|
selected: $item.is('.OxSelected')
|
|
|
|
}, data);
|
|
|
|
if (!drag.targets[id].selected && drag.targets[id].editable) {
|
|
|
|
$item.addClass('OxDroppable');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2012-05-28 14:08:23 +00:00
|
|
|
$tooltip.options({title: getTitle()}).show(data.event);
|
2012-05-28 14:10:11 +00:00
|
|
|
canMove && Ox.UI.$window.on({
|
2011-09-04 12:43:59 +00:00
|
|
|
keydown: keydown,
|
|
|
|
keyup: keyup
|
|
|
|
});
|
|
|
|
},
|
|
|
|
draganddrop: function(data) {
|
2012-05-28 14:08:23 +00:00
|
|
|
var event = data.event;
|
2011-09-04 12:43:59 +00:00
|
|
|
$tooltip.options({
|
2011-09-05 02:20:38 +00:00
|
|
|
title: getTitle(event)
|
|
|
|
}).show(event);
|
|
|
|
if (scrollInterval && !isAtListsTop(event) && !isAtListsBottom(event)) {
|
|
|
|
clearInterval(scrollInterval);
|
|
|
|
scrollInterval = 0;
|
|
|
|
}
|
2011-09-04 12:43:59 +00:00
|
|
|
},
|
2011-09-04 22:06:14 +00:00
|
|
|
draganddroppause: function(data) {
|
2012-05-28 14:08:23 +00:00
|
|
|
var event = data.event, scroll,
|
2012-01-20 18:10:25 +00:00
|
|
|
$parent, $grandparent, $panel, title;
|
2011-09-05 02:20:38 +00:00
|
|
|
// fixme: should be named showLists in the user ui prefs!
|
|
|
|
if (!pandora.user.ui.showSidebar) {
|
|
|
|
if (event.clientX < 16 && event.clientY >= 44
|
|
|
|
&& event.clientY < window.innerHeight - 16
|
|
|
|
) {
|
|
|
|
pandora.$ui.mainPanel.toggle(0);
|
|
|
|
}
|
2011-09-05 01:30:05 +00:00
|
|
|
} else {
|
2011-09-05 02:20:38 +00:00
|
|
|
$parent = $(event.target).parent();
|
2011-09-05 01:30:05 +00:00
|
|
|
$grandparent = $parent.parent();
|
2011-09-04 22:06:14 +00:00
|
|
|
$panel = $parent.is('.OxCollapsePanel') ? $parent
|
2011-09-05 01:30:05 +00:00
|
|
|
: $grandparent.is('.OxCollapsePanel') ? $grandparent : null;
|
|
|
|
if ($panel) {
|
2012-01-20 18:10:25 +00:00
|
|
|
title = $panel.children('.OxBar').children('.OxTitle')
|
2011-09-05 01:30:05 +00:00
|
|
|
.html().split(' ')[0].toLowerCase();
|
2012-01-20 18:10:25 +00:00
|
|
|
if (!pandora.user.ui.showFolder.items[title]) {
|
|
|
|
Ox.UI.elements[$panel.data('oxid')].options({collapsed: false});
|
|
|
|
}
|
2011-09-05 01:30:05 +00:00
|
|
|
}
|
2011-09-05 02:20:38 +00:00
|
|
|
if (!scrollInterval) {
|
|
|
|
scroll = isAtListsTop(event) ? -16
|
|
|
|
: isAtListsBottom(event) ? 16 : 0
|
|
|
|
if (scroll) {
|
|
|
|
scrollInterval = setInterval(function() {
|
2012-05-22 13:15:16 +00:00
|
|
|
pandora.$ui.folders.scrollTop(
|
|
|
|
pandora.$ui.folders.scrollTop() + scroll
|
2011-09-05 02:20:38 +00:00
|
|
|
);
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
}
|
2011-09-04 22:06:14 +00:00
|
|
|
}
|
|
|
|
},
|
2011-09-04 12:43:59 +00:00
|
|
|
draganddropenter: function(data) {
|
2012-05-28 14:08:23 +00:00
|
|
|
var $parent = $(data.event.target).parent(),
|
2011-09-04 12:43:59 +00:00
|
|
|
$item = $parent.is('.OxItem') ? $parent : $parent.parent(),
|
|
|
|
$list = $item.parent().parent().parent().parent();
|
|
|
|
if ($list.is('.OxDroppable')) {
|
|
|
|
$item.addClass('OxDrop');
|
|
|
|
drag.target = drag.targets[$item.data('id')];
|
|
|
|
} else {
|
|
|
|
drag.target = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
draganddropleave: function(data) {
|
2012-05-28 14:08:23 +00:00
|
|
|
var $parent = $(data.event.target).parent(),
|
2011-09-04 12:43:59 +00:00
|
|
|
$item = $parent.is('.OxItem') ? $parent : $parent.parent();
|
|
|
|
if ($item.is('.OxDroppable')) {
|
|
|
|
$item.removeClass('OxDrop');
|
|
|
|
drag.target = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
draganddropend: function(data) {
|
2011-11-04 15:54:42 +00:00
|
|
|
Ox.Log('', data, drag, '------------');
|
2012-05-28 14:10:11 +00:00
|
|
|
canMove && Ox.UI.$window.off({
|
2011-09-04 12:43:59 +00:00
|
|
|
keydown: keydown,
|
|
|
|
keyup: keyup
|
|
|
|
});
|
|
|
|
if (drag.target && drag.target.editable && !drag.target.selected) {
|
|
|
|
if (drag.action == 'copy' || (
|
|
|
|
drag.action == 'move' && drag.source.editable
|
|
|
|
)) {
|
|
|
|
if (drag.action == 'move') {
|
|
|
|
pandora.api.removeListItems({
|
2011-09-28 00:10:26 +00:00
|
|
|
list: pandora.user.ui._list,
|
2011-09-04 12:43:59 +00:00
|
|
|
items: data.ids
|
|
|
|
}, pandora.reloadList);
|
|
|
|
}
|
|
|
|
pandora.api.addListItems({
|
|
|
|
list: drag.target.id,
|
|
|
|
items: data.ids
|
|
|
|
}, function() {
|
|
|
|
Ox.Request.clearCache(); // fixme: remove
|
|
|
|
pandora.api.find({
|
|
|
|
query: {
|
|
|
|
conditions: [{key: 'list', value: drag.target.id, operator: '='}],
|
|
|
|
operator: ''
|
|
|
|
}
|
|
|
|
}, function(result) {
|
|
|
|
var folder = drag.target.status != 'featured' ? 'personal' : 'featured';
|
2011-11-04 15:54:42 +00:00
|
|
|
//Ox.Log('', drag.source.status, '//////', drag.target.status)
|
2011-09-04 12:43:59 +00:00
|
|
|
pandora.$ui.folderList[folder].value(
|
|
|
|
drag.target.id, 'items',
|
|
|
|
result.data.items
|
|
|
|
);
|
|
|
|
cleanup(250);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cleanup(0);
|
|
|
|
}
|
|
|
|
function cleanup(ms) {
|
|
|
|
drag = {};
|
2011-09-05 02:20:38 +00:00
|
|
|
clearInterval(scrollInterval);
|
|
|
|
scrollInterval = 0;
|
2011-09-04 12:43:59 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
$('.OxDroppable').removeClass('OxDroppable');
|
|
|
|
$('.OxDrop').removeClass('OxDrop');
|
|
|
|
$tooltip.hide();
|
|
|
|
}, ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-05-28 14:08:23 +00:00
|
|
|
function getTitle() {
|
2011-09-04 12:43:59 +00:00
|
|
|
var image, text;
|
|
|
|
if (drag.action == 'move' && drag.source.user != pandora.user.username) {
|
|
|
|
image = 'symbolClose'
|
|
|
|
text = 'You can only remove ' + pandora.site.itemName.plural.toLowerCase()
|
|
|
|
+ '<br/>from your own lists.';
|
|
|
|
} else if (drag.action == 'move' && drag.source.type == 'smart') {
|
|
|
|
image = 'symbolClose';
|
|
|
|
text = 'You can\'t remove ' + pandora.site.itemName.plural.toLowerCase()
|
|
|
|
+ '<br/>from smart lists.';
|
|
|
|
} else if (drag.target && drag.target.user != pandora.user.username) {
|
|
|
|
image = 'symbolClose'
|
|
|
|
text = 'You can only ' + drag.action + ' ' + pandora.site.itemName.plural.toLowerCase()
|
|
|
|
+ '<br/>to your own lists';
|
|
|
|
} else if (drag.target && drag.target.type == 'smart') {
|
|
|
|
image = 'symbolClose'
|
|
|
|
text = 'You can\'t ' + drag.action + ' ' + pandora.site.itemName.plural.toLowerCase()
|
|
|
|
+ '<br/>to smart lists';
|
|
|
|
} else {
|
|
|
|
image = drag.action == 'copy' ? 'symbolAdd' : 'symbolRemove';
|
|
|
|
text = Ox.toTitleCase(drag.action) + ' ' + (
|
|
|
|
Ox.isString(drag.item)
|
|
|
|
? '"' + drag.item + '"'
|
|
|
|
: drag.item + ' ' + pandora.site.itemName[
|
|
|
|
drag.item == 1 ? 'singular' : 'plural'
|
|
|
|
].toLowerCase()
|
|
|
|
) + '</br> to ' + (
|
2011-10-29 17:46:46 +00:00
|
|
|
drag.target && !drag.target.selected
|
2012-02-22 10:14:07 +00:00
|
|
|
? 'the list "' + Ox.encodeHTMLEntities(drag.target.name) + '"'
|
2012-04-19 09:22:48 +00:00
|
|
|
: (pandora.user.ui._list ? 'another' : 'a') + ' list'
|
2011-09-04 12:43:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return $('<div>')
|
|
|
|
.append(
|
|
|
|
$('<div>')
|
|
|
|
.css({
|
|
|
|
float: 'left',
|
|
|
|
width: '16px',
|
|
|
|
height: '16px',
|
|
|
|
padding: '2px',
|
2013-02-11 06:47:55 +00:00
|
|
|
border: '2px solid rgb(' + Ox.Theme.getThemeData().symbolDefaultColor.join(', ') + ')',
|
2011-09-04 12:43:59 +00:00
|
|
|
borderRadius: '12px',
|
|
|
|
margin: '3px 2px 2px 2px'
|
|
|
|
})
|
|
|
|
.append(
|
|
|
|
$('<img>')
|
|
|
|
.attr({src: Ox.UI.getImageURL(image)})
|
|
|
|
.css({width: '16px', height: '16px'})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.append(
|
|
|
|
$('<div>')
|
|
|
|
.css({
|
|
|
|
float: 'left',
|
|
|
|
margin: '1px 2px 2px 2px',
|
|
|
|
fontSize: '11px',
|
|
|
|
whiteSpace: 'nowrap'
|
|
|
|
})
|
|
|
|
.html(text)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2011-09-05 02:20:38 +00:00
|
|
|
function isAtListsTop(e) {
|
|
|
|
return pandora.user.ui.showSidebar
|
|
|
|
&& e.clientX < pandora.user.ui.sidebarSize
|
|
|
|
&& e.clientY >= 44 && e.clientY < 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAtListsBottom(e) {
|
|
|
|
var listsBottom = window.innerHeight - pandora.getInfoHeight();
|
|
|
|
return pandora.user.ui.showSidebar
|
|
|
|
&& e.clientX < pandora.user.ui.sidebarSize
|
|
|
|
&& e.clientY >= listsBottom - 16 && e.clientY < listsBottom;
|
|
|
|
}
|
|
|
|
|
2011-09-04 12:43:59 +00:00
|
|
|
function keydown(e) {
|
|
|
|
if (e.metaKey) {
|
|
|
|
drag.action = 'move';
|
|
|
|
$tooltip.options({title: getTitle()}).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function keyup(e) {
|
|
|
|
if (drag.action == 'move') {
|
|
|
|
drag.action = 'copy';
|
|
|
|
$tooltip.options({title: getTitle()}).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-05-25 19:42:45 +00:00
|
|
|
pandora.enterFullscreen = function() {
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.appPanel.size(0, 0);
|
|
|
|
pandora.user.ui.showSidebar && pandora.$ui.mainPanel.size(0, 0);
|
|
|
|
pandora.$ui.rightPanel.size(0, 0).size(2, 0);
|
2011-10-13 10:12:00 +00:00
|
|
|
!pandora.user.ui.showBrowser && pandora.$ui.contentPanel.css({
|
2011-05-25 19:42:45 +00:00
|
|
|
top: (-112 - Ox.UI.SCROLLBAR_SIZE) + 'px' // fixme: rightPanel.size(0, 0) doesn't preserve negative top of browser
|
|
|
|
});
|
2011-10-13 10:12:00 +00:00
|
|
|
pandora.user.ui.showBrowser && pandora.$ui.contentPanel.size(0, 0);
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.player.options({
|
|
|
|
height: pandora.$document.height() - 2,
|
|
|
|
width: pandora.$document.width() - 2
|
2011-06-16 20:00:10 +00:00
|
|
|
});
|
|
|
|
};
|
2011-05-25 19:42:45 +00:00
|
|
|
|
|
|
|
pandora.exitFullscreen = function() {
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.appPanel.size(0, 20);
|
|
|
|
pandora.user.ui.showSidebar && pandora.$ui.mainPanel.size(0, pandora.user.ui.sidebarSize);
|
|
|
|
pandora.$ui.rightPanel.size(0, 24).size(2, 16);
|
2011-10-13 10:12:00 +00:00
|
|
|
!pandora.user.ui.showBrowser && pandora.$ui.contentPanel.css({
|
2011-05-25 19:42:45 +00:00
|
|
|
top: 24 + (-112 - Ox.UI.SCROLLBAR_SIZE) + 'px' // fixme: rightPanel.size(0, 0) doesn't preserve negative top of browser
|
|
|
|
});
|
2011-10-13 10:12:00 +00:00
|
|
|
pandora.user.ui.showBrowser && pandora.$ui.contentPanel.size(0, 112 + Ox.UI.SCROLLBAR_SIZE);
|
2011-06-16 20:00:10 +00:00
|
|
|
};
|
|
|
|
|
2011-10-20 16:49:01 +00:00
|
|
|
pandora.getClipsItems = function(width) {
|
|
|
|
width = width || window.innerWidth
|
|
|
|
- pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 1
|
|
|
|
- Ox.UI.SCROLLBAR_SIZE;
|
|
|
|
return Math.floor((width - 8) / (128 + 8)) - 1;
|
|
|
|
};
|
|
|
|
|
2011-10-20 12:58:21 +00:00
|
|
|
pandora.getClipsQuery = function() {
|
2011-10-30 09:49:12 +00:00
|
|
|
// fixme: nice, but not needed
|
2011-10-20 12:58:21 +00:00
|
|
|
function addClipsConditions(conditions) {
|
|
|
|
conditions.forEach(function(condition) {
|
|
|
|
if (condition.conditions) {
|
|
|
|
addClipsConditions(condition.conditions);
|
|
|
|
} else if (
|
2012-01-18 19:03:29 +00:00
|
|
|
(condition.key == 'annotations'
|
|
|
|
||Ox.getIndexById(pandora.site.layers, condition.key) > -1)
|
2011-10-20 12:58:21 +00:00
|
|
|
&& condition.operator == '='
|
|
|
|
) {
|
|
|
|
clipsQuery.conditions.push(condition);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
var clipsQuery = {
|
|
|
|
conditions: []
|
|
|
|
};
|
|
|
|
addClipsConditions(pandora.user.ui.find.conditions);
|
|
|
|
clipsQuery.operator = clipsQuery.conditions.length ? '|' : '&';
|
|
|
|
return clipsQuery;
|
|
|
|
};
|
|
|
|
|
2011-11-09 22:32:54 +00:00
|
|
|
(function() {
|
|
|
|
var itemTitles = {};
|
|
|
|
pandora.getDocumentTitle = function(itemTitle) {
|
|
|
|
Ox.Log('', 'ITEM TITLES', itemTitles)
|
|
|
|
if (itemTitle) {
|
|
|
|
itemTitles[pandora.user.ui.item] = itemTitle
|
|
|
|
}
|
|
|
|
var parts = [pandora.site.site.name];
|
|
|
|
if (!pandora.user.ui.item) {
|
|
|
|
pandora.user.ui._list && parts.push('List ' + pandora.user.ui._list);
|
|
|
|
parts.push(Ox.toTitleCase(pandora.user.ui.listView) + ' View');
|
|
|
|
} else {
|
|
|
|
parts.push(itemTitles[pandora.user.ui.item] || pandora.user.ui.item);
|
|
|
|
parts.push(Ox.toTitleCase(pandora.user.ui.itemView) + ' View');
|
|
|
|
}
|
|
|
|
return parts.join(' - ');
|
|
|
|
};
|
|
|
|
}());
|
|
|
|
|
2011-11-06 08:28:10 +00:00
|
|
|
pandora.getFilterSizes = function() {
|
2012-06-25 14:37:45 +00:00
|
|
|
return Ox.splitInt(
|
|
|
|
window.innerWidth
|
|
|
|
- pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize
|
|
|
|
- 1,
|
|
|
|
5
|
2011-11-06 08:28:10 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2011-05-25 19:42:45 +00:00
|
|
|
pandora.getFoldersHeight = function() {
|
2011-09-01 04:46:44 +00:00
|
|
|
var height = 0;
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.site.sectionFolders[pandora.user.ui.section].forEach(function(folder, i) {
|
2011-09-01 04:46:44 +00:00
|
|
|
height += 16 + pandora.user.ui.showFolder[pandora.user.ui.section][folder.id] * (
|
2011-05-25 19:42:45 +00:00
|
|
|
!!folder.showBrowser * 40 + folder.items * 16
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return height;
|
2011-06-16 20:00:10 +00:00
|
|
|
};
|
2011-05-25 19:42:45 +00:00
|
|
|
|
|
|
|
pandora.getFoldersWidth = function() {
|
2011-06-06 15:48:11 +00:00
|
|
|
var width = pandora.user.ui.sidebarSize;
|
2011-11-04 15:54:42 +00:00
|
|
|
Ox.Log('', 'FOLDERS HEIGHT', pandora.getFoldersHeight(), 'INFO HEIGHT', pandora.getInfoHeight())
|
2011-09-28 17:32:03 +00:00
|
|
|
if (
|
2011-10-01 13:51:18 +00:00
|
|
|
pandora.$ui.appPanel
|
2011-11-06 18:36:22 +00:00
|
|
|
&& pandora.getFoldersHeight() > window.innerHeight - 20 - 24 -16 - 1 - pandora.getInfoHeight()
|
2011-09-28 17:32:03 +00:00
|
|
|
) {
|
2011-05-25 19:42:45 +00:00
|
|
|
width -= Ox.UI.SCROLLBAR_SIZE;
|
|
|
|
}
|
|
|
|
return width;
|
2011-06-16 20:00:10 +00:00
|
|
|
};
|
2011-05-25 19:42:45 +00:00
|
|
|
|
2011-10-29 13:50:40 +00:00
|
|
|
pandora.getInfoHeight = function(includeHidden) {
|
2011-09-05 02:20:38 +00:00
|
|
|
// fixme: new, check if it can be used more
|
2011-11-02 19:11:00 +00:00
|
|
|
var height = 0, isVideoPreview;
|
|
|
|
if (pandora.user.ui.showInfo || includeHidden) {
|
|
|
|
isVideoPreview = pandora.user.ui.item || (
|
|
|
|
pandora.user.ui.listSelection.length && !pandora.isClipView()
|
|
|
|
);
|
|
|
|
height = Math.min(
|
|
|
|
isVideoPreview
|
2012-01-30 21:16:58 +00:00
|
|
|
? Math.round(pandora.user.ui.sidebarSize / pandora.site.video.previewRatio) + 16
|
2011-11-06 11:51:04 +00:00
|
|
|
: pandora.user.ui.sidebarSize,
|
2011-11-02 19:11:00 +00:00
|
|
|
window.innerHeight - 109 // 20 menu + 24 bar + 64 (4 closed folders) + 1 resizebar
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return height;
|
2011-09-05 02:20:38 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 01:20:40 +00:00
|
|
|
pandora.getItemByIdOrTitle = function(type, str, callback) {
|
|
|
|
if (type == pandora.site.itemName.plural.toLowerCase()) {
|
|
|
|
var sortKey = Ox.getObjectById(pandora.site.itemKeys, 'votes')
|
|
|
|
? 'votes'
|
|
|
|
: 'timesaccessed';
|
|
|
|
pandora.api.get({id: str, keys: ['id']}, function(result) {
|
|
|
|
if (result.status.code == 200) {
|
|
|
|
callback(result.data.id);
|
|
|
|
} else {
|
|
|
|
pandora.api.find({
|
|
|
|
query: {
|
|
|
|
conditions: [{key: 'title', value: str, operator: '='}],
|
|
|
|
operator: '&'
|
|
|
|
},
|
|
|
|
sort: [{key: sortKey, operator: ''}],
|
|
|
|
range: [0, 100],
|
|
|
|
keys: ['id', 'title', sortKey]
|
|
|
|
}, function(result) {
|
|
|
|
var id = '';
|
|
|
|
if (result.data.items.length) {
|
|
|
|
var items = Ox.filter(Ox.map(result.data.items, function(item) {
|
|
|
|
// test if exact match or word match
|
|
|
|
var sort = new RegExp('^' + str + '$', 'i').test(item.title) ? 2000000
|
|
|
|
: new RegExp('\\b' + str + '\\b', 'i').test(item.title) ? 1000000 : 0;
|
|
|
|
return sort ? {id: item.id, sort: sort + (parseInt(item[sortKey]) || 0)} : null;
|
|
|
|
// fixme: remove the (...|| 0) check once the backend sends correct data
|
|
|
|
}));
|
|
|
|
if (items.length) {
|
|
|
|
id = items.sort(function(a, b) {
|
|
|
|
return b.sort - a.sort;
|
|
|
|
})[0].id;
|
|
|
|
}
|
2011-09-22 03:20:55 +00:00
|
|
|
}
|
2013-02-16 01:20:40 +00:00
|
|
|
callback(id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
callback(str);
|
|
|
|
}
|
2011-09-22 03:20:55 +00:00
|
|
|
}
|
|
|
|
|
2012-02-01 12:01:39 +00:00
|
|
|
pandora.getItemFind = function(find) {
|
|
|
|
var itemFind = '';
|
|
|
|
Ox.forEach(find.conditions, function(condition) {
|
|
|
|
if (
|
|
|
|
(
|
|
|
|
condition.key == '*' || condition.key == 'annotations'
|
|
|
|
|| Ox.getIndexById(pandora.site.layers, condition.key) > -1
|
|
|
|
)
|
|
|
|
&& condition.value.length
|
|
|
|
&& ['=', '=='].indexOf(condition.operator) > -1
|
|
|
|
) {
|
|
|
|
itemFind = condition.value;
|
2012-07-04 11:40:37 +00:00
|
|
|
return false;
|
2012-02-01 12:01:39 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
return itemFind;
|
|
|
|
};
|
|
|
|
|
2012-06-15 14:43:05 +00:00
|
|
|
pandora.getItemIdAndPosition = function() {
|
|
|
|
var selected, ret, ui = pandora.user.ui;
|
|
|
|
function getIdAndPositionByClipId(clipId) {
|
2012-06-15 14:44:46 +00:00
|
|
|
var split = clipId.replace('-', '/').split('/');
|
2012-06-15 14:43:05 +00:00
|
|
|
return {
|
|
|
|
id: split[0],
|
2012-06-15 14:44:46 +00:00
|
|
|
position: parseFloat(split[1])
|
2012-06-15 14:43:05 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
function getIdAndPositionByItemId(itemId) {
|
|
|
|
return {
|
|
|
|
id: itemId,
|
|
|
|
position: ui.videoPoints[itemId] ? ui.videoPoints[itemId].position : 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!ui.item) {
|
|
|
|
if (
|
|
|
|
ui.listView == 'timelines'
|
|
|
|
&& (selected = ui.listSelection).length == 1
|
|
|
|
) {
|
|
|
|
ret = getIdAndPositionByItemId(selected[0]);
|
|
|
|
} else if (
|
|
|
|
['clip', 'map', 'calendar'].indexOf(ui.listView) > -1
|
|
|
|
&& pandora.$ui.clipList
|
|
|
|
&& (selected = pandora.$ui.clipList.options('selected')).length == 1
|
|
|
|
) {
|
|
|
|
ret = getIdAndPositionByClipId(selected[0]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (['player', 'editor', 'timeline'].indexOf(ui.itemView) > -1) {
|
|
|
|
ret = getIdAndPositionByItemId(ui.item);
|
|
|
|
} else if (
|
|
|
|
['clips', 'map', 'calendar'].indexOf(ui.itemView) > -1
|
|
|
|
&& pandora.$ui.clipList
|
|
|
|
&& (selected = pandora.$ui.clipList.options('selected')).length == 1
|
|
|
|
) {
|
|
|
|
ret = getIdAndPositionByClipId(selected[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-07 12:12:13 +00:00
|
|
|
pandora.getListData = function(list) {
|
2011-11-07 18:17:46 +00:00
|
|
|
var data = {}, folder;
|
2013-02-16 01:20:40 +00:00
|
|
|
if (pandora.user.ui.section == 'items') {
|
|
|
|
list = Ox.isUndefined(list) ? pandora.user.ui._list : list;
|
|
|
|
} else {
|
|
|
|
list = Ox.isUndefined(list) ? pandora.user.ui[pandora.user.ui.section.slice(0, -1)] : list;
|
|
|
|
}
|
2011-11-07 12:12:13 +00:00
|
|
|
if (list) {
|
|
|
|
Ox.forEach(pandora.$ui.folderList, function($list, id) {
|
2011-11-07 18:17:46 +00:00
|
|
|
var ret = true;
|
|
|
|
// for the current list, we have to check in which
|
|
|
|
// folder it is selected, since for example, a personal
|
|
|
|
// list may appear again in the featured lists browser
|
|
|
|
if (
|
|
|
|
list == pandora.user.ui._list
|
|
|
|
&& $list.options('selected').length
|
|
|
|
) {
|
|
|
|
folder = id;
|
|
|
|
ret = false;
|
|
|
|
} else if (!Ox.isEmpty($list.value(list))) {
|
|
|
|
folder = id
|
|
|
|
ret = false;
|
2012-05-22 07:22:38 +00:00
|
|
|
}
|
|
|
|
// FIXME: Is there a `return ret` statement missing here?
|
2011-08-28 19:50:38 +00:00
|
|
|
});
|
2011-11-07 18:17:46 +00:00
|
|
|
if (folder) {
|
2013-02-16 01:20:40 +00:00
|
|
|
data = pandora.$ui.folderList[folder].value(list);
|
|
|
|
if (pandora.user.ui.section == 'item') {
|
|
|
|
data.editable = data.user == pandora.user.username && data.type == 'static';
|
|
|
|
} else {
|
|
|
|
data.editable = data.user == pandora.user.username;
|
|
|
|
}
|
2011-11-07 18:17:46 +00:00
|
|
|
data.folder = folder;
|
|
|
|
}
|
2011-08-24 06:19:34 +00:00
|
|
|
}
|
|
|
|
return data;
|
2011-06-16 20:00:10 +00:00
|
|
|
};
|
2011-05-25 19:42:45 +00:00
|
|
|
|
2011-09-22 03:20:55 +00:00
|
|
|
pandora.getMetadataByIdOrName = function(item, view, str, callback) {
|
|
|
|
// For a given item (or none) and a given view (or any), this takes a string
|
|
|
|
// and checks if it's an annotation/event/place id or an event/place name,
|
|
|
|
// and returns the id (or none) and the view (or none)
|
|
|
|
// fixme: "subtitles:23" is still missing
|
2012-01-09 09:55:52 +00:00
|
|
|
Ox.Log('URL', 'getMetadataByIdOrName', item, view, str);
|
2011-09-22 03:20:55 +00:00
|
|
|
var isName = str[0] == '@',
|
|
|
|
canBeAnnotation = (
|
2013-02-20 06:34:20 +00:00
|
|
|
!view || Ox.contains(['player', 'editor', 'timeline'], view)
|
2011-09-22 03:20:55 +00:00
|
|
|
) && item && !isName,
|
|
|
|
canBeEvent = !view || view == 'calendar',
|
|
|
|
canBePlace = !view || view == 'map';
|
2012-05-24 09:56:52 +00:00
|
|
|
str = isName ? str.slice(1) : str;
|
2011-09-22 03:20:55 +00:00
|
|
|
getId(canBeAnnotation ? 'annotation' : '', function(id) {
|
|
|
|
if (id) {
|
2012-01-09 09:55:52 +00:00
|
|
|
Ox.Log('URL', 'id?', id)
|
2011-09-22 03:20:55 +00:00
|
|
|
callback(id, pandora.user.ui.videoView);
|
|
|
|
} else {
|
|
|
|
getId(canBePlace ? 'place' : '', function(id) {
|
|
|
|
if (id) {
|
2011-11-04 15:54:42 +00:00
|
|
|
Ox.Log('', 'found place id', id)
|
2011-09-22 03:20:55 +00:00
|
|
|
callback(id, 'map');
|
|
|
|
} else {
|
|
|
|
getId(canBeEvent ? 'event' : '', function(id) {
|
|
|
|
if (id) {
|
|
|
|
callback(id, 'calendar');
|
|
|
|
} else if (canBePlace && isName) {
|
|
|
|
callback('@' + str, 'map');
|
|
|
|
} else {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
function getId(type, callback) {
|
|
|
|
if (type) {
|
|
|
|
pandora.api['find' + Ox.toTitleCase(type + 's')](Ox.extend({
|
|
|
|
query: {
|
2011-10-01 13:51:18 +00:00
|
|
|
conditions: [{
|
|
|
|
key: isName ? 'name' : 'id',
|
2012-01-09 09:55:52 +00:00
|
|
|
value: type != 'annotation' ? str : item + '/' + str,
|
2011-10-01 13:51:18 +00:00
|
|
|
operator: '=='
|
|
|
|
}],
|
|
|
|
operator: '&'
|
2011-09-22 03:20:55 +00:00
|
|
|
},
|
2012-01-09 09:55:52 +00:00
|
|
|
keys: type != 'annotation' ? ['id'] : ['id', 'in', 'out'],
|
2011-09-22 03:20:55 +00:00
|
|
|
range: [0, 1]
|
2012-01-09 09:55:52 +00:00
|
|
|
}, item && type != 'annotation' ? {
|
2011-10-01 13:51:18 +00:00
|
|
|
itemQuery: {
|
|
|
|
conditions: [{key: 'id', value: item, operator: '=='}],
|
|
|
|
operator: '&'
|
|
|
|
}
|
2011-09-22 03:20:55 +00:00
|
|
|
} : {}), function(result) {
|
2012-01-09 09:55:52 +00:00
|
|
|
var annotation, span;
|
|
|
|
if (result.data.items.length) {
|
|
|
|
span = result.data.items[0];
|
|
|
|
annotation = span.id.split('/')[1];
|
|
|
|
type == 'annotation' && pandora.UI.set('videoPoints.' + item, {
|
|
|
|
annotation: annotation,
|
|
|
|
'in': span['in'],
|
|
|
|
out: span.out,
|
|
|
|
position: span['in']
|
|
|
|
});
|
|
|
|
}
|
|
|
|
callback(
|
|
|
|
!span ? ''
|
|
|
|
: type != 'annotation' ? span.id
|
|
|
|
: annotation
|
|
|
|
);
|
2011-09-22 03:20:55 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-11-09 22:32:54 +00:00
|
|
|
pandora.getPageTitle = function(stateOrURL) {
|
2012-05-24 08:22:56 +00:00
|
|
|
var pages = [
|
2011-11-09 22:32:54 +00:00
|
|
|
{id: '', title: ''},
|
|
|
|
{id: 'help', title: 'Help'},
|
|
|
|
{id: 'home', title: ''},
|
|
|
|
{id: 'preferences', title: 'Preferences'},
|
|
|
|
{id: 'signin', title: 'Sign In'},
|
|
|
|
{id: 'signout', title: 'Sign Out'},
|
|
|
|
{id: 'signup', title: 'Sign Up'},
|
2011-12-24 06:13:30 +00:00
|
|
|
{id: 'software', title: 'Software'},
|
|
|
|
{id: 'tv', title: 'TV'}
|
2012-05-24 08:22:56 +00:00
|
|
|
].concat(pandora.site.sitePages),
|
2011-11-09 22:32:54 +00:00
|
|
|
page = Ox.getObjectById(
|
|
|
|
pages,
|
2012-05-24 09:56:52 +00:00
|
|
|
Ox.isObject(stateOrURL) ? stateOrURL.page : stateOrURL.slice(1)
|
2011-11-09 22:32:54 +00:00
|
|
|
);
|
|
|
|
return page
|
|
|
|
? pandora.site.site.name
|
|
|
|
+ (page.title ? ' - ' + page.title : '')
|
|
|
|
: null;
|
|
|
|
};
|
2011-10-08 14:52:00 +00:00
|
|
|
|
2011-10-09 12:46:35 +00:00
|
|
|
pandora.getSortKeyData = function(key) {
|
|
|
|
return Ox.getObjectById(pandora.site.itemKeys, key)
|
|
|
|
|| Ox.getObjectById(pandora.site.clipKeys, key);
|
2011-09-22 03:20:55 +00:00
|
|
|
}
|
|
|
|
|
2012-06-30 20:07:43 +00:00
|
|
|
pandora.getSortKeys = function() {
|
|
|
|
return pandora.site.itemKeys.filter(function(key) {
|
|
|
|
return key.sort && (
|
|
|
|
!key.capability
|
|
|
|
|| pandora.site.capabilities[key.capability][pandora.user.level]
|
|
|
|
);
|
|
|
|
}).map(function(key) {
|
|
|
|
return Ox.extend(key, {
|
|
|
|
operator: pandora.getSortOperator(key.id)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2011-10-09 12:46:35 +00:00
|
|
|
pandora.getSortOperator = function(key) {
|
|
|
|
var data = pandora.getSortKeyData(key);
|
|
|
|
return data.sortOperator || ['string', 'text'].indexOf(
|
|
|
|
Ox.isArray(data.type) ? data.type[0] : data.type
|
2011-05-25 19:42:45 +00:00
|
|
|
) > -1 ? '+' : '-';
|
2011-06-16 20:00:10 +00:00
|
|
|
};
|
2011-05-25 19:42:45 +00:00
|
|
|
|
2012-03-03 13:56:35 +00:00
|
|
|
pandora.getVideoUrl = function(id, resolution, part) {
|
2012-03-03 13:59:53 +00:00
|
|
|
var prefix = pandora.site.site.videoprefix
|
2012-03-03 15:02:30 +00:00
|
|
|
.replace('{id}', id)
|
|
|
|
.replace('{part}', part)
|
|
|
|
.replace('{resolution}', resolution)
|
|
|
|
.replace('{uid}', Ox.uid());
|
2012-03-03 13:56:35 +00:00
|
|
|
return prefix + '/' + id + '/' + resolution + 'p' + part + '.' + pandora.user.videoFormat;
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:12:23 +00:00
|
|
|
pandora.getVideoOptions = function(data) {
|
2012-02-08 11:10:26 +00:00
|
|
|
var canPlayClips = data.editable || pandora.site.capabilities.canPlayClips[pandora.user.level] >= data.rightslevel,
|
|
|
|
canPlayVideo = data.editable || pandora.site.capabilities.canPlayVideo[pandora.user.level] >= data.rightslevel,
|
2012-02-19 08:05:41 +00:00
|
|
|
options = {},
|
2012-05-21 06:05:35 +00:00
|
|
|
subtitlesLayer = pandora.site.layers.filter(function(layer) {
|
|
|
|
return layer.isSubtitles;
|
|
|
|
})[0];
|
2012-02-19 08:10:39 +00:00
|
|
|
options.subtitles = subtitlesLayer ? data.layers[subtitlesLayer.id].map(function(subtitle) {
|
2012-02-25 10:51:33 +00:00
|
|
|
return {
|
|
|
|
id: subtitle.id,
|
|
|
|
'in': subtitle['in'],
|
|
|
|
out: subtitle.out,
|
|
|
|
text: subtitle.value.replace(/\n/g, ' ').replace(/<br\/?>/g, '\n')
|
|
|
|
};
|
2012-02-19 08:05:41 +00:00
|
|
|
}) : [];
|
2011-12-19 21:12:23 +00:00
|
|
|
options.censored = canPlayVideo ? []
|
|
|
|
: canPlayClips ? (
|
|
|
|
options.subtitles.length
|
2012-05-24 08:22:56 +00:00
|
|
|
? options.subtitles.map(function(subtitle, i) {
|
|
|
|
return {
|
|
|
|
'in': i == 0 ? 0 : options.subtitles[i - 1].out,
|
|
|
|
out: subtitle['in']
|
|
|
|
};
|
|
|
|
}).concat(
|
2011-12-19 21:12:23 +00:00
|
|
|
[{'in': Ox.last(options.subtitles).out, out: data.duration}]
|
2012-04-19 06:51:32 +00:00
|
|
|
).filter(function(censored) {
|
|
|
|
// don't include gaps shorter than one second
|
|
|
|
return censored.out - censored['in'] >= 1;
|
|
|
|
})
|
2011-12-19 21:12:23 +00:00
|
|
|
: Ox.range(0, data.duration - 5, 60).map(function(position) {
|
|
|
|
return {
|
|
|
|
'in': position + 5,
|
|
|
|
out: Math.min(position + 60, data.duration)
|
|
|
|
};
|
|
|
|
})
|
|
|
|
)
|
|
|
|
: [{'in': 0, out: data.duration}];
|
|
|
|
options.video = {};
|
|
|
|
pandora.site.video.resolutions.forEach(function(resolution) {
|
|
|
|
options.video[resolution] = Ox.range(data.parts).map(function(i) {
|
2012-03-03 13:56:35 +00:00
|
|
|
return pandora.getVideoUrl(data.item || pandora.user.ui.item, resolution, i + 1);
|
2011-12-19 21:12:23 +00:00
|
|
|
});
|
|
|
|
});
|
2012-04-17 06:31:44 +00:00
|
|
|
options.annotations = [];
|
2011-12-20 13:08:30 +00:00
|
|
|
pandora.site.layers.forEach(function(layer, i) {
|
2012-04-17 06:31:44 +00:00
|
|
|
options.annotations[i] = Ox.extend({}, layer, {
|
2012-01-03 20:17:44 +00:00
|
|
|
items: data.layers[layer.id].map(function(annotation) {
|
2012-02-15 17:25:17 +00:00
|
|
|
annotation.duration = Math.abs(annotation.out - annotation['in']);
|
2012-02-08 11:06:20 +00:00
|
|
|
annotation.editable = annotation.editable
|
|
|
|
|| annotation.user == pandora.user.username
|
|
|
|
|| pandora.site.capabilities['canEditAnnotations'][pandora.user.level];
|
2012-01-03 20:17:44 +00:00
|
|
|
return annotation;
|
|
|
|
})
|
|
|
|
});
|
2011-12-20 13:08:30 +00:00
|
|
|
});
|
2011-12-19 21:12:23 +00:00
|
|
|
return options;
|
|
|
|
};
|
|
|
|
|
2011-08-24 06:19:34 +00:00
|
|
|
pandora.getVideoPartsAndPoints = function(durations, points) {
|
|
|
|
var parts = durations.length,
|
|
|
|
offsets = Ox.range(parts).map(function(i) {
|
2012-05-22 13:15:16 +00:00
|
|
|
return Ox.sum(durations.slice(0, i));
|
2011-08-24 06:19:34 +00:00
|
|
|
}),
|
|
|
|
ret = {
|
|
|
|
parts: [],
|
|
|
|
points: []
|
|
|
|
};
|
|
|
|
points.forEach(function(point, i) {
|
|
|
|
Ox.loop(parts - 1, -1, -1, function(i) {
|
|
|
|
if (offsets[i] <= point) {
|
|
|
|
ret.parts[i] = i;
|
2012-07-04 11:40:37 +00:00
|
|
|
return false;
|
2011-08-24 06:19:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
ret.parts = Ox.unique(ret.parts);
|
|
|
|
ret.points = points.map(function(point) {
|
|
|
|
return point - offsets[ret.parts[0]];
|
|
|
|
});
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
2011-11-07 19:55:39 +00:00
|
|
|
pandora.hasDialogOrScreen = function() {
|
|
|
|
return $('.OxDialog:visible').length
|
|
|
|
|| $('.OxFullscreen').length
|
|
|
|
|| $('.OxScreen').length;
|
|
|
|
};
|
|
|
|
|
2012-01-15 15:05:37 +00:00
|
|
|
pandora.hasEventsLayer = function() {
|
|
|
|
return pandora.site.layers.some(function(layer) {
|
|
|
|
return layer.type == 'event';
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2011-11-07 19:55:39 +00:00
|
|
|
pandora.hasFocusedInput = function() {
|
|
|
|
var focused = Ox.Focus.focused();
|
|
|
|
return focused && Ox.UI.elements[focused].is('.OxInput');
|
|
|
|
};
|
2011-11-02 20:57:49 +00:00
|
|
|
|
2012-01-15 15:05:37 +00:00
|
|
|
pandora.hasPlacesLayer = function() {
|
|
|
|
return pandora.site.layers.some(function(layer) {
|
|
|
|
return layer.type == 'place';
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2011-09-22 03:20:55 +00:00
|
|
|
pandora.isClipView = function(view, item) {
|
2011-09-23 10:44:54 +00:00
|
|
|
if (arguments.length == 0) {
|
|
|
|
item = pandora.user.ui.item;
|
|
|
|
view = !item ? pandora.user.ui.listView : pandora.user.ui.itemView;
|
2011-10-13 10:39:22 +00:00
|
|
|
} else if (arguments.length == 1) {
|
|
|
|
item = pandora.user.ui.item;
|
2011-09-23 10:44:54 +00:00
|
|
|
}
|
2011-09-22 03:20:55 +00:00
|
|
|
return (
|
|
|
|
!item ? ['calendar', 'clip', 'map'] : ['calendar', 'clips', 'map']
|
|
|
|
).indexOf(view) > -1;
|
2011-09-17 21:04:42 +00:00
|
|
|
};
|
|
|
|
|
2013-02-21 14:47:28 +00:00
|
|
|
pandora.isEmbedURL = function(url) {
|
|
|
|
var hash = Ox.parseURL(url).hash;
|
|
|
|
return hash.substr(0, 2) == '#?'
|
2013-02-21 16:06:49 +00:00
|
|
|
&& Ox.unserialize(hash.substr(2), true).embed === true
|
2013-02-21 14:47:28 +00:00
|
|
|
};
|
|
|
|
|
2012-06-30 11:55:15 +00:00
|
|
|
pandora.logEvent = function(data, event, element) {
|
|
|
|
var element = this,
|
|
|
|
handlers = self.eventHandlers ? self.eventHandlers[event] : [];
|
|
|
|
if (!Ox.contains([
|
|
|
|
'mousedown', 'mouserepeat', 'anyclick', 'singleclick', 'doubleclick',
|
|
|
|
'dragstart', 'drag', 'dragenter', 'dragleave', 'dragpause', 'dragend',
|
|
|
|
'draganddropstart', 'draganddrop', 'draganddropenter', 'draganddropleave', 'draganddropend',
|
|
|
|
'playing', 'position', 'progress', 'request'
|
2012-06-30 16:13:20 +00:00
|
|
|
], event) && !Ox.startsWith(event, 'pandora_')) {
|
2012-06-30 11:55:15 +00:00
|
|
|
try {
|
|
|
|
data = JSON.stringify(data)
|
|
|
|
} catch(e) {}
|
|
|
|
Ox.print(
|
|
|
|
'EVENT',
|
|
|
|
element.oxid,
|
|
|
|
'"' + element[0].className.split(' ').filter(function(className) {
|
|
|
|
return /^Ox/.test(className);
|
|
|
|
}).map(function(className) {
|
|
|
|
return className.replace(/^Ox/, '');
|
|
|
|
}).join(' ') + '"',
|
|
|
|
event,
|
|
|
|
data,
|
|
|
|
handlers.length,
|
|
|
|
handlers.map(function(handler) {
|
|
|
|
return handler.toString().split('\n').shift();
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-20 04:52:29 +00:00
|
|
|
pandora.normalizeHashQuery = function(state) {
|
|
|
|
var embedKeys = [
|
|
|
|
'annotationsFont', 'annotationsRange', 'annotationsSort',
|
2013-02-20 08:57:12 +00:00
|
|
|
'embed',
|
2013-02-20 04:52:29 +00:00
|
|
|
'ignoreRights', 'invertHighlight',
|
2013-02-20 08:57:12 +00:00
|
|
|
'matchRatio',
|
2013-02-20 04:52:29 +00:00
|
|
|
'paused', 'playInToOut',
|
|
|
|
'showAnnotations', 'showCloseButton', 'showLayers', 'showTimeline',
|
2013-02-21 07:02:37 +00:00
|
|
|
'timeline', 'title'
|
2013-02-20 04:52:29 +00:00
|
|
|
],
|
2013-02-20 05:22:37 +00:00
|
|
|
isEmbed = state.hash && state.hash.query
|
|
|
|
&& Ox.indexOf(state.hash.query, function(condition) {
|
|
|
|
return Ox.isEqual(condition, {key: 'embed', value: true});
|
|
|
|
}) > -1,
|
2013-02-20 04:52:29 +00:00
|
|
|
newState = Ox.clone(state, true),
|
|
|
|
removeKeys = [];
|
|
|
|
if (state.hash && state.hash.anchor) {
|
|
|
|
if (!state.page) {
|
|
|
|
delete newState.hash.anchor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (state.hash && state.hash.query) {
|
|
|
|
if (isEmbed) {
|
|
|
|
state.hash.query.forEach(function(condition) {
|
|
|
|
if (!Ox.contains(embedKeys, condition.key)) {
|
|
|
|
removeKeys.push(condition.key);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
state.hash.query.forEach(function(condition) {
|
|
|
|
var key = condition.key.split('.')[0];
|
|
|
|
if (pandora.site.user.ui[key] === void 0) {
|
|
|
|
removeKeys.push(condition.key);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
newState.hash.query = newState.hash.query.filter(function(condition) {
|
|
|
|
return !Ox.contains(removeKeys, condition.key);
|
|
|
|
});
|
2013-02-20 04:59:54 +00:00
|
|
|
if (Ox.isEmpty(newState.hash.query)) {
|
|
|
|
delete newState.hash.query;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Ox.isEmpty(newState.hash)) {
|
|
|
|
delete newState.hash;
|
2013-02-20 04:52:29 +00:00
|
|
|
}
|
|
|
|
return newState;
|
|
|
|
};
|
|
|
|
|
2011-08-24 21:04:13 +00:00
|
|
|
pandora.signin = function(data) {
|
2012-06-30 20:07:43 +00:00
|
|
|
// fixme: this is still voodoo
|
|
|
|
pandora.user = Ox.extend(data.user, {
|
2012-03-09 20:19:49 +00:00
|
|
|
sectionElement: 'buttons',
|
|
|
|
videoFormat: Ox.UI.getVideoFormat(pandora.site.video.formats)
|
|
|
|
});
|
2012-06-30 21:18:30 +00:00
|
|
|
pandora.user.ui._list = pandora.getListState(pandora.user.ui.find);
|
|
|
|
pandora.user.ui._filterState = pandora.getFilterState(pandora.user.ui.find);
|
|
|
|
pandora.user.ui._findState = pandora.getFindState(pandora.user.ui.find);
|
2012-06-30 20:07:43 +00:00
|
|
|
pandora.site.sortKeys = pandora.getSortKeys();
|
|
|
|
pandora.URL.init();
|
2012-06-30 21:18:30 +00:00
|
|
|
pandora.URL.update();
|
2011-06-06 15:48:11 +00:00
|
|
|
Ox.Theme(pandora.user.ui.theme);
|
2011-10-22 10:18:57 +00:00
|
|
|
Ox.Request.clearCache();
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.appPanel.reload();
|
2011-06-16 20:00:10 +00:00
|
|
|
};
|
2011-05-25 19:42:45 +00:00
|
|
|
|
2011-08-24 21:04:13 +00:00
|
|
|
pandora.signout = function(data) {
|
2012-06-30 20:07:43 +00:00
|
|
|
// fixme: this is still voodoo
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.user = data.user;
|
2012-06-30 21:18:30 +00:00
|
|
|
pandora.user.ui._list = pandora.getListState(pandora.user.ui.find);
|
|
|
|
pandora.user.ui._filterState = pandora.getFilterState(pandora.user.ui.find);
|
|
|
|
pandora.user.ui._findState = pandora.getFindState(pandora.user.ui.find);
|
2012-06-30 20:07:43 +00:00
|
|
|
pandora.site.sortKeys = pandora.getSortKeys();
|
|
|
|
pandora.URL.init();
|
2012-06-30 21:18:30 +00:00
|
|
|
pandora.URL.update();
|
|
|
|
Ox.Theme(pandora.user.ui.theme);
|
2011-10-22 10:18:57 +00:00
|
|
|
Ox.Request.clearCache();
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.appPanel.reload();
|
2011-06-16 20:00:10 +00:00
|
|
|
};
|
2011-05-25 19:42:45 +00:00
|
|
|
|
|
|
|
pandora.reloadList = function() {
|
2011-11-04 15:54:42 +00:00
|
|
|
Ox.Log('', 'reloadList')
|
2011-05-25 19:42:45 +00:00
|
|
|
var listData = pandora.getListData();
|
|
|
|
Ox.Request.clearCache(); // fixme: remove
|
2011-11-06 08:28:10 +00:00
|
|
|
pandora.$ui.filters.forEach(function($filter) {
|
|
|
|
$filter.reloadList();
|
2011-05-25 19:42:45 +00:00
|
|
|
});
|
2011-09-27 14:14:40 +00:00
|
|
|
pandora.$ui.list
|
|
|
|
.bindEvent({
|
2011-09-17 17:40:15 +00:00
|
|
|
init: function(data) {
|
2011-09-04 11:31:05 +00:00
|
|
|
// fixme: this will not work for lists in the favorites folder
|
|
|
|
// (but then it's also unlikely they'll have to be reloaded)
|
|
|
|
var folder = listData.status != 'featured' ? 'personal' : 'featured';
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.folderList[folder].value(listData.id, 'items', data.items);
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.bindEventOnce({
|
2011-09-17 17:40:15 +00:00
|
|
|
load: function(data) {
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.list.gainFocus();
|
2011-10-18 02:50:45 +00:00
|
|
|
// fixme: what is this?
|
2011-10-29 12:31:16 +00:00
|
|
|
// if (data) pandora.$ui.list.options({selected: [data.items]});
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.reloadList();
|
2011-06-16 20:00:10 +00:00
|
|
|
};
|
2011-05-25 19:42:45 +00:00
|
|
|
|
2011-11-06 11:51:04 +00:00
|
|
|
pandora.renameList = function(oldId, newId, newName, folder) {
|
|
|
|
folder = folder || pandora.getListData(oldId).folder;
|
|
|
|
pandora.$ui.folderList[folder].value(oldId, 'name', newName);
|
|
|
|
pandora.$ui.folderList[folder].value(oldId, 'id', newId);
|
2013-02-16 01:20:40 +00:00
|
|
|
if (pandora.user.ui.section == 'items') {
|
|
|
|
pandora.$ui.toolbar.updateListName(newId);
|
|
|
|
pandora.UI.set({
|
|
|
|
find: {
|
|
|
|
conditions: [{key: 'list', value: newId, operator: '=='}],
|
|
|
|
operator: '&'
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
} else {
|
|
|
|
pandora.UI.set(pandora.user.ui.section.slice(0, -1), newId);
|
|
|
|
}
|
2011-11-06 11:51:04 +00:00
|
|
|
};
|
|
|
|
|
2011-11-06 08:28:10 +00:00
|
|
|
pandora.resizeFilters = function(width) {
|
|
|
|
pandora.user.ui.filterSizes = pandora.getFilterSizes();
|
2013-02-16 01:20:40 +00:00
|
|
|
pandora.$ui.browser && pandora.$ui.browser
|
2011-11-06 08:28:10 +00:00
|
|
|
.size(0, pandora.user.ui.filterSizes[0])
|
|
|
|
.size(2, pandora.user.ui.filterSizes[4]);
|
2013-02-16 01:20:40 +00:00
|
|
|
pandora.$ui.filtersInnerPanel && pandora.$ui.filtersInnerPanel
|
2011-11-06 08:28:10 +00:00
|
|
|
.size(0, pandora.user.ui.filterSizes[1])
|
|
|
|
.size(2, pandora.user.ui.filterSizes[3]);
|
2013-02-16 01:20:40 +00:00
|
|
|
pandora.$ui.filters && pandora.$ui.filters.forEach(function($list, i) {
|
2012-12-23 02:33:20 +00:00
|
|
|
$list.resizeColumn('name', pandora.user.ui.filterSizes[i] - 44 - Ox.UI.SCROLLBAR_SIZE);
|
2013-02-19 19:57:59 +00:00
|
|
|
if (pandora.site.flags) {
|
2012-12-23 02:33:20 +00:00
|
|
|
$list.find('.flagname').css({width: pandora.user.ui.filterSizes[i] - 68 - Ox.UI.SCROLLBAR_SIZE})
|
2011-11-03 12:58:22 +00:00
|
|
|
}
|
2011-05-25 19:42:45 +00:00
|
|
|
});
|
2011-06-16 20:00:10 +00:00
|
|
|
};
|
2011-05-25 19:42:45 +00:00
|
|
|
|
|
|
|
pandora.resizeFolders = function() {
|
|
|
|
var width = pandora.getFoldersWidth(),
|
2013-02-16 01:20:40 +00:00
|
|
|
columnWidth = {},
|
|
|
|
sectionWidth = pandora.user.ui.section == 'items'? 96 : 32;
|
|
|
|
columnWidth = {user: parseInt((width - (sectionWidth)) * 0.4)};
|
|
|
|
columnWidth.name = (width - sectionWidth) - columnWidth.user;
|
2011-11-04 15:54:42 +00:00
|
|
|
Ox.Log('', 'RESIZE FOLDERS', width);
|
2011-11-06 18:36:22 +00:00
|
|
|
pandora.$ui.allItems.resizeElement(width - 104);
|
2011-09-05 02:20:38 +00:00
|
|
|
Ox.forEach(pandora.$ui.folderList, function($list, id) {
|
2012-01-04 08:10:47 +00:00
|
|
|
var pos = Ox.getIndexById(pandora.site.sectionFolders[pandora.user.ui.section], id);
|
2011-09-27 14:14:40 +00:00
|
|
|
pandora.$ui.folder[pos].css({width: width + 'px'});
|
2011-05-25 19:42:45 +00:00
|
|
|
$list.css({width: width + 'px'});
|
2013-02-16 01:20:40 +00:00
|
|
|
if (pandora.site.sectionFolders[pandora.user.ui.section][pos].showBrowser) {
|
|
|
|
pandora.$ui.findListInput[id].options({
|
|
|
|
width: width - 24
|
|
|
|
});
|
|
|
|
$list.resizeColumn('user', columnWidth.user)
|
|
|
|
.resizeColumn('name', columnWidth.name);
|
|
|
|
} else {
|
|
|
|
$list.resizeColumn(id == 'favorite' ? 'id' : 'name', width - 96);
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
2011-06-06 15:48:11 +00:00
|
|
|
if (!pandora.user.ui.showFolder[pandora.user.ui.section][id]) {
|
2012-05-28 15:52:11 +00:00
|
|
|
pandora.$ui.folder[pos].updatePanel();
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
|
|
|
});
|
2011-06-16 20:00:10 +00:00
|
|
|
};
|
2011-05-25 19:42:45 +00:00
|
|
|
|
2011-10-22 10:18:57 +00:00
|
|
|
pandora.resizeWindow = function() {
|
2011-11-09 17:37:44 +00:00
|
|
|
// FIXME: a lot of this throws errors on load
|
2012-04-19 14:34:15 +00:00
|
|
|
pandora.$ui.leftPanel && pandora.$ui.leftPanel.size(2, pandora.getInfoHeight(true));
|
2011-10-22 10:18:57 +00:00
|
|
|
pandora.resizeFolders();
|
2013-02-16 01:20:40 +00:00
|
|
|
if (pandora.user.ui.section == 'item') {
|
|
|
|
if (!pandora.user.ui.item) {
|
|
|
|
pandora.resizeFilters(pandora.$ui.rightPanel.width());
|
|
|
|
if (pandora.user.ui.listView == 'clips') {
|
|
|
|
var clipsItems = pandora.getClipsItems(),
|
|
|
|
previousClipsItems = pandora.getClipsItems(pandora.$ui.list.options('width'));
|
|
|
|
pandora.$ui.list.options({
|
|
|
|
width: window.innerWidth
|
|
|
|
- pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 1
|
|
|
|
- Ox.UI.SCROLLBAR_SIZE
|
|
|
|
});
|
|
|
|
if (clipsItems != previousClipsItems) {
|
|
|
|
Ox.Request.clearCache(); // fixme
|
|
|
|
pandora.$ui.list.reloadList(true);
|
|
|
|
}
|
|
|
|
} else if (pandora.user.ui.listView == 'timelines') {
|
|
|
|
pandora.$ui.list.options({
|
|
|
|
width: window.innerWidth
|
|
|
|
- pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 1
|
|
|
|
- Ox.UI.SCROLLBAR_SIZE
|
|
|
|
});
|
|
|
|
} else if (pandora.user.ui.listView == 'map') {
|
|
|
|
pandora.$ui.map && pandora.$ui.map.resizeMap();
|
|
|
|
} else if (pandora.user.ui.listView == 'calendar') {
|
|
|
|
pandora.$ui.calendar && pandora.$ui.calendar.resizeCalendar();
|
|
|
|
} else {
|
|
|
|
pandora.$ui.list && pandora.$ui.list.size();
|
2011-10-22 10:18:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-02-16 01:20:40 +00:00
|
|
|
pandora.$ui.browser.scrollToSelection();
|
|
|
|
if (pandora.user.ui.itemView == 'info') {
|
|
|
|
pandora.$ui.item.resize();
|
|
|
|
} else if (pandora.user.ui.itemView == 'clips') {
|
|
|
|
pandora.$ui.clipList.size();
|
|
|
|
} else if (pandora.user.ui.itemView == 'timeline') {
|
|
|
|
pandora.$ui.timeline && pandora.$ui.timeline.options({
|
|
|
|
// fixme: duplicated
|
|
|
|
height: pandora.$ui.contentPanel.size(1),
|
|
|
|
width: pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1
|
|
|
|
});
|
|
|
|
} else if (pandora.user.ui.itemView == 'player') {
|
|
|
|
pandora.$ui.player && pandora.$ui.player.options({
|
|
|
|
// fixme: duplicated
|
|
|
|
height: pandora.$ui.contentPanel.size(1),
|
|
|
|
width: pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1
|
|
|
|
});
|
|
|
|
} else if (pandora.user.ui.itemView == 'editor') {
|
|
|
|
pandora.$ui.editor && pandora.$ui.editor.options({
|
|
|
|
// fixme: duplicated
|
|
|
|
height: pandora.$ui.contentPanel.size(1),
|
|
|
|
width: pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1
|
|
|
|
});
|
|
|
|
} else if (pandora.user.ui.itemView == 'map') {
|
|
|
|
pandora.$ui.map.resizeMap();
|
|
|
|
} else if (pandora.user.ui.itemView == 'calendar') {
|
|
|
|
pandora.$ui.calendar.resizeCalendar();
|
|
|
|
}
|
2011-10-22 10:18:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-05-25 19:42:45 +00:00
|
|
|
pandora.selectList = function() {
|
2013-02-16 01:20:40 +00:00
|
|
|
if (pandora.user.ui.section == 'items') {
|
|
|
|
if (pandora.user.ui._list) {
|
|
|
|
pandora.api.findLists({
|
|
|
|
keys: ['status', 'user'],
|
|
|
|
query: {
|
|
|
|
conditions: [{key: 'id', value: pandora.user.ui._list, operator: '=='}],
|
|
|
|
operator: ''
|
|
|
|
},
|
|
|
|
range: [0, 1]
|
|
|
|
}, function(result) {
|
|
|
|
var folder, list;
|
|
|
|
if (result.data.items.length) {
|
|
|
|
list = result.data.items[0];
|
|
|
|
folder = list.status == 'featured' ? 'featured' : (
|
|
|
|
list.user == pandora.user.username ? 'personal' : 'favorite'
|
|
|
|
);
|
|
|
|
pandora.$ui.folderList[folder]
|
|
|
|
.options({selected: [pandora.user.ui._list]});
|
|
|
|
if (!pandora.hasDialogOrScreen() && !pandora.hasFocusedInput()) {
|
|
|
|
pandora.$ui.folderList[folder].gainFocus();
|
|
|
|
}
|
2011-11-07 19:55:39 +00:00
|
|
|
}
|
2013-02-16 01:20:40 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var id = pandora.user.ui[pandora.user.ui.section.slice(0,-1)];
|
|
|
|
if (id) {
|
|
|
|
pandora.api.getText({id: id}, function(result) {
|
|
|
|
var folder;
|
|
|
|
if (result.data.id) {
|
|
|
|
folder = result.data.status == 'featured' ? 'featured' : (
|
|
|
|
result.data.user == pandora.user.username ? 'personal' : 'favorite'
|
|
|
|
);
|
|
|
|
pandora.$ui.folderList[folder].options({selected: [id]});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
2011-06-16 20:00:10 +00:00
|
|
|
};
|
2011-05-25 19:42:45 +00:00
|
|
|
|
2012-03-17 00:15:06 +00:00
|
|
|
pandora.beforeunloadWindow = function() {
|
|
|
|
if (pandora.firefogg)
|
|
|
|
return "Encoding is currently running\nDo you want to leave this page?";
|
2012-05-29 15:19:18 +00:00
|
|
|
//prevent error dialogs on unload
|
|
|
|
pandora.isUnloading = true;
|
2012-03-17 00:15:06 +00:00
|
|
|
}
|
|
|
|
|
2011-10-22 10:18:57 +00:00
|
|
|
pandora.unloadWindow = function() {
|
2011-11-06 11:51:04 +00:00
|
|
|
/*
|
2011-10-22 10:18:57 +00:00
|
|
|
// fixme: ajax request has to have async set to false for this to work
|
|
|
|
pandora.user.ui.section == 'items'
|
|
|
|
&& pandora.user.ui.item
|
2012-04-17 14:54:04 +00:00
|
|
|
&& ['video', 'timeline'].indexOf(pandora.user.ui.itemView) > -1
|
2011-10-22 10:18:57 +00:00
|
|
|
&& pandora.UI.set(
|
|
|
|
'videoPosition.' + pandora.user.ui.item,
|
2012-04-17 14:54:04 +00:00
|
|
|
pandora.$ui[
|
|
|
|
pandora.user.ui.itemView == 'video' ? 'player' : 'editor'
|
|
|
|
].options('position')
|
2011-10-22 10:18:57 +00:00
|
|
|
);
|
2011-11-06 11:51:04 +00:00
|
|
|
*/
|
2011-10-22 10:18:57 +00:00
|
|
|
};
|
|
|
|
|
2013-02-11 11:15:06 +00:00
|
|
|
pandora.updateItemContext = function() {
|
2013-02-11 12:18:49 +00:00
|
|
|
Ox.Request.clearCache('find');
|
2013-02-11 11:15:06 +00:00
|
|
|
if (!Ox.isEqual(pandora.user.ui.find, pandora.site.user.ui.find)) {
|
|
|
|
pandora.api.find({
|
|
|
|
query: pandora.user.ui.find,
|
|
|
|
positions: [pandora.user.ui.item],
|
|
|
|
sort: pandora.user.ui.sort
|
|
|
|
}, function(result) {
|
|
|
|
if (result.data.positions[pandora.user.ui.item] === void 0) {
|
|
|
|
pandora.stayInItemView = true;
|
|
|
|
pandora.UI.set({find: pandora.site.user.ui.find});
|
|
|
|
pandora.$ui.contentPanel.replaceElement(0, pandora.$ui.browser = pandora.ui.browser());
|
2013-02-11 12:18:49 +00:00
|
|
|
} else {
|
|
|
|
pandora.$ui.browser.reloadList();
|
2013-02-11 11:15:06 +00:00
|
|
|
}
|
|
|
|
});
|
2013-02-11 12:18:49 +00:00
|
|
|
} else {
|
|
|
|
pandora.$ui.browser.reloadList();
|
2013-02-11 11:15:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-27 14:14:40 +00:00
|
|
|
(function() {
|
|
|
|
|
2011-11-06 08:28:10 +00:00
|
|
|
// Note: getFindState has to run after getListState and getFilterState
|
2011-09-27 14:14:40 +00:00
|
|
|
|
|
|
|
function everyCondition(conditions, key, operator) {
|
|
|
|
// If every condition has the given key and operator
|
|
|
|
// (excluding conditions where all subconditions match)
|
|
|
|
// returns true, otherwise false
|
|
|
|
return Ox.every(conditions, function(condition) {
|
|
|
|
return condition.key == key && condition.operator == operator;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function oneCondition(conditions, key, operator, includeSubconditions) {
|
|
|
|
// If exactly one condition has the given key and operator
|
|
|
|
// (including or excluding conditions where all subconditions match)
|
|
|
|
// returns the corresponding index, otherwise returns -1
|
2012-05-22 15:07:34 +00:00
|
|
|
var indices = Ox.indicesOf(conditions, function(condition) {
|
2011-09-27 14:14:40 +00:00
|
|
|
return (
|
|
|
|
condition.conditions
|
|
|
|
? includeSubconditions && everyCondition(condition.conditions, key, operator)
|
|
|
|
: condition.key == key && condition.operator == operator
|
2012-05-22 15:07:34 +00:00
|
|
|
);
|
2011-09-27 14:14:40 +00:00
|
|
|
});
|
|
|
|
return indices.length == 1 ? indices[0] : -1;
|
|
|
|
}
|
|
|
|
|
2011-11-06 08:28:10 +00:00
|
|
|
pandora.getFilterState = function(find) {
|
|
|
|
// A filter is selected if exactly one condition in an & query or every
|
|
|
|
// condition in an | query has the filter id as key and "==" as operator
|
|
|
|
return pandora.user.ui.filters.map(function(filter) {
|
2011-09-27 14:14:40 +00:00
|
|
|
// FIXME: cant index be an empty array, instead of -1?
|
2011-11-06 08:28:10 +00:00
|
|
|
var key = filter.id,
|
2011-09-27 14:14:40 +00:00
|
|
|
state = {index: -1, find: Ox.clone(find, true), selected: []};
|
|
|
|
if (find.operator == '&') {
|
|
|
|
// include conditions where all subconditions match
|
|
|
|
state.index = oneCondition(find.conditions, key, '==', true);
|
|
|
|
if (state.index > -1) {
|
|
|
|
state.selected = find.conditions[state.index].conditions
|
|
|
|
? find.conditions[state.index].conditions.map(function(condition) {
|
|
|
|
return condition.value;
|
|
|
|
})
|
|
|
|
: [find.conditions[state.index].value];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (everyCondition(find.conditions, key, '==')) {
|
|
|
|
state.index = Ox.range(find.conditions.length);
|
|
|
|
state.selected = find.conditions.map(function(condition) {
|
|
|
|
return condition.value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (state.selected.length) {
|
|
|
|
if (Ox.isArray(state.index)) {
|
2011-11-06 08:28:10 +00:00
|
|
|
// every condition in an | query matches this filter
|
2011-09-27 14:14:40 +00:00
|
|
|
state.find = {conditions: [], operator: ''};
|
|
|
|
} else {
|
2011-11-06 08:28:10 +00:00
|
|
|
// one condition in an & query matches this filter
|
2011-09-27 14:14:40 +00:00
|
|
|
state.find.conditions.splice(state.index, 1);
|
2011-09-27 22:12:37 +00:00
|
|
|
if (
|
|
|
|
state.find.conditions.length == 1
|
|
|
|
&& state.find.conditions[0].conditions
|
|
|
|
) {
|
|
|
|
// unwrap single remaining bracketed query
|
|
|
|
state.find = {
|
|
|
|
conditions: state.find.conditions[0].conditions,
|
|
|
|
operator: state.find.conditions[0].operator
|
|
|
|
};
|
2011-09-27 14:14:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-11-06 08:28:10 +00:00
|
|
|
pandora.getFindState = function(find) {
|
|
|
|
// The find element is populated if exactly one condition in an & query
|
|
|
|
// has a findKey as key and "=" as operator (and all other conditions
|
|
|
|
// are either list or filters), or if all conditions in an | query have
|
|
|
|
// the same filter id as key and "==" as operator
|
2012-02-16 11:34:46 +00:00
|
|
|
Ox.Log('Find', 'getFindState', find)
|
2011-11-06 08:28:10 +00:00
|
|
|
// FIXME: this is still incorrect when you select a lot of filter items
|
|
|
|
// and reload the page (will be advanced)
|
|
|
|
var conditions, indices, state = {index: -1, key: '*', value: ''};
|
|
|
|
if (find.operator == '&') {
|
|
|
|
// number of conditions that are not list or filters
|
|
|
|
conditions = find.conditions.length
|
|
|
|
- !!pandora.user.ui._list
|
|
|
|
- pandora.user.ui._filterState.filter(function(filter) {
|
|
|
|
return filter.index > -1;
|
|
|
|
}).length;
|
|
|
|
// indices of non-advanced find queries
|
2012-05-22 16:24:07 +00:00
|
|
|
indices = pandora.site.findKeys.map(function(findKey) {
|
|
|
|
return oneCondition(find.conditions, findKey.id, '=');
|
2012-05-22 16:14:34 +00:00
|
|
|
}).filter(function(index) {
|
2012-05-22 15:07:34 +00:00
|
|
|
return index > -1;
|
2011-11-06 08:28:10 +00:00
|
|
|
});
|
|
|
|
state = conditions == 1 && indices.length == 1 ? {
|
|
|
|
index: indices[0],
|
|
|
|
key: find.conditions[indices[0]].key,
|
|
|
|
value: decodeURIComponent(find.conditions[indices[0]].value)
|
|
|
|
} : {
|
|
|
|
index: -1,
|
|
|
|
key: conditions == 0 && indices.length == 0 ? '*' : 'advanced',
|
|
|
|
value: ''
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
state = {
|
|
|
|
index: -1,
|
|
|
|
key: 'advanced',
|
|
|
|
value: ''
|
|
|
|
};
|
|
|
|
Ox.forEach(pandora.user.ui.filters, function(key) {
|
|
|
|
if (everyCondition(find.conditions, key, '==')) {
|
|
|
|
state.key = '*';
|
2012-07-04 11:40:37 +00:00
|
|
|
return false;
|
2011-11-06 08:28:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
pandora.getListState = function(find) {
|
2011-09-27 14:14:40 +00:00
|
|
|
// A list is selected if exactly one condition in an & query has "list"
|
|
|
|
// as key and "==" as operator
|
2011-09-27 22:12:37 +00:00
|
|
|
var index, state = '';
|
2011-09-27 14:14:40 +00:00
|
|
|
if (find.operator == '&') {
|
|
|
|
index = oneCondition(find.conditions, 'list', '==');
|
|
|
|
if (index > -1) {
|
|
|
|
state = find.conditions[index].value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
};
|
|
|
|
|
2011-09-29 17:25:04 +00:00
|
|
|
}());
|