@@ -3,8 +3,12 @@ let pdfRenderTasks = [];
33let pdffile = null
44let deletedMetadata = [ ] ;
55let isLocalPath = false ;
6+ let isDavPath = false ;
7+ let isIframe = Boolean ( window . parent ) ;
8+ let davTokenReceived = null ;
69let hasModifications = false ;
710let sizeOfText = 0 ;
11+ let pdf = null ;
812
913function responsiveDisplay ( ) {
1014 let menu = document . getElementById ( 'sidebarTools' ) ;
@@ -31,7 +35,7 @@ async function loadPDF(pdfBlob) {
3135 pdffile = pdfBlob
3236
3337 const loadingTask = pdfjsLib . getDocument ( url ) ;
34- const pdf = await loadingTask . promise ;
38+ pdf = await loadingTask . promise ;
3539
3640 const metadata = await pdf . getMetadata ( )
3741 const attachments = await pdf . getAttachments ( ) ;
@@ -226,6 +230,9 @@ window.addEventListener('message', function(event) {
226230 }
227231 setIsChanged ( true ) ;
228232 }
233+ if ( event . data . action === 'davOpenFile' && event . data . key == "token" ) {
234+ davTokenReceived = event . data . value
235+ }
229236} ) ;
230237
231238function updateMetadataInfos ( ) {
@@ -344,6 +351,19 @@ async function save() {
344351 } ) ;
345352 return ;
346353 }
354+
355+ if ( window . location . hash && window . location . hash . match ( / ^ \# d a v / ) ) {
356+ let headers = new Headers ( ) ;
357+ let davToken = await requestDavToken ( ) ;
358+ headers . set ( 'Authorization' , 'Basic ' + btoa ( davToken ) ) ;
359+ fetch ( window . location . hash . replace ( '#dav:' , '' ) , {
360+ method : 'PUT' ,
361+ body : newPDF ,
362+ headers : headers
363+ } ) ;
364+ return ;
365+ }
366+
347367 download ( newPDF , document . getElementById ( 'input_pdf_upload' ) . files [ 0 ] . name )
348368}
349369
@@ -472,6 +492,14 @@ function createEventsListener() {
472492 }
473493 followText ( e . target , '#container-pages .textLayer span' , '#pdf_text span' , true ) ;
474494 } ) ;
495+
496+ document . getElementById ( 'btn_exit' ) . addEventListener ( 'click' , function ( e ) {
497+ if ( isIframe ) {
498+ window . parent . postMessage ( { action : 'exit' } , '*' ) ;
499+ e . preventDefault ( ) ;
500+ return ;
501+ }
502+ } ) ;
475503}
476504
477505function followText ( element , selectorFrom , selectorTo , hide ) {
@@ -507,14 +535,14 @@ async function pageMetadata(url) {
507535 document . querySelector ( 'body' ) . classList . add ( 'bg-light' ) ;
508536 document . getElementById ( 'page-upload' ) . classList . add ( 'd-none' ) ;
509537 document . getElementById ( 'page-metadata' ) . classList . remove ( 'd-none' ) ;
510- if ( isLocalPath ) {
538+ if ( isLocalPath || isDavPath ) {
511539 document . getElementById ( 'save' ) . classList . add ( 'd-none' ) ;
512540 document . getElementById ( 'save_mobile' ) . classList . add ( 'd-none' ) ;
513541 document . getElementById ( 'save_local' ) . classList . remove ( 'd-none' ) ;
514542 document . getElementById ( 'save_mobile_local' ) . classList . remove ( 'd-none' ) ;
515543 }
516544
517- if ( url && url . match ( / ^ c a c h e : \/ \/ / ) ) {
545+ if ( url && url . match ( / ^ c a c h e : \/ \/ / ) && ! isDavPath ) {
518546 await loadFileFromCache ( url . replace ( / ^ c a c h e : \/ \/ / , '' ) ) ;
519547 } else if ( url ) {
520548 await loadFileFromUrl ( url ) ;
@@ -535,9 +563,12 @@ async function pageMetadata(url) {
535563} ;
536564
537565
538- document . addEventListener ( 'DOMContentLoaded' , function ( ) {
566+ document . addEventListener ( 'DOMContentLoaded' , async function ( ) {
539567 if ( window . location . hash && window . location . hash . match ( / ^ \# h t t p / ) ) {
540568 pageMetadata ( window . location . hash . replace ( / ^ \# / , '' ) ) ;
569+ } else if ( window . location . hash && window . location . hash . match ( / ^ \# d a v : / ) ) {
570+ isDavPath = true ;
571+ pageMetadata ( window . location . hash . replace ( / ^ \# d a v : / , '' ) ) ;
541572 } else if ( window . location . hash && window . location . hash . match ( / ^ \# l o c a l / ) ) {
542573 isLocalPath = true ;
543574 pageMetadata ( window . location . origin + "/api/file/get?path=" + window . location . hash . replace ( / ^ \# l o c a l : / , '' ) , '/metadata' , window . location . hash . replace ( / ^ \# / , '' ) ) ;
0 commit comments