make pdf viewer work a bit better with the rest of owncloud
This commit is contained in:
parent
f4ce399162
commit
4cc68eac6d
3 changed files with 42 additions and 6 deletions
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
//load the required files
|
||||
//OC_Util::addStyle( 'files_texteditor', 'style' );
|
||||
//OC_Util::addScript( 'files_texteditor', 'editor');
|
||||
OC_Util::addScript( 'files_pdfviewer', 'viewer');
|
||||
OC_Util::addStyle( 'files_pdfviewer', 'viewer');
|
||||
OC_Util::addScript( 'files_pdfviewer', 'pdfjs/build/pdf');
|
||||
|
|
|
@ -31,6 +31,7 @@ var cache = new Cache(kCacheSize);
|
|||
var currentPageNumber = 1;
|
||||
|
||||
var PDFView = {
|
||||
active: false,
|
||||
pages: [],
|
||||
thumbnails: [],
|
||||
currentScale: kDefaultScale,
|
||||
|
@ -146,6 +147,9 @@ var PDFView = {
|
|||
|
||||
navigateTo: function pdfViewNavigateTo(dest) {
|
||||
if (typeof dest === 'string')
|
||||
if(!this.destinations || ! this.destinations[dest]){
|
||||
return; // invalid destination
|
||||
}
|
||||
dest = this.destinations[dest];
|
||||
if (!(dest instanceof Array))
|
||||
return; // invalid destination
|
||||
|
@ -628,10 +632,16 @@ function updateViewarea() {
|
|||
}
|
||||
|
||||
window.addEventListener('scroll', function webViewerScroll(evt) {
|
||||
if(!PDFView.active){
|
||||
return;
|
||||
}
|
||||
updateViewarea();
|
||||
}, true);
|
||||
|
||||
window.addEventListener('resize', function webViewerResize(evt) {
|
||||
if(!PDFView.active){
|
||||
return;
|
||||
}
|
||||
if (document.getElementById('pageWidthOption').selected ||
|
||||
document.getElementById('pageFitOption').selected)
|
||||
PDFView.parseScale(document.getElementById('scaleSelect').value);
|
||||
|
@ -639,10 +649,16 @@ window.addEventListener('resize', function webViewerResize(evt) {
|
|||
});
|
||||
|
||||
window.addEventListener('hashchange', function webViewerHashchange(evt) {
|
||||
if(!PDFView.active){
|
||||
return;
|
||||
}
|
||||
PDFView.setHash(document.location.hash.substring(1));
|
||||
});
|
||||
|
||||
window.addEventListener('change', function webViewerChange(evt) {
|
||||
if(!PDFView.active){
|
||||
return;
|
||||
}
|
||||
var files = evt.target.files;
|
||||
if (!files || files.length == 0)
|
||||
return;
|
||||
|
@ -671,6 +687,9 @@ window.addEventListener('change', function webViewerChange(evt) {
|
|||
}, true);
|
||||
|
||||
window.addEventListener('scalechange', function scalechange(evt) {
|
||||
if(!PDFView.active){
|
||||
return;
|
||||
}
|
||||
var customScaleOption = document.getElementById('customScaleOption');
|
||||
customScaleOption.selected = false;
|
||||
|
||||
|
@ -703,6 +722,9 @@ window.addEventListener('scalechange', function scalechange(evt) {
|
|||
}, true);
|
||||
|
||||
window.addEventListener('pagechange', function pagechange(evt) {
|
||||
if(!PDFView.active){
|
||||
return;
|
||||
}
|
||||
var page = evt.pageNumber;
|
||||
if (document.getElementById('pageNumber').value != page)
|
||||
document.getElementById('pageNumber').value = page;
|
||||
|
@ -711,6 +733,9 @@ window.addEventListener('pagechange', function pagechange(evt) {
|
|||
}, true);
|
||||
|
||||
window.addEventListener('keydown', function keydown(evt) {
|
||||
if(!PDFView.active){
|
||||
return;
|
||||
}
|
||||
var curElement = document.activeElement;
|
||||
var controlsElement = document.getElementById('controls2');
|
||||
while (curElement) {
|
||||
|
|
|
@ -5,6 +5,7 @@ function hidePDFviewer() {
|
|||
$("#viewer").remove();
|
||||
$("#loading").remove()
|
||||
document.title = showPDFviewer.lastTitle;
|
||||
PDFView.active=false;
|
||||
}
|
||||
|
||||
function showPDFviewer(dir,filename){
|
||||
|
@ -21,8 +22,21 @@ function showPDFviewer(dir,filename){
|
|||
var oldcontent = $("#content").html();
|
||||
$("#content").html(oldcontent+'<div id="loading">Loading... 0%</div><div id="viewer"></div>');
|
||||
showPDFviewer.lastTitle = document.title;
|
||||
PDFView.Ptitle = filename;
|
||||
PDFView.open(url,1.00);
|
||||
if(!showPDFviewer.loaded){
|
||||
OC.addScript( 'files_pdfviewer', 'pdfjs/build/pdf',function(){
|
||||
OC.addScript( 'files_pdfviewer', 'pdfview',function(){
|
||||
showPDFviewer.loaded=true;
|
||||
PDFJS.workerSrc = OC.filePath('files_pdfviewer','js','pdfjs/build/pdf.js');
|
||||
PDFView.Ptitle = filename;
|
||||
PDFView.open(url,1.00);
|
||||
PDFView.active=true;
|
||||
});
|
||||
});
|
||||
}else{
|
||||
PDFView.Ptitle = filename;
|
||||
PDFView.open(url,1.00);
|
||||
PDFView.active=true;
|
||||
}
|
||||
$("#pageWidthOption").attr("selected","selected");
|
||||
showPDFviewer.shown = true;
|
||||
}
|
||||
|
@ -30,8 +44,7 @@ function showPDFviewer(dir,filename){
|
|||
showPDFviewer.shown=false;
|
||||
showPDFviewer.oldCode='';
|
||||
showPDFviewer.lastTitle='';
|
||||
|
||||
var extrahtml = '<li id="extra" style="display:none;"><a title="" href="'+OC.webroot+"/apps/files_pdfviewer/lastopened.php"+'" style="background-image:url(/owncloud/apps/files_pdfviewer/css/history.png)">Last opened</a></li>';
|
||||
showPDFviewer.loaded=false;
|
||||
|
||||
$(document).ready(function(){
|
||||
if(location.href.indexOf("files")!=-1) {
|
||||
|
|
Loading…
Reference in a new issue