Skip to content

Commit

Permalink
Merge pull request #790 from cdrini/feature/textsel-jsonp-xml
Browse files Browse the repository at this point in the history
Add jsonp support to textsel fetches + Netlify CORS support
  • Loading branch information
cdrini authored Jan 24, 2023
2 parents 367248e + 0dfd0f6 commit 6df6ec5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[[headers]]
# Define which paths this specific [[headers]] block will cover.
for = "/BookReader/*"
[headers.values]
Access-Control-Allow-Origin = "*"
2 changes: 2 additions & 0 deletions src/css/_TextSelection.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.textSelectionSVG {
z-index: 2;

// Make it so right-clicking on "blank" part of svg sends events to the image (for saving)
pointer-events: none;
.BRwordElement { pointer-events: all; }
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/plugin.text_selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const DEFAULT_OPTIONS = {
fullDjvuXmlUrl: null,
/** @type {StringWithVars} The URL to fetch a single page of the DJVU xml. Supports options.vars. Also has {{pageIndex}} */
singlePageDjvuXmlUrl: null,
/** Whether to fetch the XML as a jsonp */
jsonp: false,
};
/** @typedef {typeof DEFAULT_OPTIONS} TextSelectionPluginOptions */

Expand Down Expand Up @@ -74,7 +76,8 @@ export class TextSelectionPlugin {
this.djvuPagesPromise = $.ajax({
type: "GET",
url: applyVariables(this.options.fullDjvuXmlUrl, this.optionVariables),
dataType: "html",
dataType: this.options.jsonp ? "jsonp" : "html",
cache: true,
error: (e) => undefined
}).then((res) => {
try {
Expand All @@ -99,7 +102,8 @@ export class TextSelectionPlugin {
const res = await $.ajax({
type: "GET",
url: applyVariables(this.options.singlePageDjvuXmlUrl, this.optionVariables, { pageIndex: index }),
dataType: "html",
dataType: this.options.jsonp ? "jsonp" : "html",
cache: true,
error: (e) => undefined,
});
try {
Expand Down

0 comments on commit 6df6ec5

Please sign in to comment.