From b1949b45aaf2188c176dcc35ca2f0a684d2b386d Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 28 Feb 2013 15:43:59 +0000 Subject: [PATCH] add dialog to edit tpdf inline video player urls, hide right panel for now --- static/js/pandora/embedPanel.js | 4 +- static/js/pandora/textPanel.js | 32 ++++++-- static/pdf.js/embeds.js | 126 +++++++++----------------------- 3 files changed, 64 insertions(+), 98 deletions(-) diff --git a/static/js/pandora/embedPanel.js b/static/js/pandora/embedPanel.js index ce207baa..aa822728 100644 --- a/static/js/pandora/embedPanel.js +++ b/static/js/pandora/embedPanel.js @@ -137,7 +137,9 @@ pandora.ui.embedPanel = function() { } }) .bindEvent(function(data, event) { - Ox.$parent.postMessage(event, {}); + if (Ox.contains(['close', 'paused'], event)) { + Ox.$parent.postMessage(event, data); + } }); $controls = Ox.Element(); diff --git a/static/js/pandora/textPanel.js b/static/js/pandora/textPanel.js index f46df6be..7aa46b47 100644 --- a/static/js/pandora/textPanel.js +++ b/static/js/pandora/textPanel.js @@ -105,8 +105,9 @@ pandora.ui.textPanel = function() { }, { element: pandora.$ui.textEmbed = pandora.ui.textEmbed(), - size: pandora.user.ui.embedSize, - resizable: true, + //fixme: at some point pdf will also have a sidebar + size: text.type == 'html' ? pandora.user.ui.embedSize : 0, + resizable: text.type == 'html', resize: [192, 256, 320, 384, 448, 512] } ], @@ -338,10 +339,29 @@ pandora.ui.textPDF = function(text) { }) .onMessage(function(event, data) { if(event == 'edit') { - Ox.Dialog({ - title: 'edit', - content: Ox.Element().html('test') - }).open() + console.log('existing url?', data); + pandora.ui.insertEmbedDialog(data.src, function(url) { + data.src = url; + var embed = text.embeds.filter(function(embed) { + return embed.id == data.id + && embed.type == data.type + && embed.page == data.page; + })[0]; + if(embed) { + embed.src = url; + + } else { + text.embeds.push(data); + //fixme sort embeds by page/id + } + console.log('saving', text.embeds); + pandora.api.editText({ + id: text.id, + embeds: text.embeds + }, function(result) { + $iframe.postMessage('update', data); + }); + }).open(); } }) .appendTo(that); diff --git a/static/pdf.js/embeds.js b/static/pdf.js/embeds.js index 39bca21f..951db87f 100644 --- a/static/pdf.js/embeds.js +++ b/static/pdf.js/embeds.js @@ -1,44 +1,3 @@ -Ox.Message.bind(function(event, data, oxid) { - if (Ox.isUndefined(oxid)) { - //process messages here - } -}); -Ox.$parent = { - postMessage: function(event, message) { - Ox.Message.post(event, message); - return this; - }, - onMessage: function() { - var callback; - if (Ox.isObject(arguments[0])) { - Ox.forEach(arguments[0], function(callback, event) { - Ox.Message.bind(function(evt, data, oxid) { - if (Ox.isUndefined(oxid) && event == evt) { - callback(data); - } - }); - }); - } else { - callback = arguments[0]; - Ox.Message.bind(function(event, data, oxid) { - Ox.isUndefined(oxid) && callback(event, data); - }); - } - return this; - } -}; - -function getEmbedURL(id, videoURL) { - var parsed = Ox.parseURL(videoURL), - parts = parsed.pathname.split('/'), - item = parts[1], - points = parts[parts.length - 1].split(','), - outPoint = points.pop(), - inPoint = points.pop(); - return parsed.protocol + '//' + parsed.host + '/' + item + '/embed?view=player&id=' + id - + '&in=' + inPoint + '&out=' + outPoint - + '&paused=false&showCloseButton=true'; -} function getVideoOverlay(page) { var links = embeds.filter(function(embed) { return embed.page == page && embed.type =='inline'; @@ -87,34 +46,49 @@ function getVideoOverlay(page) { enableVideoUI(); } this.div.appendChild($interface[0]); + Ox.Message.bind(function(event, data, oxid) { + if (event == 'update') { + if(Ox.isUndefined(oxid) + && video + && data.id == video.id + && data.page == video.page) { + video.src = data.src; + video.src !== '' ? enableVideoUI() : disableVideoUI(); + } + } + }); } function play(e) { e.preventDefault(); e.stopPropagation(); - var videoId = 'video' + page + id, + var videoId = 'video' + page + id + Ox.uid(), $iframe = Ox.$('