From ac2f1a550f3e850d54607b2021536e16970a91ba Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 23 Sep 2014 23:46:03 +0200 Subject: [PATCH] update pdf.js to use new iframe/postMessage api --- pandora/text/templates/pdf/viewer.html | 3 +- static/pdf.js/embeds.js | 63 ++++++++++++-------------- static/pdf.js/index.html | 1 - 3 files changed, 29 insertions(+), 38 deletions(-) diff --git a/pandora/text/templates/pdf/viewer.html b/pandora/text/templates/pdf/viewer.html index edb5b4961..9150cb351 100644 --- a/pandora/text/templates/pdf/viewer.html +++ b/pandora/text/templates/pdf/viewer.html @@ -24,8 +24,7 @@ limitations under the License. - - + diff --git a/static/pdf.js/embeds.js b/static/pdf.js/embeds.js index 95a6b52a4..eb44cf16e 100644 --- a/static/pdf.js/embeds.js +++ b/static/pdf.js/embeds.js @@ -1,27 +1,30 @@ -Ox.load(function() { +Ox.load({ + 'UI': { + loadCSS: false + } +}, function() { var currentPage = PDFView.page; window.addEventListener('pagechange', function (evt) { var page = evt.pageNumber; if (page && page != currentPage) { currentPage = page; - Ox.$parent.postMessage('page', { + Ox.parent.postMessage('page', { page: Math.round(page) }); } }); - Ox.$parent.onMessage(function(event, data, oxid) { - if (event == 'page' && Ox.isUndefined(oxid)) { + Ox.parent.bindMessage({ + page: function(data) { if (data.page != PDFView.page) { PDFView.page = data.page; } - } - if (event == 'pdf' && Ox.isUndefined(oxid)) { + }, + pdf: function(data) { if (PDFView.url != data.pdf) { PDFView.open(data.pdf); } } }); - Ox.$parent.postMessage('init', {}); }); function getVideoOverlay(page) { @@ -72,15 +75,10 @@ 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(); - } + Ox.parent.bindMessage('update', function(data) { + if (video && data.id == video.id && data.page == video.page) { + video.src = data.src; + video.src !== '' ? enableVideoUI() : disableVideoUI(); } }); } @@ -88,7 +86,7 @@ function getVideoOverlay(page) { e.preventDefault(); e.stopPropagation(); var videoId = 'video' + page + id + Ox.uid(), - $iframe = Ox.$('