update pdf.js to use new iframe/postMessage api
This commit is contained in:
parent
55f84fb7f4
commit
ac2f1a550f
3 changed files with 29 additions and 38 deletions
|
@ -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>
|
||||
|
||||
|
||||
|
|
|
@ -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.$('<iframe>')
|
||||
$iframe = Ox.Element('<iframe>')
|
||||
.attr({
|
||||
id: videoId,
|
||||
src: video.src
|
||||
|
@ -96,27 +94,22 @@ function getVideoOverlay(page) {
|
|||
+ '&showCloseButton=true&fullscreen=false&paused=false',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
scrolling: 'no',
|
||||
frameborder: 0
|
||||
})
|
||||
.bindMessage({
|
||||
close: function(data) {
|
||||
if(!closed) {
|
||||
closed = true;
|
||||
$iframe.remove();
|
||||
delete $iframe;
|
||||
$playButton.show();
|
||||
$editButton.show();
|
||||
}
|
||||
}
|
||||
})
|
||||
.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) {
|
||||
closed = true;
|
||||
$iframe.remove();
|
||||
delete $iframe;
|
||||
$playButton.show();
|
||||
$editButton.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
$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() {
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue