]> source.dussan.org Git - nextcloud-server.git/commitdiff
make pdf viewer work a bit better with the rest of owncloud
authorRobin Appelman <icewind@owncloud.com>
Sat, 14 Jan 2012 20:38:33 +0000 (21:38 +0100)
committerRobin Appelman <icewind@owncloud.com>
Sat, 14 Jan 2012 20:38:33 +0000 (21:38 +0100)
apps/files_pdfviewer/appinfo/app.php
apps/files_pdfviewer/js/pdfview.js
apps/files_pdfviewer/js/viewer.js

index a446b4caa419d519272d4902c9f16d1ae065ce95..0f0b40764d9360763c2df56aff39cb7a75b8e6e4 100755 (executable)
@@ -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');
index 5e546fd55801fe6794476d332fd349bac08f090a..51f6e169f72e62faaea70f0636266467d8a008f2 100755 (executable)
@@ -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) {
index 314a08b27e6297fd91d80139984398272903b001..03288ebe4207cf4f10931d102b8d4cf2765a023e 100755 (executable)
@@ -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) {