From f5b027f2466fec9014cb8eacc18461335119b8c5 Mon Sep 17 00:00:00 2001 From: farling42 Date: Thu, 15 Feb 2024 19:36:14 +0000 Subject: [PATCH] Make compatible with Monk's Enhanced Journal --- CHANGELOG.md | 4 ++++ README.md | 4 ++++ scripts/pdf-linker.mjs | 17 ++++++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c5f041..b4fdcd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.51.0 + +- With Monk's Enhanced Journal module, support creation of `@PDF` links when dragging a PDF page title to a journal page. + ## 0.50.0 - Only display "Data Inspector" and "Show PDF Fields" in the Actor/Item PDF sheet if the user is a GM. diff --git a/README.md b/README.md index 0e9d0ff..54269b9 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,10 @@ It also generates reads the Outline from the PDF file to use as the Table of Con The module option "Immediately Display PDF" will remove the "Load PDF" button from the PDF pages of journal and will instead immediately load the PDF into the window. +## Create links to sections within a PDF. + +The page header or an individual section from the table of contents of a PDF journal page can be dragged to another journal page in order to create a `@PDF` link to that PDF document. When the page header is dragged from the TOC, then a link is created to the currently visible page within the PDF. + ## PDF Character Sheets This module will allow a fillable PDF document to be used as the Actor sheet for actors. diff --git a/scripts/pdf-linker.mjs b/scripts/pdf-linker.mjs index cefdf6f..807b7fb 100644 --- a/scripts/pdf-linker.mjs +++ b/scripts/pdf-linker.mjs @@ -134,13 +134,16 @@ function JournalEntryPage_createDocumentLink(wrapped, eventData, args) { // Use page=xxx as slug let pagenum=1; let sheet = this.parent?.sheet; // JournalEntry - if (sheet && sheet._pages[sheet.pageIndex]._id == this.id) - { - let iframe = sheet.element?.find('iframe'); - if (iframe?.length>0) { - // Read current page from PDF viewer, then remove the user-configured offset from that number. - pagenum = iframe[0].contentWindow.PDFViewerApplication.page - (this.getFlag(PDFCONFIG.MODULE_NAME, PDFCONFIG.FLAG_OFFSET) ?? 0); - } + let iframe; + + if (game.MonksEnhancedJournal) + iframe = game.MonksEnhancedJournal.journal?.element?.find('iframe'); + else if (sheet && sheet._pages && sheet._pages[sheet.pageIndex]._id == this.id) + iframe = sheet.element?.find('iframe'); + + if (iframe?.length>0) { + // Read current page from PDF viewer, then remove the user-configured offset from that number. + pagenum = iframe[0].contentWindow.PDFViewerApplication.page - (this.getFlag(PDFCONFIG.MODULE_NAME, PDFCONFIG.FLAG_OFFSET) ?? 0); } slug = `page=${pagenum}` label = this.name;