Skip to content

Commit ff3b376

Browse files
authored
Merge pull request #285 from pipwerks/2.2.9
2.2.10
2 parents 3fd7de6 + 6f12afa commit ff3b376

File tree

7 files changed

+31
-15
lines changed

7 files changed

+31
-15
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The MIT License (MIT)
2-
Copyright © 2021 Philip Hutchison
2+
Copyright © 2023 Philip Hutchison
33
https://pipwerks.mit-license.org/
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pdfobject",
33
"description": "An open-source standards-friendly JavaScript utility for embedding PDF files into HTML documents",
4-
"version": "2.2.8",
4+
"version": "2.2.10",
55
"main": "pdfobject.js",
66
"moduleType": [
77
"globals",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pdfobject",
3-
"version": "2.2.8",
3+
"version": "2.2.10",
44
"description": "An open-source standards-friendly JavaScript utility for embedding PDF files into HTML documents",
55
"main": "pdfobject.js",
66
"scripts": {

pdfobject.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* PDFObject v2.2.8
2+
* PDFObject v2.2.10
33
* https://github.com/pipwerks/PDFObject
44
* @license
5-
* Copyright (c) 2008-2022 Philip Hutchison
5+
* Copyright (c) 2008-2023 Philip Hutchison
66
* MIT-style license: http://pipwerks.mit-license.org/
77
* UMD module pattern from https://github.com/umdjs/umd/blob/master/templates/returnExports.js
88
*/
@@ -184,7 +184,7 @@
184184

185185
};
186186

187-
let generatePDFObjectMarkup = function (embedType, targetNode, url, pdfOpenFragment, width, height, id, title, omitInlineStyles, PDFJS_URL){
187+
let generatePDFObjectMarkup = function (embedType, targetNode, url, pdfOpenFragment, width, height, id, title, omitInlineStyles, customAttribute, PDFJS_URL){
188188

189189
//Ensure target element is empty first
190190
emptyNodeContents(targetNode);
@@ -195,6 +195,8 @@
195195
//If PDFJS_URL already contains a ?, assume querystring is in place, and use an ampersand to append PDFJS's file parameter
196196
let connector = (PDFJS_URL.indexOf("?") !== -1) ? "&" : "?";
197197
source = PDFJS_URL + connector + "file=" + encodeURIComponent(url) + pdfOpenFragment;
198+
} else {
199+
source += pdfOpenFragment;
198200
}
199201

200202
let el_type = (embedType === "pdfjs" || embedType === "iframe") ? "iframe" : "embed";
@@ -230,6 +232,12 @@
230232

231233
}
232234

235+
//Allow developer to insert custom attribute on embed/iframe element, but ensure it does not conflict with attributes used by PDFObject
236+
let reservedTokens = ["className", "type", "title", "src", "style", "id", "allow", "frameborder"];
237+
if(customAttribute && customAttribute.key && reservedTokens.every(token => !customAttribute.key.includes(token))){
238+
el.setAttribute(customAttribute.key, (typeof customAttribute.value !== "undefined") ? customAttribute.value : "");
239+
}
240+
233241
targetNode.classList.add("pdfobject-container");
234242
targetNode.appendChild(el);
235243

@@ -263,6 +271,7 @@
263271
let targetNode = getTargetElement(selector);
264272
let fallbackHTML = "";
265273
let pdfOpenFragment = "";
274+
let customAttribute = opt.customAttribute || {};
266275
let fallbackHTML_default = "<p>This browser does not support inline PDFs. Please download the PDF to view it: <a href='[url]'>Download PDF</a></p>";
267276

268277
//Ensure URL is available. If not, exit now.
@@ -282,7 +291,7 @@
282291

283292
//If the forcePDFJS option is invoked, skip everything else and embed as directed
284293
if(forcePDFJS && PDFJS_URL){
285-
return generatePDFObjectMarkup("pdfjs", targetNode, url, pdfOpenFragment, width, height, id, title, omitInlineStyles, PDFJS_URL);
294+
return generatePDFObjectMarkup("pdfjs", targetNode, url, pdfOpenFragment, width, height, id, title, omitInlineStyles, customAttribute, PDFJS_URL);
286295
}
287296

288297
// --== Embed attempt #2 ==--
@@ -298,15 +307,15 @@
298307
//Forcing Safari desktop to use iframe due to freezing bug in macOS 11 (Big Sur)
299308
let embedtype = (forceIframe || supportRedirect || isSafariDesktop) ? "iframe" : "embed";
300309

301-
return generatePDFObjectMarkup(embedtype, targetNode, url, pdfOpenFragment, width, height, id, title, omitInlineStyles);
310+
return generatePDFObjectMarkup(embedtype, targetNode, url, pdfOpenFragment, width, height, id, title, omitInlineStyles, customAttribute);
302311

303312
}
304313

305314
// --== Embed attempt #3 ==--
306315

307316
//If everything else has failed and a PDFJS fallback is provided, try to use it
308317
if(PDFJS_URL){
309-
return generatePDFObjectMarkup("pdfjs", targetNode, url, pdfOpenFragment, width, height, id, title, omitInlineStyles, PDFJS_URL);
318+
return generatePDFObjectMarkup("pdfjs", targetNode, url, pdfOpenFragment, width, height, id, title, omitInlineStyles, customAttribute, PDFJS_URL);
310319
}
311320

312321
// --== PDF embed not supported! Use fallback ==--

pdfobject.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PDFObject is a lightweight JavaScript utility for dynamically embedding PDFs in
22

33
Examples and documentation can be found at https://pdfobject.com.
44

5-
Copyright (c) 2008-2022 Philip Hutchison
5+
Copyright (c) 2008-2023 Philip Hutchison
66
MIT-style license: http://pipwerks.mit-license.org/
77

88
-----
@@ -11,6 +11,13 @@ MIT-style license: http://pipwerks.mit-license.org/
1111

1212
## Changelog
1313

14+
### 2.2.10, May 2023
15+
Version bump for cleaning up docs and aligning on NPM. I'm a bit rusty.
16+
17+
### 2.2.9, May 2023
18+
* Fixed regression for `pdfOpenParams` handling, resolves issue #272. Hat tip to Theo Beers.
19+
* Added ability to specify custom attribute on `embed` and `iframe` elements, per #274
20+
1421
### 2.2.8, April 2022
1522
* Refactored to reduce redundant code. Simplified iframe and PDFJS handling. Subsequently resolves #263 (double scroll bars) and PR #267 (PDFJS_URL param fix). Hat tip to Theo Beers, Sascha Greuel, meier-andersen, and everyone who helped identify and confirm the underlying issues.
1623
* Fixed `fallbackLink` handling to ensure `false` is respected. Hat tip to Theo Beers.

0 commit comments

Comments
 (0)