viewer.js 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. function hidePDFviewer() {
  2. showPDFviewer.shown = false;
  3. $('table').show();
  4. $('#controls').html(showPDFviewer.oldcode);
  5. $("#viewer").remove();
  6. $("#loading").remove()
  7. $("#editor").show();
  8. document.title = showPDFviewer.lastTitle;
  9. PDFView.active=false;
  10. $('iframe').remove();
  11. }
  12. function showPDFviewer(dir,filename){
  13. if(!showPDFviewer.shown){
  14. $("#editor").hide();
  15. var url = OC.filePath('files','ajax','download.php')+'?files='+encodeURIComponent(filename)+"&dir="+encodeURIComponent(dir);
  16. $('table').hide();
  17. function im(path) { return OC.filePath('files_pdfviewer','js','pdfjs/web/images/'+path); }
  18. showPDFviewer.oldcode = $("#controls").html();
  19. $("#controls").empty();
  20. $("#controls").html('<button id="previous" onclick="PDFView.page--;" oncontextmenu="return false;"><img src="'+im('go-up.svg')+'" align="top" height="10"/>Previous</button><button id="next" onclick="PDFView.page++;" oncontextmenu="return false;"><img src="'+im('go-down.svg')+'" align="top" height="10"/>Next</button><div class="separator"></div><input style="width:25px;" type="number" id="pageNumber" onchange="PDFView.page = this.value;" value="1" size="4" min="1" /><span>/</span><span id="numPages">--</span><div class="separator"></div><button id="zoomOut" title="Zoom Out" onclick="PDFView.zoomOut();" oncontextmenu="return false;"><img src="'+im('zoom-out.svg')+'" align="top" height="10"/></button><button id="zoomIn" title="Zoom In" onclick="PDFView.zoomIn();" oncontextmenu="return false;"><img src="'+im('zoom-in.svg')+
  21. '" align="top" height="10"/></button><div class="separator"></div><select id="scaleSelect" onchange="PDFView.parseScale(this.value);" oncontextmenu="return false;"><option id="customScaleOption" value="custom"></option><option value="0.5">50%</option><option value="0.75">75%</option><option value="1">100%</option><option value="1.25" selected="selected">125%</option><option value="1.5">150%</option><option value="2">200%</option><option id="pageWidthOption" value="page-width">Page Width</option><option id="pageFitOption" value="page-fit">Page Fit</option></select><div class="separator"></div><button id="print" onclick="window.print();" oncontextmenu="return false;"><img src="'+im('document-print.svg')+'" align="top" height="10"/>Print</button><button id="download" title="Download" onclick="PDFView.download();" oncontextmenu="return false;">'+
  22. '<img src="'+im('download.svg')+'" align="top" height="10"/>Download</button><button id="close" title="Close viewer" onclick="hidePDFviewer();" oncontextmenu="return false;">x</button><span id="info">--</span></div>');
  23. var oldcontent = $("#content").html();
  24. $("#content").html(oldcontent+'<div id="loading">Loading... 0%</div><div id="viewer"></div>');
  25. showPDFviewer.lastTitle = document.title;
  26. if(!showPDFviewer.loaded){
  27. OC.addScript( 'files_pdfviewer', 'pdfjs/build/pdf',function(){
  28. OC.addScript( 'files_pdfviewer', 'pdfview',function(){
  29. showPDFviewer.loaded=true;
  30. PDFJS.workerSrc = OC.filePath('files_pdfviewer','js','pdfjs/build/pdf.js');
  31. PDFView.Ptitle = filename;
  32. PDFView.open(url,1.00);
  33. PDFView.active=true;
  34. });
  35. });
  36. }else{
  37. PDFView.Ptitle = filename;
  38. PDFView.open(url,1.00);
  39. PDFView.active=true;
  40. }
  41. $("#pageWidthOption").attr("selected","selected");
  42. showPDFviewer.shown = true;
  43. }
  44. }
  45. showPDFviewer.shown=false;
  46. showPDFviewer.oldCode='';
  47. showPDFviewer.lastTitle='';
  48. showPDFviewer.loaded=false;
  49. $(document).ready(function(){
  50. if(!$.browser.msie){//doesnt work on IE
  51. if(location.href.indexOf("files")!=-1) {
  52. PDFJS.workerSrc = OC.filePath('files_pdfviewer','js','pdfjs/build/pdf.js');
  53. if(typeof FileActions!=='undefined'){
  54. FileActions.register('application/pdf','Edit','',function(filename){
  55. showPDFviewer($('#dir').val(),filename);
  56. });
  57. FileActions.setDefault('application/pdf','Edit');
  58. }
  59. }
  60. }
  61. });