From 6fae534b9c5bef89de0e7991611e0097038882b9 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Tue, 3 Jan 2023 19:01:03 -0500 Subject: [PATCH] added additional configuration fields for citations. and fixed copy conflict --- package-lock.json | 4 +- package.json | 2 +- src/modules/citation/CitationModule.ts | 41 +++++++++++++++---- .../protection/ContentProtectionModule.ts | 7 +++- src/reader.ts | 18 ++++---- viewer/index_dita.html | 10 +++-- 6 files changed, 58 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3b5ec0b0..6c1be36e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@d-i-t-a/reader", - "version": "2.1.7", + "version": "2.1.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@d-i-t-a/reader", - "version": "2.1.7", + "version": "2.1.8", "license": "Apache-2.0", "dependencies": { "@types/sass": "^1.43.1", diff --git a/package.json b/package.json index efe6cd10..d228816c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@d-i-t-a/reader", - "version": "2.1.7", + "version": "2.1.8", "description": "A viewer application for EPUB files.", "repository": "https://github.com/d-i-t-a/R2D2BC", "license": "Apache-2.0", diff --git a/src/modules/citation/CitationModule.ts b/src/modules/citation/CitationModule.ts index 33efc0a0..6caedbdf 100644 --- a/src/modules/citation/CitationModule.ts +++ b/src/modules/citation/CitationModule.ts @@ -42,6 +42,10 @@ export interface CitationModuleProperties { appLink?: string; library?: string; styles?: string[]; + title?: string; + author?: string; + publisher?: string; + published?: string; } export interface CitationModuleAPI { citationCreated: any; @@ -89,10 +93,13 @@ export default class CitationModule implements ReaderModule { } async stop() { - log.log("Timeline module stop"); + log.log("Citation module stop"); } copyToClipboard(textToClipboard) { + if (this.delegate?.contentProtectionModule) { + this.delegate!.contentProtectionModule.citation = true; + } let success = true; // @ts-ignore if (window.clipboardData) { @@ -172,7 +179,11 @@ export default class CitationModule implements ReaderModule { let mlaString = ""; let apaString = ""; - if (self.publication.Metadata.Author?.length > 0) { + if (self.properties.author) { + apaString = apaString + self.properties.author; + mlaString = mlaString + self.properties.author; + chicagoString = chicagoString + self.properties.author; + } else if (self.publication.Metadata.Author?.length > 0) { // var numAuthors = self.publication.Metadata.Author.length; let authorIndex = 0; @@ -203,8 +214,10 @@ export default class CitationModule implements ReaderModule { let chicagoString = ""; let mlaString = ""; let apaString = ""; - - if ( + if (self.properties.publisher) { + mlaString = mlaString + self.properties.publisher + ", "; + chicagoString = chicagoString + self.properties.publisher + ", "; + } else if ( self.publication.Metadata.Publisher && self.publication.Metadata.Publisher[0].Name ) { @@ -216,7 +229,11 @@ export default class CitationModule implements ReaderModule { ", "; } - if (self.publication.Metadata.PublicationDate) { + if (self.properties.published) { + apaString = apaString + "(" + self.properties.published + ")"; + mlaString = mlaString + self.properties.published; + chicagoString = chicagoString + self.properties.published; + } else if (self.publication.Metadata.PublicationDate) { if (self.publication.Metadata.PublicationDate.getFullYear() > 0) { apaString = apaString + @@ -242,7 +259,13 @@ export default class CitationModule implements ReaderModule { return ["", "", ""]; }; let bookTitleFormatted = function () { - if (self.publication.Metadata.Title) { + if (self.properties.title) { + return [ + self.properties.title + ". ", + self.properties.title + ". ", + self.properties.title + ". ", + ]; + } else if (self.publication.Metadata.Title) { return [ self.publication.Metadata.Title + ". ", self.publication.Metadata.Title + ". ", @@ -291,7 +314,11 @@ export default class CitationModule implements ReaderModule { let mlaString = ""; let apaString = ""; - if ( + if (self.properties.publisher) { + mlaString = mlaString + self.properties.publisher + ", "; + chicagoString = chicagoString + self.properties.publisher + ", "; + apaString = apaString + self.properties.publisher + ", "; + } else if ( self.publication.Metadata.Publisher && self.publication.Metadata.Publisher[0].Name ) { diff --git a/src/modules/protection/ContentProtectionModule.ts b/src/modules/protection/ContentProtectionModule.ts index a517a3c5..cdc2bc5f 100644 --- a/src/modules/protection/ContentProtectionModule.ts +++ b/src/modules/protection/ContentProtectionModule.ts @@ -75,13 +75,13 @@ interface ContentProtectionRect { export class ContentProtectionModule implements ReaderModule { private rects: Array; private delegate: IFrameNavigator; - private properties?: ContentProtectionModuleProperties; + properties?: ContentProtectionModuleProperties; private hasEventListener: boolean = false; private isHacked: boolean = false; private securityContainer: HTMLDivElement; private mutationObserver: MutationObserver; private wrapper: HTMLDivElement; - + citation: boolean; public static async setupPreloadProtection( config: Partial ): Promise { @@ -1029,6 +1029,9 @@ export class ContentProtectionModule implements ReaderModule { preventDefault: () => void; stopPropagation: () => void; }) { + if (this.citation) { + return; + } log.log("copy action initiated"); let win = this.delegate.iframes[0].contentWindow; if (win) { diff --git a/src/reader.ts b/src/reader.ts index 656189ea..256729b2 100644 --- a/src/reader.ts +++ b/src/reader.ts @@ -308,6 +308,15 @@ export default class D2Reader { }) : undefined; + const citationModule = rights.enableCitations + ? await CitationModule.create({ + publication: publication, + delegate: navigator, + highlighter: highlighter, + ...initialConfig.citations, + }) + : undefined; + // Content Protection Module const contentProtectionModule = rights.enableContentProtection ? await ContentProtectionModule.create({ @@ -365,15 +374,6 @@ export default class D2Reader { }) : undefined; - const citationModule = rights.enableCitations - ? await CitationModule.create({ - publication: publication, - delegate: navigator, - highlighter: highlighter, - ...initialConfig.citations, - }) - : undefined; - return new D2Reader( settings, navigator, diff --git a/viewer/index_dita.html b/viewer/index_dita.html index 0116a839..bde98229 100644 --- a/viewer/index_dita.html +++ b/viewer/index_dita.html @@ -974,10 +974,14 @@ }, citations: { characters: 100, - appName: "r2d2bc", - appLink: "localhost", - library: "library", + appName: "r2d2bc", // optional + appLink: "localhost", // optional + library: "library", // optional styles: ["Chicago","MLA", "APA"], + title: "book title", // optional + author: "author here", // optional + publisher: "publisher name", // optional + published: "date published", // optional api : { citationCreated: function(message) { console.log("citationCreated")