userscripts

This commit is contained in:
j 2014-04-12 13:33:28 +02:00
commit 1f843cf433
3 changed files with 174 additions and 0 deletions

6
README Normal file
View file

@ -0,0 +1,6 @@
A collection of pan.do/ra users scripts
playlist.js - tuns pan.do/ra into an automated tour
goto_item.js - add textare into menu extras to enter item id

60
goto_item.js Normal file
View file

@ -0,0 +1,60 @@
(function() {
var css = {
margin: '2px',
},
reload = pandora.$ui.appPanel.reload,
timeout,
$item = Ox.Editable({
placeholder: 'No Item',
editable: true,
value: pandora.user.ui.section == 'items' ? pandora.user.ui.item : ''
}).css(css).bindEvent({
pandora_item: update,
pandora_section: update,
submit: function(data) {
pandora.UI.set({section: 'items', item: data.value});
}
});
load();
function update() {
$item.options({value: pandora.user.ui.section == 'items' ? pandora.user.ui.item : ''});
}
function load() {
pandora.$ui.mainMenu.find('.OxExtras').prepend($item);
pandora.$ui.extraItem = $item;
patchReload();
}
function patchReload() {
pandora.$ui.appPanel.reload = function() {
reload();
load();
}
}
window.missingLocale ={};
Ox._.log(function(k, v) {
if (Ox.isUndefined(v)) {
window.missingLocale[k] = '';
}
});
window.missingLocale.show = function() {
Ox.Dialog({
width: 320,
height: 320,
closeButton: true,
destroyOnClose: true,
content: Ox.Input({
width: 300,
height: 300,
type: 'textarea', value: JSON.stringify(window.missingLocale, null, 4)
})
}).open();
};
}());

108
playlist.js Normal file
View file

@ -0,0 +1,108 @@
//open User->Preferences->Advanced->Run Script on Load and paste this script
(function() {
playlist([
[function() { info('A'); }, 30.000],
[function() { play('B', 3); }, 10],
]);
//helper functions
function playlist(playlist) {
var current = 0;
pandora.$ui.home && pandora.$ui.home.fadeOutScreen();
clearTimeout(pandora.playlist);
next();
function next() {
if(current >= playlist.length) {
window.location.reload();
current = 0;
} else {
playlist[current][0]();
clearTimeout(pandora.playlist);
var duration = playlist[current][1];
if(Ox.isString(duration)) {
duration = Ox.parseDuration(duration);
}
pandora.playlist = setTimeout(next, Math.round(duration * 1000));
current += 1;
}
}
}
function sitePage(page) {
//if there is a player, pause it
pandora.$ui.player && pandora.$ui.player.options('paused', true);
//back to results view
pandora.UI.set({item: ''});
//open about page
pandora.UI.set({page: page});
}
function editor(item, start) {
playItem(item, 'editor', start);
}
function info(item) {
pandora.UI.set({page: ''});
pandora.UI.set({itemView: 'info'});
pandora.UI.set({item: item});
}
function play(item, position, layers) {
playItem(item, 'player', position, layers);
}
function timeline(item, position, layers) {
playItem(item, 'player', position, layers);
}
function playItem(item, view, position, layers) {
showLayers(layers);
position = position || 0;
if(Ox.isString(position)) {
position = Ox.parseDuration(position);
}
pandora.UI.set({page: ''});
pandora.UI.set('videoPoints.' + item, {
'annotation': '',
'in': position,
out: position,
position: position
});
if(item != pandora.user.ui.item || pandora.user.ui.itemView != view) {
delete pandora.$ui[view];
pandora.UI.set({itemView: view});
pandora.UI.set({item: item});
}
startPlayback();
function startPlayback() {
if(pandora.$ui[view]) {
pandora.$ui[view].options({paused: false});
} else {
setTimeout(startPlayback, 500);
}
}
}
function find(query, view) {
view = view || 'grid';
pandora.UI.set({item: '', page: '', listView: view});
pandora.$ui.findInput.value(query);
pandora.UI.set({find: {conditions: [{key: '*', value: query, operator: '='}], operator: '&'}});
}
function showLayers(layers) {
layers = layers || Object.keys(pandora.site.user.ui.showLayers).filter(function(layer) {
return pandora.site.user.ui.showLayers[layer];
});
pandora.UI.set('showLayers', Ox.map(pandora.site.user.ui.showLayers, function(value, layer) {
return layers.indexOf(layer) > -1;
}));
}
function openDocument(id) {
//if there is a player, pause it
pandora.$ui.player && pandora.$ui.player.options('paused', true);
pandora.URL.push('/documents/' + id);
}
function closeDocument() {
pandora.$ui.documentDialog.close();
}
})();