forked from 0x2620/pandora
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"/>
|
<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/build/Ox.js?{{settings.CONFIG.site.version}}"></script>
|
||||||
<script type="text/javascript" src="/static/oxjs/source/Ox.UI/js/Core/Message.js"></script>
|
|
||||||
<script type="text/javascript" src="/static/pdf.js/compatibility.js"></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;
|
var currentPage = PDFView.page;
|
||||||
window.addEventListener('pagechange', function (evt) {
|
window.addEventListener('pagechange', function (evt) {
|
||||||
var page = evt.pageNumber;
|
var page = evt.pageNumber;
|
||||||
if (page && page != currentPage) {
|
if (page && page != currentPage) {
|
||||||
currentPage = page;
|
currentPage = page;
|
||||||
Ox.$parent.postMessage('page', {
|
Ox.parent.postMessage('page', {
|
||||||
page: Math.round(page)
|
page: Math.round(page)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Ox.$parent.onMessage(function(event, data, oxid) {
|
Ox.parent.bindMessage({
|
||||||
if (event == 'page' && Ox.isUndefined(oxid)) {
|
page: function(data) {
|
||||||
if (data.page != PDFView.page) {
|
if (data.page != PDFView.page) {
|
||||||
PDFView.page = data.page;
|
PDFView.page = data.page;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
if (event == 'pdf' && Ox.isUndefined(oxid)) {
|
pdf: function(data) {
|
||||||
if (PDFView.url != data.pdf) {
|
if (PDFView.url != data.pdf) {
|
||||||
PDFView.open(data.pdf);
|
PDFView.open(data.pdf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Ox.$parent.postMessage('init', {});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function getVideoOverlay(page) {
|
function getVideoOverlay(page) {
|
||||||
|
@ -72,15 +75,10 @@ function getVideoOverlay(page) {
|
||||||
enableVideoUI();
|
enableVideoUI();
|
||||||
}
|
}
|
||||||
this.div.appendChild($interface[0]);
|
this.div.appendChild($interface[0]);
|
||||||
Ox.Message.bind(function(event, data, oxid) {
|
Ox.parent.bindMessage('update', function(data) {
|
||||||
if (event == 'update') {
|
if (video && data.id == video.id && data.page == video.page) {
|
||||||
if(Ox.isUndefined(oxid)
|
video.src = data.src;
|
||||||
&& video
|
video.src !== '' ? enableVideoUI() : disableVideoUI();
|
||||||
&& 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.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
var videoId = 'video' + page + id + Ox.uid(),
|
var videoId = 'video' + page + id + Ox.uid(),
|
||||||
$iframe = Ox.$('<iframe>')
|
$iframe = Ox.Element('<iframe>')
|
||||||
.attr({
|
.attr({
|
||||||
id: videoId,
|
id: videoId,
|
||||||
src: video.src
|
src: video.src
|
||||||
|
@ -96,27 +94,22 @@ function getVideoOverlay(page) {
|
||||||
+ '&showCloseButton=true&fullscreen=false&paused=false',
|
+ '&showCloseButton=true&fullscreen=false&paused=false',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
|
scrolling: 'no',
|
||||||
frameborder: 0
|
frameborder: 0
|
||||||
})
|
})
|
||||||
|
.bindMessage({
|
||||||
|
close: function(data) {
|
||||||
|
if(!closed) {
|
||||||
|
closed = true;
|
||||||
|
$iframe.remove();
|
||||||
|
delete $iframe;
|
||||||
|
$playButton.show();
|
||||||
|
$editButton.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
.appendTo($interface),
|
.appendTo($interface),
|
||||||
closed = false;
|
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();
|
$playButton.hide();
|
||||||
$editButton.hide();
|
$editButton.hide();
|
||||||
return false;
|
return false;
|
||||||
|
@ -131,7 +124,7 @@ function getVideoOverlay(page) {
|
||||||
src: '',
|
src: '',
|
||||||
type: 'inline'
|
type: 'inline'
|
||||||
};
|
};
|
||||||
Ox.$parent.postMessage('edit', video);
|
Ox.parent.postMessage('edit', video);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
function enableVideoUI() {
|
function enableVideoUI() {
|
||||||
|
|
|
@ -25,7 +25,6 @@ limitations under the License.
|
||||||
<link rel="stylesheet" href="/static/pdf.js/viewer.css"/>
|
<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/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>
|
<script type="text/javascript" src="compatibility.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue