Skip to content

Commit

Permalink
Merge pull request #422 from d-i-t-a/develop
Browse files Browse the repository at this point in the history
2.1.8
  • Loading branch information
aferditamuriqi authored Jan 4, 2023
2 parents 49d3585 + 8d90561 commit 11ebd5d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
41 changes: 34 additions & 7 deletions src/modules/citation/CitationModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
) {
Expand All @@ -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 +
Expand All @@ -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 + ". ",
Expand Down Expand Up @@ -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
) {
Expand Down
7 changes: 5 additions & 2 deletions src/modules/protection/ContentProtectionModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ interface ContentProtectionRect {
export class ContentProtectionModule implements ReaderModule {
private rects: Array<ContentProtectionRect>;
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<ContentProtectionModuleConfig>
): Promise<void> {
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions src/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions viewer/index_dita.html
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 11ebd5d

Please sign in to comment.