update pdf.js to use new iframe/postMessage api

This commit is contained in:
j 2014-09-23 23:46:03 +02:00
parent 55f84fb7f4
commit ac2f1a550f
3 changed files with 29 additions and 38 deletions

View file

@ -24,8 +24,7 @@ limitations under the License.
<link rel="stylesheet" href="/static/pdf.js/viewer.css"/>
<script type="text/javascript" src="/static/oxjs/build/Ox.js"></script>
<script type="text/javascript" src="/static/oxjs/source/Ox.UI/js/Core/Message.js"></script>
<script type="text/javascript" src="/static/oxjs/build/Ox.js?{{settings.CONFIG.site.version}}"></script>
<script type="text/javascript" src="/static/pdf.js/compatibility.js"></script>

View file

@ -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,23 +75,18 @@ 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) {
Ox.parent.bindMessage('update', function(data) {
if (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 + Ox.uid(),
$iframe = Ox.$('<iframe>')
$iframe = Ox.Element('<iframe>')
.attr({
id: videoId,
src: video.src
@ -96,19 +94,12 @@ function getVideoOverlay(page) {
+ '&showCloseButton=true&fullscreen=false&paused=false',
width: '100%',
height: '100%',
scrolling: 'no',
frameborder: 0
})
.appendTo($interface),
closed = false;
$iframe.postMessage = function(event, data) {
Ox.Message.post($iframe, event, data);
return $iframe;
};
Ox.Message.bind(function(event, data, oxid) {
if(!closed && event == 'loaded') {
$iframe.postMessage('init', {id: videoId});
} else if(event == 'close') {
if(!closed && !Ox.isUndefined(oxid) && videoId == oxid) {
.bindMessage({
close: function(data) {
if(!closed) {
closed = true;
$iframe.remove();
delete $iframe;
@ -116,7 +107,9 @@ function getVideoOverlay(page) {
$editButton.show();
}
}
});
})
.appendTo($interface),
closed = false;
$playButton.hide();
$editButton.hide();
return false;
@ -131,7 +124,7 @@ function getVideoOverlay(page) {
src: '',
type: 'inline'
};
Ox.$parent.postMessage('edit', video);
Ox.parent.postMessage('edit', video);
return false;
}
function enableVideoUI() {

View file

@ -25,7 +25,6 @@ limitations under the License.
<link rel="stylesheet" href="/static/pdf.js/viewer.css"/>
<script type="text/javascript" src="/static/oxjs/build/Ox.js"></script>
<script type="text/javascript" src="/static/oxjs/source/Ox.UI/js/Core/Message.js"></script>
<script type="text/javascript" src="compatibility.js"></script>