printjs-rpk 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +12 -0
- package/LICENSE +21 -0
- package/README.md +98 -0
- package/dist/print.css +97 -0
- package/dist/print.js +991 -0
- package/dist/print.map +1 -0
- package/package.json +60 -0
- package/src/index.d.ts +46 -0
- package/src/index.js +10 -0
- package/src/js/browser.js +29 -0
- package/src/js/functions.js +111 -0
- package/src/js/html.js +70 -0
- package/src/js/image.js +48 -0
- package/src/js/init.js +169 -0
- package/src/js/json.js +109 -0
- package/src/js/modal.js +62 -0
- package/src/js/pdf.js +57 -0
- package/src/js/print.js +102 -0
- package/src/js/raw-html.js +15 -0
- package/src/sass/index.scss +14 -0
- package/src/sass/modules/_colors.scss +10 -0
- package/src/sass/partials/_modal.scss +41 -0
- package/src/sass/partials/_spinner.scss +46 -0
package/dist/print.js
ADDED
@@ -0,0 +1,991 @@
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
3
|
+
module.exports = factory();
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
5
|
+
define([], factory);
|
6
|
+
else if(typeof exports === 'object')
|
7
|
+
exports["printJS"] = factory();
|
8
|
+
else
|
9
|
+
root["printJS"] = factory();
|
10
|
+
})(window, function() {
|
11
|
+
return /******/ (function(modules) { // webpackBootstrap
|
12
|
+
/******/ // The module cache
|
13
|
+
/******/ var installedModules = {};
|
14
|
+
/******/
|
15
|
+
/******/ // The require function
|
16
|
+
/******/ function __webpack_require__(moduleId) {
|
17
|
+
/******/
|
18
|
+
/******/ // Check if module is in cache
|
19
|
+
/******/ if(installedModules[moduleId]) {
|
20
|
+
/******/ return installedModules[moduleId].exports;
|
21
|
+
/******/ }
|
22
|
+
/******/ // Create a new module (and put it into the cache)
|
23
|
+
/******/ var module = installedModules[moduleId] = {
|
24
|
+
/******/ i: moduleId,
|
25
|
+
/******/ l: false,
|
26
|
+
/******/ exports: {}
|
27
|
+
/******/ };
|
28
|
+
/******/
|
29
|
+
/******/ // Execute the module function
|
30
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
31
|
+
/******/
|
32
|
+
/******/ // Flag the module as loaded
|
33
|
+
/******/ module.l = true;
|
34
|
+
/******/
|
35
|
+
/******/ // Return the exports of the module
|
36
|
+
/******/ return module.exports;
|
37
|
+
/******/ }
|
38
|
+
/******/
|
39
|
+
/******/
|
40
|
+
/******/ // expose the modules object (__webpack_modules__)
|
41
|
+
/******/ __webpack_require__.m = modules;
|
42
|
+
/******/
|
43
|
+
/******/ // expose the module cache
|
44
|
+
/******/ __webpack_require__.c = installedModules;
|
45
|
+
/******/
|
46
|
+
/******/ // define getter function for harmony exports
|
47
|
+
/******/ __webpack_require__.d = function(exports, name, getter) {
|
48
|
+
/******/ if(!__webpack_require__.o(exports, name)) {
|
49
|
+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
50
|
+
/******/ }
|
51
|
+
/******/ };
|
52
|
+
/******/
|
53
|
+
/******/ // define __esModule on exports
|
54
|
+
/******/ __webpack_require__.r = function(exports) {
|
55
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
56
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
57
|
+
/******/ }
|
58
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
59
|
+
/******/ };
|
60
|
+
/******/
|
61
|
+
/******/ // create a fake namespace object
|
62
|
+
/******/ // mode & 1: value is a module id, require it
|
63
|
+
/******/ // mode & 2: merge all properties of value into the ns
|
64
|
+
/******/ // mode & 4: return value when already ns object
|
65
|
+
/******/ // mode & 8|1: behave like require
|
66
|
+
/******/ __webpack_require__.t = function(value, mode) {
|
67
|
+
/******/ if(mode & 1) value = __webpack_require__(value);
|
68
|
+
/******/ if(mode & 8) return value;
|
69
|
+
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
70
|
+
/******/ var ns = Object.create(null);
|
71
|
+
/******/ __webpack_require__.r(ns);
|
72
|
+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
73
|
+
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
74
|
+
/******/ return ns;
|
75
|
+
/******/ };
|
76
|
+
/******/
|
77
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
78
|
+
/******/ __webpack_require__.n = function(module) {
|
79
|
+
/******/ var getter = module && module.__esModule ?
|
80
|
+
/******/ function getDefault() { return module['default']; } :
|
81
|
+
/******/ function getModuleExports() { return module; };
|
82
|
+
/******/ __webpack_require__.d(getter, 'a', getter);
|
83
|
+
/******/ return getter;
|
84
|
+
/******/ };
|
85
|
+
/******/
|
86
|
+
/******/ // Object.prototype.hasOwnProperty.call
|
87
|
+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
88
|
+
/******/
|
89
|
+
/******/ // __webpack_public_path__
|
90
|
+
/******/ __webpack_require__.p = "";
|
91
|
+
/******/
|
92
|
+
/******/
|
93
|
+
/******/ // Load entry module and return exports
|
94
|
+
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
95
|
+
/******/ })
|
96
|
+
/************************************************************************/
|
97
|
+
/******/ ({
|
98
|
+
|
99
|
+
/***/ "./src/index.js":
|
100
|
+
/*!**********************!*\
|
101
|
+
!*** ./src/index.js ***!
|
102
|
+
\**********************/
|
103
|
+
/*! exports provided: default */
|
104
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
105
|
+
|
106
|
+
"use strict";
|
107
|
+
__webpack_require__.r(__webpack_exports__);
|
108
|
+
/* harmony import */ var _sass_index_scss__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./sass/index.scss */ "./src/sass/index.scss");
|
109
|
+
/* harmony import */ var _sass_index_scss__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_sass_index_scss__WEBPACK_IMPORTED_MODULE_0__);
|
110
|
+
/* harmony import */ var _js_init__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./js/init */ "./src/js/init.js");
|
111
|
+
|
112
|
+
|
113
|
+
var printJS = _js_init__WEBPACK_IMPORTED_MODULE_1__["default"].init;
|
114
|
+
|
115
|
+
if (typeof window !== 'undefined') {
|
116
|
+
window.printJS = printJS;
|
117
|
+
}
|
118
|
+
|
119
|
+
/* harmony default export */ __webpack_exports__["default"] = (printJS);
|
120
|
+
|
121
|
+
/***/ }),
|
122
|
+
|
123
|
+
/***/ "./src/js/browser.js":
|
124
|
+
/*!***************************!*\
|
125
|
+
!*** ./src/js/browser.js ***!
|
126
|
+
\***************************/
|
127
|
+
/*! exports provided: default */
|
128
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
129
|
+
|
130
|
+
"use strict";
|
131
|
+
__webpack_require__.r(__webpack_exports__);
|
132
|
+
var Browser = {
|
133
|
+
// Firefox 1.0+
|
134
|
+
isFirefox: function isFirefox() {
|
135
|
+
return typeof InstallTrigger !== 'undefined';
|
136
|
+
},
|
137
|
+
// Internet Explorer 6-11
|
138
|
+
isIE: function isIE() {
|
139
|
+
return navigator.userAgent.indexOf('MSIE') !== -1 || !!document.documentMode;
|
140
|
+
},
|
141
|
+
// Edge 20+
|
142
|
+
isEdge: function isEdge() {
|
143
|
+
return !Browser.isIE() && !!window.StyleMedia;
|
144
|
+
},
|
145
|
+
// Chrome 1+
|
146
|
+
isChrome: function isChrome() {
|
147
|
+
var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
|
148
|
+
return !!context.chrome;
|
149
|
+
},
|
150
|
+
// At least Safari 3+: "[object HTMLElementConstructor]"
|
151
|
+
isSafari: function isSafari() {
|
152
|
+
return Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 || navigator.userAgent.toLowerCase().indexOf('safari') !== -1;
|
153
|
+
},
|
154
|
+
// IOS Chrome
|
155
|
+
isIOSChrome: function isIOSChrome() {
|
156
|
+
return navigator.userAgent.toLowerCase().indexOf('crios') !== -1;
|
157
|
+
}
|
158
|
+
};
|
159
|
+
/* harmony default export */ __webpack_exports__["default"] = (Browser);
|
160
|
+
|
161
|
+
/***/ }),
|
162
|
+
|
163
|
+
/***/ "./src/js/functions.js":
|
164
|
+
/*!*****************************!*\
|
165
|
+
!*** ./src/js/functions.js ***!
|
166
|
+
\*****************************/
|
167
|
+
/*! exports provided: addWrapper, capitalizePrint, collectStyles, addHeader, cleanUp, isRawHTML */
|
168
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
169
|
+
|
170
|
+
"use strict";
|
171
|
+
__webpack_require__.r(__webpack_exports__);
|
172
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addWrapper", function() { return addWrapper; });
|
173
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "capitalizePrint", function() { return capitalizePrint; });
|
174
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "collectStyles", function() { return collectStyles; });
|
175
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addHeader", function() { return addHeader; });
|
176
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "cleanUp", function() { return cleanUp; });
|
177
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isRawHTML", function() { return isRawHTML; });
|
178
|
+
/* harmony import */ var _modal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./modal */ "./src/js/modal.js");
|
179
|
+
/* harmony import */ var _browser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./browser */ "./src/js/browser.js");
|
180
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
function addWrapper(htmlData, params) {
|
185
|
+
var bodyStyle = 'font-family:' + params.font + ' !important; font-size: ' + params.font_size + ' !important; width:100%;';
|
186
|
+
return '<div style="' + bodyStyle + '">' + htmlData + '</div>';
|
187
|
+
}
|
188
|
+
function capitalizePrint(obj) {
|
189
|
+
return obj.charAt(0).toUpperCase() + obj.slice(1);
|
190
|
+
}
|
191
|
+
function collectStyles(element, params) {
|
192
|
+
var win = document.defaultView || window; // String variable to hold styling for each element
|
193
|
+
|
194
|
+
var elementStyle = ''; // Loop over computed styles
|
195
|
+
|
196
|
+
var styles = win.getComputedStyle(element, '');
|
197
|
+
|
198
|
+
for (var key = 0; key < styles.length; key++) {
|
199
|
+
// Check if style should be processed
|
200
|
+
if (params.targetStyles.indexOf('*') !== -1 || params.targetStyle.indexOf(styles[key]) !== -1 || targetStylesMatch(params.targetStyles, styles[key])) {
|
201
|
+
if (styles.getPropertyValue(styles[key])) elementStyle += styles[key] + ':' + styles.getPropertyValue(styles[key]) + ';';
|
202
|
+
}
|
203
|
+
} // Print friendly defaults (deprecated)
|
204
|
+
|
205
|
+
|
206
|
+
elementStyle += 'max-width: ' + params.maxWidth + 'px !important; font-size: ' + params.font_size + ' !important;';
|
207
|
+
return elementStyle;
|
208
|
+
}
|
209
|
+
|
210
|
+
function targetStylesMatch(styles, value) {
|
211
|
+
for (var i = 0; i < styles.length; i++) {
|
212
|
+
if (_typeof(value) === 'object' && value.indexOf(styles[i]) !== -1) return true;
|
213
|
+
}
|
214
|
+
|
215
|
+
return false;
|
216
|
+
}
|
217
|
+
|
218
|
+
function addHeader(printElement, params) {
|
219
|
+
// Create the header container div
|
220
|
+
var headerContainer = document.createElement('div'); // Check if the header is text or raw html
|
221
|
+
|
222
|
+
if (isRawHTML(params.header)) {
|
223
|
+
headerContainer.innerHTML = params.header;
|
224
|
+
} else {
|
225
|
+
// Create header element
|
226
|
+
var headerElement = document.createElement('h1'); // Create header text node
|
227
|
+
|
228
|
+
var headerNode = document.createTextNode(params.header); // Build and style
|
229
|
+
|
230
|
+
headerElement.appendChild(headerNode);
|
231
|
+
headerElement.setAttribute('style', params.headerStyle);
|
232
|
+
headerContainer.appendChild(headerElement);
|
233
|
+
}
|
234
|
+
|
235
|
+
printElement.insertBefore(headerContainer, printElement.childNodes[0]);
|
236
|
+
}
|
237
|
+
function cleanUp(params) {
|
238
|
+
// If we are showing a feedback message to user, remove it
|
239
|
+
if (params.showModal) _modal__WEBPACK_IMPORTED_MODULE_0__["default"].close(); // Check for a finished loading hook function
|
240
|
+
|
241
|
+
if (params.onLoadingEnd) params.onLoadingEnd(); // If preloading pdf files, clean blob url
|
242
|
+
|
243
|
+
if (params.showModal || params.onLoadingStart) window.URL.revokeObjectURL(params.printable); // Run onPrintDialogClose callback
|
244
|
+
|
245
|
+
var event = 'mouseover';
|
246
|
+
|
247
|
+
if (_browser__WEBPACK_IMPORTED_MODULE_1__["default"].isChrome() || _browser__WEBPACK_IMPORTED_MODULE_1__["default"].isFirefox()) {
|
248
|
+
// Ps.: Firefox will require an extra click in the document to fire the focus event.
|
249
|
+
event = 'focus';
|
250
|
+
}
|
251
|
+
|
252
|
+
var handler = function handler() {
|
253
|
+
// Make sure the event only happens once.
|
254
|
+
window.removeEventListener(event, handler);
|
255
|
+
params.onPrintDialogClose(); // Remove iframe from the DOM
|
256
|
+
|
257
|
+
var iframe = document.getElementById(params.frameId);
|
258
|
+
|
259
|
+
if (iframe) {
|
260
|
+
iframe.remove();
|
261
|
+
}
|
262
|
+
};
|
263
|
+
|
264
|
+
window.addEventListener(event, handler);
|
265
|
+
}
|
266
|
+
function isRawHTML(raw) {
|
267
|
+
var regexHtml = new RegExp('<([A-Za-z][A-Za-z0-9]*)\\b[^>]*>(.*?)</\\1>');
|
268
|
+
return regexHtml.test(raw);
|
269
|
+
}
|
270
|
+
|
271
|
+
/***/ }),
|
272
|
+
|
273
|
+
/***/ "./src/js/html.js":
|
274
|
+
/*!************************!*\
|
275
|
+
!*** ./src/js/html.js ***!
|
276
|
+
\************************/
|
277
|
+
/*! exports provided: default */
|
278
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
279
|
+
|
280
|
+
"use strict";
|
281
|
+
__webpack_require__.r(__webpack_exports__);
|
282
|
+
/* harmony import */ var _functions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./functions */ "./src/js/functions.js");
|
283
|
+
/* harmony import */ var _print__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./print */ "./src/js/print.js");
|
284
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
/* harmony default export */ __webpack_exports__["default"] = ({
|
289
|
+
print: function print(params, printFrame) {
|
290
|
+
// Get the DOM printable element
|
291
|
+
var printElement = isHtmlElement(params.printable) ? params.printable : document.getElementById(params.printable); // Check if the element exists
|
292
|
+
|
293
|
+
if (!printElement) {
|
294
|
+
window.console.error('Invalid HTML element id: ' + params.printable);
|
295
|
+
return;
|
296
|
+
} // Clone the target element including its children (if available)
|
297
|
+
|
298
|
+
|
299
|
+
params.printableElement = cloneElement(printElement, params); // Add header
|
300
|
+
|
301
|
+
if (params.header) {
|
302
|
+
Object(_functions__WEBPACK_IMPORTED_MODULE_0__["addHeader"])(params.printableElement, params);
|
303
|
+
} // Print html element contents
|
304
|
+
|
305
|
+
|
306
|
+
_print__WEBPACK_IMPORTED_MODULE_1__["default"].send(params, printFrame);
|
307
|
+
}
|
308
|
+
});
|
309
|
+
|
310
|
+
function cloneElement(element, params) {
|
311
|
+
// Clone the main node (if not already inside the recursion process)
|
312
|
+
var clone = element.cloneNode(); // Loop over and process the children elements / nodes (including text nodes)
|
313
|
+
|
314
|
+
var childNodesArray = Array.prototype.slice.call(element.childNodes);
|
315
|
+
|
316
|
+
for (var i = 0; i < childNodesArray.length; i++) {
|
317
|
+
// Check if we are skipping the current element
|
318
|
+
if (params.ignoreElements.indexOf(childNodesArray[i].id) !== -1) {
|
319
|
+
continue;
|
320
|
+
} // Clone the child element
|
321
|
+
|
322
|
+
|
323
|
+
var clonedChild = cloneElement(childNodesArray[i], params); // Attach the cloned child to the cloned parent node
|
324
|
+
|
325
|
+
clone.appendChild(clonedChild);
|
326
|
+
} // Get all styling for print element (for nodes of type element only)
|
327
|
+
|
328
|
+
|
329
|
+
if (params.scanStyles && element.nodeType === 1) {
|
330
|
+
clone.setAttribute('style', Object(_functions__WEBPACK_IMPORTED_MODULE_0__["collectStyles"])(element, params));
|
331
|
+
} // Check if the element needs any state processing (copy user input data)
|
332
|
+
|
333
|
+
|
334
|
+
switch (element.tagName) {
|
335
|
+
case 'SELECT':
|
336
|
+
// Copy the current selection value to its clone
|
337
|
+
clone.value = element.value;
|
338
|
+
break;
|
339
|
+
|
340
|
+
case 'CANVAS':
|
341
|
+
// Copy the canvas content to its clone
|
342
|
+
clone.getContext('2d').drawImage(element, 0, 0);
|
343
|
+
break;
|
344
|
+
}
|
345
|
+
|
346
|
+
return clone;
|
347
|
+
}
|
348
|
+
|
349
|
+
function isHtmlElement(printable) {
|
350
|
+
// Check if element is instance of HTMLElement or has nodeType === 1 (for elements in iframe)
|
351
|
+
return _typeof(printable) === 'object' && printable && (printable instanceof HTMLElement || printable.nodeType === 1);
|
352
|
+
}
|
353
|
+
|
354
|
+
/***/ }),
|
355
|
+
|
356
|
+
/***/ "./src/js/image.js":
|
357
|
+
/*!*************************!*\
|
358
|
+
!*** ./src/js/image.js ***!
|
359
|
+
\*************************/
|
360
|
+
/*! exports provided: default */
|
361
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
362
|
+
|
363
|
+
"use strict";
|
364
|
+
__webpack_require__.r(__webpack_exports__);
|
365
|
+
/* harmony import */ var _functions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./functions */ "./src/js/functions.js");
|
366
|
+
/* harmony import */ var _print__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./print */ "./src/js/print.js");
|
367
|
+
/* harmony import */ var _browser__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./browser */ "./src/js/browser.js");
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
/* harmony default export */ __webpack_exports__["default"] = ({
|
372
|
+
print: function print(params, printFrame) {
|
373
|
+
// Check if we are printing one image or multiple images
|
374
|
+
if (params.printable.constructor !== Array) {
|
375
|
+
// Create array with one image
|
376
|
+
params.printable = [params.printable];
|
377
|
+
} // Create printable element (container)
|
378
|
+
|
379
|
+
|
380
|
+
params.printableElement = document.createElement('div'); // Create all image elements and append them to the printable container
|
381
|
+
|
382
|
+
params.printable.forEach(function (src) {
|
383
|
+
// Create the image element
|
384
|
+
var img = document.createElement('img');
|
385
|
+
img.setAttribute('style', params.imageStyle); // Set image src with the file url
|
386
|
+
|
387
|
+
img.src = src; // The following block is for Firefox, which for some reason requires the image's src to be fully qualified in
|
388
|
+
// order to print it
|
389
|
+
|
390
|
+
if (_browser__WEBPACK_IMPORTED_MODULE_2__["default"].isFirefox()) {
|
391
|
+
var fullyQualifiedSrc = img.src;
|
392
|
+
img.src = fullyQualifiedSrc;
|
393
|
+
} // Create the image wrapper
|
394
|
+
|
395
|
+
|
396
|
+
var imageWrapper = document.createElement('div'); // Append image to the wrapper element
|
397
|
+
|
398
|
+
imageWrapper.appendChild(img); // Append wrapper to the printable element
|
399
|
+
|
400
|
+
params.printableElement.appendChild(imageWrapper);
|
401
|
+
}); // Check if we are adding a print header
|
402
|
+
|
403
|
+
if (params.header) Object(_functions__WEBPACK_IMPORTED_MODULE_0__["addHeader"])(params.printableElement, params); // Print image
|
404
|
+
|
405
|
+
_print__WEBPACK_IMPORTED_MODULE_1__["default"].send(params, printFrame);
|
406
|
+
}
|
407
|
+
});
|
408
|
+
|
409
|
+
/***/ }),
|
410
|
+
|
411
|
+
/***/ "./src/js/init.js":
|
412
|
+
/*!************************!*\
|
413
|
+
!*** ./src/js/init.js ***!
|
414
|
+
\************************/
|
415
|
+
/*! exports provided: default */
|
416
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
417
|
+
|
418
|
+
"use strict";
|
419
|
+
__webpack_require__.r(__webpack_exports__);
|
420
|
+
/* harmony import */ var _browser__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./browser */ "./src/js/browser.js");
|
421
|
+
/* harmony import */ var _modal__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./modal */ "./src/js/modal.js");
|
422
|
+
/* harmony import */ var _pdf__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./pdf */ "./src/js/pdf.js");
|
423
|
+
/* harmony import */ var _html__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./html */ "./src/js/html.js");
|
424
|
+
/* harmony import */ var _raw_html__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./raw-html */ "./src/js/raw-html.js");
|
425
|
+
/* harmony import */ var _image__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./image */ "./src/js/image.js");
|
426
|
+
/* harmony import */ var _json__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./json */ "./src/js/json.js");
|
427
|
+
|
428
|
+
|
429
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
var printTypes = ['pdf', 'html', 'image', 'json', 'raw-html'];
|
439
|
+
/* harmony default export */ __webpack_exports__["default"] = ({
|
440
|
+
init: function init() {
|
441
|
+
var params = {
|
442
|
+
printable: null,
|
443
|
+
fallbackPrintable: null,
|
444
|
+
type: 'pdf',
|
445
|
+
header: null,
|
446
|
+
headerStyle: 'font-weight: 300;',
|
447
|
+
maxWidth: 800,
|
448
|
+
properties: null,
|
449
|
+
gridHeaderStyle: 'font-weight: bold; padding: 5px; border: 1px solid #dddddd;',
|
450
|
+
gridStyle: 'border: 1px solid lightgray; margin-bottom: -1px;',
|
451
|
+
showModal: false,
|
452
|
+
onError: function onError(error) {
|
453
|
+
throw error;
|
454
|
+
},
|
455
|
+
onLoadingStart: null,
|
456
|
+
onLoadingEnd: null,
|
457
|
+
onPrintDialogClose: function onPrintDialogClose() {},
|
458
|
+
onIncompatibleBrowser: function onIncompatibleBrowser() {},
|
459
|
+
modalMessage: 'Retrieving Document...',
|
460
|
+
frameId: 'printJS',
|
461
|
+
printableElement: null,
|
462
|
+
documentTitle: 'Document',
|
463
|
+
targetStyle: ['clear', 'display', 'width', 'min-width', 'height', 'min-height', 'max-height'],
|
464
|
+
targetStyles: ['border', 'box', 'break', 'text-decoration'],
|
465
|
+
ignoreElements: [],
|
466
|
+
repeatTableHeader: true,
|
467
|
+
css: null,
|
468
|
+
style: null,
|
469
|
+
scanStyles: true,
|
470
|
+
base64: false,
|
471
|
+
// Deprecated
|
472
|
+
onPdfOpen: null,
|
473
|
+
font: 'TimesNewRoman',
|
474
|
+
font_size: '12pt',
|
475
|
+
honorMarginPadding: true,
|
476
|
+
honorColor: false,
|
477
|
+
imageStyle: 'max-width: 100%;'
|
478
|
+
}; // Check if a printable document or object was supplied
|
479
|
+
|
480
|
+
var args = arguments[0];
|
481
|
+
|
482
|
+
if (args === undefined) {
|
483
|
+
throw new Error('printJS expects at least 1 attribute.');
|
484
|
+
} // Process parameters
|
485
|
+
|
486
|
+
|
487
|
+
switch (_typeof(args)) {
|
488
|
+
case 'string':
|
489
|
+
params.printable = encodeURI(args);
|
490
|
+
params.fallbackPrintable = params.printable;
|
491
|
+
params.type = arguments[1] || params.type;
|
492
|
+
break;
|
493
|
+
|
494
|
+
case 'object':
|
495
|
+
params.printable = args.printable;
|
496
|
+
params.fallbackPrintable = typeof args.fallbackPrintable !== 'undefined' ? args.fallbackPrintable : params.printable;
|
497
|
+
params.fallbackPrintable = params.base64 ? "data:application/pdf;base64,".concat(params.fallbackPrintable) : params.fallbackPrintable;
|
498
|
+
|
499
|
+
for (var k in params) {
|
500
|
+
if (k === 'printable' || k === 'fallbackPrintable') continue;
|
501
|
+
params[k] = typeof args[k] !== 'undefined' ? args[k] : params[k];
|
502
|
+
}
|
503
|
+
|
504
|
+
break;
|
505
|
+
|
506
|
+
default:
|
507
|
+
throw new Error('Unexpected argument type! Expected "string" or "object", got ' + _typeof(args));
|
508
|
+
} // Validate printable
|
509
|
+
|
510
|
+
|
511
|
+
if (!params.printable) throw new Error('Missing printable information.'); // Validate type
|
512
|
+
|
513
|
+
if (!params.type || typeof params.type !== 'string' || printTypes.indexOf(params.type.toLowerCase()) === -1) {
|
514
|
+
throw new Error('Invalid print type. Available types are: pdf, html, image and json.');
|
515
|
+
} // Check if we are showing a feedback message to the user (useful for large files)
|
516
|
+
|
517
|
+
|
518
|
+
if (params.showModal) _modal__WEBPACK_IMPORTED_MODULE_1__["default"].show(params); // Check for a print start hook function
|
519
|
+
|
520
|
+
if (params.onLoadingStart) params.onLoadingStart(); // To prevent duplication and issues, remove any used printFrame from the DOM
|
521
|
+
|
522
|
+
var usedFrame = document.getElementById(params.frameId);
|
523
|
+
if (usedFrame) usedFrame.parentNode.removeChild(usedFrame); // Create a new iframe for the print job
|
524
|
+
|
525
|
+
var printFrame = document.createElement('iframe');
|
526
|
+
|
527
|
+
if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isFirefox()) {
|
528
|
+
// Set the iframe to be is visible on the page (guaranteed by fixed position) but hidden using opacity 0, because
|
529
|
+
// this works in Firefox. The height needs to be sufficient for some part of the document other than the PDF
|
530
|
+
// viewer's toolbar to be visible in the page
|
531
|
+
printFrame.setAttribute('style', 'width: 1px; height: 100px; position: fixed; left: 0; top: 0; opacity: 0; border-width: 0; margin: 0; padding: 0');
|
532
|
+
} else {
|
533
|
+
// Hide the iframe in other browsers
|
534
|
+
printFrame.setAttribute('style', 'visibility: hidden; height: 0; width: 0; position: absolute; border: 0');
|
535
|
+
} // Set iframe element id
|
536
|
+
|
537
|
+
|
538
|
+
printFrame.setAttribute('id', params.frameId); // For non pdf printing, pass an html document string to srcdoc (force onload callback)
|
539
|
+
|
540
|
+
if (params.type !== 'pdf') {
|
541
|
+
printFrame.srcdoc = '<html><head><title>' + params.documentTitle + '</title>'; // Attach css files
|
542
|
+
|
543
|
+
if (params.css) {
|
544
|
+
// Add support for single file
|
545
|
+
if (!Array.isArray(params.css)) params.css = [params.css]; // Create link tags for each css file
|
546
|
+
|
547
|
+
params.css.forEach(function (file) {
|
548
|
+
printFrame.srcdoc += '<link rel="stylesheet" href="' + file + '">';
|
549
|
+
});
|
550
|
+
}
|
551
|
+
|
552
|
+
printFrame.srcdoc += '</head><body></body></html>';
|
553
|
+
} // Check printable type
|
554
|
+
|
555
|
+
|
556
|
+
switch (params.type) {
|
557
|
+
case 'pdf':
|
558
|
+
// Check browser support for pdf and if not supported we will just open the pdf file instead
|
559
|
+
if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isIE()) {
|
560
|
+
try {
|
561
|
+
console.info('Print.js doesn\'t support PDF printing in Internet Explorer.');
|
562
|
+
var win = window.open(params.fallbackPrintable, '_blank');
|
563
|
+
win.focus();
|
564
|
+
params.onIncompatibleBrowser();
|
565
|
+
} catch (error) {
|
566
|
+
params.onError(error);
|
567
|
+
} finally {
|
568
|
+
// Make sure there is no loading modal opened
|
569
|
+
if (params.showModal) _modal__WEBPACK_IMPORTED_MODULE_1__["default"].close();
|
570
|
+
if (params.onLoadingEnd) params.onLoadingEnd();
|
571
|
+
}
|
572
|
+
} else {
|
573
|
+
_pdf__WEBPACK_IMPORTED_MODULE_2__["default"].print(params, printFrame);
|
574
|
+
}
|
575
|
+
|
576
|
+
break;
|
577
|
+
|
578
|
+
case 'image':
|
579
|
+
_image__WEBPACK_IMPORTED_MODULE_5__["default"].print(params, printFrame);
|
580
|
+
break;
|
581
|
+
|
582
|
+
case 'html':
|
583
|
+
_html__WEBPACK_IMPORTED_MODULE_3__["default"].print(params, printFrame);
|
584
|
+
break;
|
585
|
+
|
586
|
+
case 'raw-html':
|
587
|
+
_raw_html__WEBPACK_IMPORTED_MODULE_4__["default"].print(params, printFrame);
|
588
|
+
break;
|
589
|
+
|
590
|
+
case 'json':
|
591
|
+
_json__WEBPACK_IMPORTED_MODULE_6__["default"].print(params, printFrame);
|
592
|
+
break;
|
593
|
+
}
|
594
|
+
}
|
595
|
+
});
|
596
|
+
|
597
|
+
/***/ }),
|
598
|
+
|
599
|
+
/***/ "./src/js/json.js":
|
600
|
+
/*!************************!*\
|
601
|
+
!*** ./src/js/json.js ***!
|
602
|
+
\************************/
|
603
|
+
/*! exports provided: default */
|
604
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
605
|
+
|
606
|
+
"use strict";
|
607
|
+
__webpack_require__.r(__webpack_exports__);
|
608
|
+
/* harmony import */ var _functions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./functions */ "./src/js/functions.js");
|
609
|
+
/* harmony import */ var _print__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./print */ "./src/js/print.js");
|
610
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
611
|
+
|
612
|
+
|
613
|
+
|
614
|
+
/* harmony default export */ __webpack_exports__["default"] = ({
|
615
|
+
print: function print(params, printFrame) {
|
616
|
+
// Check if we received proper data
|
617
|
+
if (_typeof(params.printable) !== 'object') {
|
618
|
+
throw new Error('Invalid javascript data object (JSON).');
|
619
|
+
} // Validate repeatTableHeader
|
620
|
+
|
621
|
+
|
622
|
+
if (typeof params.repeatTableHeader !== 'boolean') {
|
623
|
+
throw new Error('Invalid value for repeatTableHeader attribute (JSON).');
|
624
|
+
} // Validate properties
|
625
|
+
|
626
|
+
|
627
|
+
if (!params.properties || !Array.isArray(params.properties)) {
|
628
|
+
throw new Error('Invalid properties array for your JSON data.');
|
629
|
+
} // We will format the property objects to keep the JSON api compatible with older releases
|
630
|
+
|
631
|
+
|
632
|
+
params.properties = params.properties.map(function (property) {
|
633
|
+
return {
|
634
|
+
field: _typeof(property) === 'object' ? property.field : property,
|
635
|
+
displayName: _typeof(property) === 'object' ? property.displayName : property,
|
636
|
+
columnSize: _typeof(property) === 'object' && property.columnSize ? property.columnSize + ';' : 100 / params.properties.length + '%;'
|
637
|
+
};
|
638
|
+
}); // Create a print container element
|
639
|
+
|
640
|
+
params.printableElement = document.createElement('div'); // Check if we are adding a print header
|
641
|
+
|
642
|
+
if (params.header) {
|
643
|
+
Object(_functions__WEBPACK_IMPORTED_MODULE_0__["addHeader"])(params.printableElement, params);
|
644
|
+
} // Build the printable html data
|
645
|
+
|
646
|
+
|
647
|
+
params.printableElement.innerHTML += jsonToHTML(params); // Print the json data
|
648
|
+
|
649
|
+
_print__WEBPACK_IMPORTED_MODULE_1__["default"].send(params, printFrame);
|
650
|
+
}
|
651
|
+
});
|
652
|
+
|
653
|
+
function jsonToHTML(params) {
|
654
|
+
// Get the row and column data
|
655
|
+
var data = params.printable;
|
656
|
+
var properties = params.properties; // Create a html table
|
657
|
+
|
658
|
+
var htmlData = '<table style="border-collapse: collapse; width: 100%;">'; // Check if the header should be repeated
|
659
|
+
|
660
|
+
if (params.repeatTableHeader) {
|
661
|
+
htmlData += '<thead>';
|
662
|
+
} // Add the table header row
|
663
|
+
|
664
|
+
|
665
|
+
htmlData += '<tr>'; // Add the table header columns
|
666
|
+
|
667
|
+
for (var a = 0; a < properties.length; a++) {
|
668
|
+
htmlData += '<th style="width:' + properties[a].columnSize + ';' + params.gridHeaderStyle + '">' + Object(_functions__WEBPACK_IMPORTED_MODULE_0__["capitalizePrint"])(properties[a].displayName) + '</th>';
|
669
|
+
} // Add the closing tag for the table header row
|
670
|
+
|
671
|
+
|
672
|
+
htmlData += '</tr>'; // If the table header is marked as repeated, add the closing tag
|
673
|
+
|
674
|
+
if (params.repeatTableHeader) {
|
675
|
+
htmlData += '</thead>';
|
676
|
+
} // Create the table body
|
677
|
+
|
678
|
+
|
679
|
+
htmlData += '<tbody>'; // Add the table data rows
|
680
|
+
|
681
|
+
for (var i = 0; i < data.length; i++) {
|
682
|
+
// Add the row starting tag
|
683
|
+
htmlData += '<tr>'; // Print selected properties only
|
684
|
+
|
685
|
+
for (var n = 0; n < properties.length; n++) {
|
686
|
+
var stringData = data[i]; // Support nested objects
|
687
|
+
|
688
|
+
var property = properties[n].field.split('.');
|
689
|
+
|
690
|
+
if (property.length > 1) {
|
691
|
+
for (var p = 0; p < property.length; p++) {
|
692
|
+
stringData = stringData[property[p]];
|
693
|
+
}
|
694
|
+
} else {
|
695
|
+
stringData = stringData[properties[n].field];
|
696
|
+
} // Add the row contents and styles
|
697
|
+
|
698
|
+
|
699
|
+
htmlData += '<td style="width:' + properties[n].columnSize + params.gridStyle + '">' + stringData + '</td>';
|
700
|
+
} // Add the row closing tag
|
701
|
+
|
702
|
+
|
703
|
+
htmlData += '</tr>';
|
704
|
+
} // Add the table and body closing tags
|
705
|
+
|
706
|
+
|
707
|
+
htmlData += '</tbody></table>';
|
708
|
+
return htmlData;
|
709
|
+
}
|
710
|
+
|
711
|
+
/***/ }),
|
712
|
+
|
713
|
+
/***/ "./src/js/modal.js":
|
714
|
+
/*!*************************!*\
|
715
|
+
!*** ./src/js/modal.js ***!
|
716
|
+
\*************************/
|
717
|
+
/*! exports provided: default */
|
718
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
719
|
+
|
720
|
+
"use strict";
|
721
|
+
__webpack_require__.r(__webpack_exports__);
|
722
|
+
var Modal = {
|
723
|
+
show: function show(params) {
|
724
|
+
// Build modal
|
725
|
+
var modalStyle = 'font-family:sans-serif; ' + 'display:table; ' + 'text-align:center; ' + 'font-weight:300; ' + 'font-size:30px; ' + 'left:0; top:0;' + 'position:fixed; ' + 'z-index: 9990;' + 'color: #0460B5; ' + 'width: 100%; ' + 'height: 100%; ' + 'background-color:rgba(255,255,255,.9);' + 'transition: opacity .3s ease;'; // Create wrapper
|
726
|
+
|
727
|
+
var printModal = document.createElement('div');
|
728
|
+
printModal.setAttribute('style', modalStyle);
|
729
|
+
printModal.setAttribute('id', 'printJS-Modal'); // Create content div
|
730
|
+
|
731
|
+
var contentDiv = document.createElement('div');
|
732
|
+
contentDiv.setAttribute('style', 'display:table-cell; vertical-align:middle; padding-bottom:100px;'); // Add close button (requires print.css)
|
733
|
+
|
734
|
+
var closeButton = document.createElement('div');
|
735
|
+
closeButton.setAttribute('class', 'printClose');
|
736
|
+
closeButton.setAttribute('id', 'printClose');
|
737
|
+
contentDiv.appendChild(closeButton); // Add spinner (requires print.css)
|
738
|
+
|
739
|
+
var spinner = document.createElement('span');
|
740
|
+
spinner.setAttribute('class', 'printSpinner');
|
741
|
+
contentDiv.appendChild(spinner); // Add message
|
742
|
+
|
743
|
+
var messageNode = document.createTextNode(params.modalMessage);
|
744
|
+
contentDiv.appendChild(messageNode); // Add contentDiv to printModal
|
745
|
+
|
746
|
+
printModal.appendChild(contentDiv); // Append print modal element to document body
|
747
|
+
|
748
|
+
document.getElementsByTagName('body')[0].appendChild(printModal); // Add event listener to close button
|
749
|
+
|
750
|
+
document.getElementById('printClose').addEventListener('click', function () {
|
751
|
+
Modal.close();
|
752
|
+
});
|
753
|
+
},
|
754
|
+
close: function close() {
|
755
|
+
var printModal = document.getElementById('printJS-Modal');
|
756
|
+
|
757
|
+
if (printModal) {
|
758
|
+
printModal.parentNode.removeChild(printModal);
|
759
|
+
}
|
760
|
+
}
|
761
|
+
};
|
762
|
+
/* harmony default export */ __webpack_exports__["default"] = (Modal);
|
763
|
+
|
764
|
+
/***/ }),
|
765
|
+
|
766
|
+
/***/ "./src/js/pdf.js":
|
767
|
+
/*!***********************!*\
|
768
|
+
!*** ./src/js/pdf.js ***!
|
769
|
+
\***********************/
|
770
|
+
/*! exports provided: default */
|
771
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
772
|
+
|
773
|
+
"use strict";
|
774
|
+
__webpack_require__.r(__webpack_exports__);
|
775
|
+
/* harmony import */ var _print__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./print */ "./src/js/print.js");
|
776
|
+
/* harmony import */ var _functions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./functions */ "./src/js/functions.js");
|
777
|
+
|
778
|
+
|
779
|
+
/* harmony default export */ __webpack_exports__["default"] = ({
|
780
|
+
print: function print(params, printFrame) {
|
781
|
+
// Check if we have base64 data
|
782
|
+
if (params.base64) {
|
783
|
+
var bytesArray = Uint8Array.from(atob(params.printable), function (c) {
|
784
|
+
return c.charCodeAt(0);
|
785
|
+
});
|
786
|
+
createBlobAndPrint(params, printFrame, bytesArray);
|
787
|
+
return;
|
788
|
+
} // Format pdf url
|
789
|
+
|
790
|
+
|
791
|
+
params.printable = /^(blob|http|\/\/)/i.test(params.printable) ? params.printable : window.location.origin + (params.printable.charAt(0) !== '/' ? '/' + params.printable : params.printable); // Get the file through a http request (Preload)
|
792
|
+
|
793
|
+
var req = new window.XMLHttpRequest();
|
794
|
+
req.responseType = 'arraybuffer';
|
795
|
+
req.addEventListener('error', function () {
|
796
|
+
Object(_functions__WEBPACK_IMPORTED_MODULE_1__["cleanUp"])(params);
|
797
|
+
params.onError(req.statusText, req); // Since we don't have a pdf document available, we will stop the print job
|
798
|
+
});
|
799
|
+
req.addEventListener('load', function () {
|
800
|
+
// Check for errors
|
801
|
+
if ([200, 201].indexOf(req.status) === -1) {
|
802
|
+
Object(_functions__WEBPACK_IMPORTED_MODULE_1__["cleanUp"])(params);
|
803
|
+
params.onError(req.statusText, req); // Since we don't have a pdf document available, we will stop the print job
|
804
|
+
|
805
|
+
return;
|
806
|
+
} // Print requested document
|
807
|
+
|
808
|
+
|
809
|
+
createBlobAndPrint(params, printFrame, req.response);
|
810
|
+
});
|
811
|
+
req.open('GET', params.printable, true);
|
812
|
+
req.send();
|
813
|
+
}
|
814
|
+
});
|
815
|
+
|
816
|
+
function createBlobAndPrint(params, printFrame, data) {
|
817
|
+
// Pass response or base64 data to a blob and create a local object url
|
818
|
+
var localPdf = new window.Blob([data], {
|
819
|
+
type: 'application/pdf'
|
820
|
+
});
|
821
|
+
localPdf = window.URL.createObjectURL(localPdf); // Set iframe src with pdf document url
|
822
|
+
|
823
|
+
printFrame.setAttribute('src', localPdf);
|
824
|
+
_print__WEBPACK_IMPORTED_MODULE_0__["default"].send(params, printFrame);
|
825
|
+
}
|
826
|
+
|
827
|
+
/***/ }),
|
828
|
+
|
829
|
+
/***/ "./src/js/print.js":
|
830
|
+
/*!*************************!*\
|
831
|
+
!*** ./src/js/print.js ***!
|
832
|
+
\*************************/
|
833
|
+
/*! exports provided: default */
|
834
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
835
|
+
|
836
|
+
"use strict";
|
837
|
+
__webpack_require__.r(__webpack_exports__);
|
838
|
+
/* harmony import */ var _browser__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./browser */ "./src/js/browser.js");
|
839
|
+
/* harmony import */ var _functions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./functions */ "./src/js/functions.js");
|
840
|
+
|
841
|
+
|
842
|
+
var Print = {
|
843
|
+
send: function send(params, printFrame) {
|
844
|
+
// Append iframe element to document body
|
845
|
+
document.getElementsByTagName('body')[0].appendChild(printFrame); // Get iframe element
|
846
|
+
|
847
|
+
var iframeElement = document.getElementById(params.frameId); // Wait for iframe to load all content
|
848
|
+
|
849
|
+
iframeElement.onload = function () {
|
850
|
+
if (params.type === 'pdf') {
|
851
|
+
// Add a delay for Firefox. In my tests, 1000ms was sufficient but 100ms was not
|
852
|
+
if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isFirefox()) {
|
853
|
+
setTimeout(function () {
|
854
|
+
return performPrint(iframeElement, params);
|
855
|
+
}, 1000);
|
856
|
+
} else {
|
857
|
+
performPrint(iframeElement, params);
|
858
|
+
}
|
859
|
+
|
860
|
+
return;
|
861
|
+
} // Get iframe element document
|
862
|
+
|
863
|
+
|
864
|
+
var printDocument = iframeElement.contentWindow || iframeElement.contentDocument;
|
865
|
+
if (printDocument.document) printDocument = printDocument.document; // Append printable element to the iframe body
|
866
|
+
|
867
|
+
printDocument.body.appendChild(params.printableElement); // Add custom style
|
868
|
+
|
869
|
+
if (params.type !== 'pdf' && params.style) {
|
870
|
+
// Create style element
|
871
|
+
var style = document.createElement('style');
|
872
|
+
style.innerHTML = params.style; // Append style element to iframe's head
|
873
|
+
|
874
|
+
printDocument.head.appendChild(style);
|
875
|
+
} // If printing images, wait for them to load inside the iframe
|
876
|
+
|
877
|
+
|
878
|
+
var images = printDocument.getElementsByTagName('img');
|
879
|
+
|
880
|
+
if (images.length > 0) {
|
881
|
+
loadIframeImages(Array.from(images)).then(function () {
|
882
|
+
return performPrint(iframeElement, params);
|
883
|
+
});
|
884
|
+
} else {
|
885
|
+
performPrint(iframeElement, params);
|
886
|
+
}
|
887
|
+
};
|
888
|
+
}
|
889
|
+
};
|
890
|
+
|
891
|
+
function performPrint(iframeElement, params) {
|
892
|
+
try {
|
893
|
+
iframeElement.focus(); // If Edge or IE, try catch with execCommand
|
894
|
+
|
895
|
+
if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isEdge() || _browser__WEBPACK_IMPORTED_MODULE_0__["default"].isIE()) {
|
896
|
+
try {
|
897
|
+
iframeElement.contentWindow.document.execCommand('print', false, null);
|
898
|
+
} catch (e) {
|
899
|
+
iframeElement.contentWindow.print();
|
900
|
+
}
|
901
|
+
} else {
|
902
|
+
// Other browsers
|
903
|
+
iframeElement.contentWindow.print();
|
904
|
+
}
|
905
|
+
} catch (error) {
|
906
|
+
params.onError(error);
|
907
|
+
} finally {
|
908
|
+
if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isFirefox()) {
|
909
|
+
// Move the iframe element off-screen and make it invisible
|
910
|
+
iframeElement.style.visibility = 'hidden';
|
911
|
+
iframeElement.style.left = '-1px';
|
912
|
+
}
|
913
|
+
|
914
|
+
Object(_functions__WEBPACK_IMPORTED_MODULE_1__["cleanUp"])(params);
|
915
|
+
}
|
916
|
+
}
|
917
|
+
|
918
|
+
function loadIframeImages(images) {
|
919
|
+
var promises = images.map(function (image) {
|
920
|
+
if (image.src && image.src !== window.location.href) {
|
921
|
+
return loadIframeImage(image);
|
922
|
+
}
|
923
|
+
});
|
924
|
+
return Promise.all(promises);
|
925
|
+
}
|
926
|
+
|
927
|
+
function loadIframeImage(image) {
|
928
|
+
return new Promise(function (resolve) {
|
929
|
+
var pollImage = function pollImage() {
|
930
|
+
!image || typeof image.naturalWidth === 'undefined' || image.naturalWidth === 0 || !image.complete ? setTimeout(pollImage, 500) : resolve();
|
931
|
+
};
|
932
|
+
|
933
|
+
pollImage();
|
934
|
+
});
|
935
|
+
}
|
936
|
+
|
937
|
+
/* harmony default export */ __webpack_exports__["default"] = (Print);
|
938
|
+
|
939
|
+
/***/ }),
|
940
|
+
|
941
|
+
/***/ "./src/js/raw-html.js":
|
942
|
+
/*!****************************!*\
|
943
|
+
!*** ./src/js/raw-html.js ***!
|
944
|
+
\****************************/
|
945
|
+
/*! exports provided: default */
|
946
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
947
|
+
|
948
|
+
"use strict";
|
949
|
+
__webpack_require__.r(__webpack_exports__);
|
950
|
+
/* harmony import */ var _print__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./print */ "./src/js/print.js");
|
951
|
+
|
952
|
+
/* harmony default export */ __webpack_exports__["default"] = ({
|
953
|
+
print: function print(params, printFrame) {
|
954
|
+
// Create printable element (container)
|
955
|
+
params.printableElement = document.createElement('div');
|
956
|
+
params.printableElement.setAttribute('style', 'width:100%'); // Set our raw html as the printable element inner html content
|
957
|
+
|
958
|
+
params.printableElement.innerHTML = params.printable; // Print html contents
|
959
|
+
|
960
|
+
_print__WEBPACK_IMPORTED_MODULE_0__["default"].send(params, printFrame);
|
961
|
+
}
|
962
|
+
});
|
963
|
+
|
964
|
+
/***/ }),
|
965
|
+
|
966
|
+
/***/ "./src/sass/index.scss":
|
967
|
+
/*!*****************************!*\
|
968
|
+
!*** ./src/sass/index.scss ***!
|
969
|
+
\*****************************/
|
970
|
+
/*! no static exports found */
|
971
|
+
/***/ (function(module, exports, __webpack_require__) {
|
972
|
+
|
973
|
+
// extracted by mini-css-extract-plugin
|
974
|
+
|
975
|
+
/***/ }),
|
976
|
+
|
977
|
+
/***/ 0:
|
978
|
+
/*!****************************!*\
|
979
|
+
!*** multi ./src/index.js ***!
|
980
|
+
\****************************/
|
981
|
+
/*! no static exports found */
|
982
|
+
/***/ (function(module, exports, __webpack_require__) {
|
983
|
+
|
984
|
+
module.exports = __webpack_require__(/*! ./src/index.js */"./src/index.js");
|
985
|
+
|
986
|
+
|
987
|
+
/***/ })
|
988
|
+
|
989
|
+
/******/ })["default"];
|
990
|
+
});
|
991
|
+
//# sourceMappingURL=print.map
|