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("print-js", [], factory);
|
6 | else if(typeof exports === 'object')
|
7 | exports["print-js"] = factory();
|
8 | else
|
9 | root["print-js"] = factory();
|
10 | })(this, function() {
|
11 | return (function(modules) {
|
12 |
|
13 | var installedModules = {};
|
14 |
|
15 |
|
16 | function __webpack_require__(moduleId) {
|
17 |
|
18 |
|
19 | if(installedModules[moduleId]) {
|
20 | return installedModules[moduleId].exports;
|
21 | }
|
22 |
|
23 | var module = installedModules[moduleId] = {
|
24 | i: moduleId,
|
25 | l: false,
|
26 | exports: {}
|
27 | };
|
28 |
|
29 |
|
30 | modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
31 |
|
32 |
|
33 | module.l = true;
|
34 |
|
35 |
|
36 | return module.exports;
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 | __webpack_require__.m = modules;
|
42 |
|
43 |
|
44 | __webpack_require__.c = installedModules;
|
45 |
|
46 |
|
47 | __webpack_require__.i = function(value) { return value; };
|
48 |
|
49 |
|
50 | __webpack_require__.d = function(exports, name, getter) {
|
51 | if(!__webpack_require__.o(exports, name)) {
|
52 | Object.defineProperty(exports, name, {
|
53 | configurable: false,
|
54 | enumerable: true,
|
55 | get: getter
|
56 | /******/ });
|
57 | /******/ }
|
58 | /******/ };
|
59 | /******/
|
60 | /******/ // getDefaultExport function for compatibility with non-harmony modules
|
61 | /******/ __webpack_require__.n = function(module) {
|
62 | var getter = module && module.__esModule ?
|
63 | function getDefault() { return module['default']; } :
|
64 | function getModuleExports() { return module; };
|
65 | __webpack_require__.d(getter, 'a', getter);
|
66 | return getter;
|
67 | };
|
68 |
|
69 |
|
70 | __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
71 |
|
72 |
|
73 | __webpack_require__.p = "./";
|
74 |
|
75 |
|
76 | return __webpack_require__(__webpack_require__.s = 10);
|
77 | })
|
78 |
|
79 | ([
|
80 |
|
81 | (function(module, __webpack_exports__, __webpack_require__) {
|
82 |
|
83 | "use strict";
|
84 | var __WEBPACK_IMPORTED_MODULE_0__browser__ = __webpack_require__(2);
|
85 | var __WEBPACK_IMPORTED_MODULE_1__modal__ = __webpack_require__(3);
|
86 |
|
87 |
|
88 |
|
89 | var Print = {
|
90 | send: function send(params, printFrame) {
|
91 |
|
92 | document.getElementsByTagName('body')[0].appendChild(printFrame);
|
93 |
|
94 |
|
95 | var iframeElement = document.getElementById(params.frameId);
|
96 |
|
97 |
|
98 | if (params.type === 'pdf' && (__WEBPACK_IMPORTED_MODULE_0__browser__["a" ].isIE() || __WEBPACK_IMPORTED_MODULE_0__browser__["a" ].isEdge())) {
|
99 | iframeElement.setAttribute('onload', finishPrint(iframeElement, params));
|
100 | } else {
|
101 | printFrame.onload = function () {
|
102 | if (params.type === 'pdf') {
|
103 | finishPrint(iframeElement, params);
|
104 | } else {
|
105 |
|
106 | var printDocument = iframeElement.contentWindow || iframeElement.contentDocument;
|
107 | if (printDocument.document) printDocument = printDocument.document;
|
108 |
|
109 |
|
110 | printDocument.body.innerHTML = params.htmlData;
|
111 |
|
112 |
|
113 | if (params.type !== 'pdf' && params.style !== null) {
|
114 |
|
115 | var style = document.createElement('style');
|
116 | style.innerHTML = params.style;
|
117 |
|
118 |
|
119 | printDocument.head.appendChild(style);
|
120 | }
|
121 |
|
122 |
|
123 | if (params.type === 'image') {
|
124 | loadIframeImages(printDocument, params).then(function () {
|
125 | finishPrint(iframeElement, params);
|
126 | });
|
127 | } else {
|
128 | finishPrint(iframeElement, params);
|
129 | }
|
130 | }
|
131 | };
|
132 | }
|
133 | }
|
134 | };
|
135 |
|
136 | function finishPrint(iframeElement, params) {
|
137 | iframeElement.focus();
|
138 |
|
139 |
|
140 | if (__WEBPACK_IMPORTED_MODULE_0__browser__["a" ].isEdge() || __WEBPACK_IMPORTED_MODULE_0__browser__["a" ].isIE()) {
|
141 | try {
|
142 | iframeElement.contentWindow.document.execCommand('print', false, null);
|
143 | } catch (e) {
|
144 | iframeElement.contentWindow.print();
|
145 | }
|
146 | } else {
|
147 |
|
148 | iframeElement.contentWindow.print();
|
149 | }
|
150 |
|
151 |
|
152 | if (params.showModal) __WEBPACK_IMPORTED_MODULE_1__modal__["a" ].close();
|
153 |
|
154 |
|
155 | if (params.onLoadingEnd) params.onLoadingEnd();
|
156 |
|
157 |
|
158 | if (params.showModal || params.onLoadingStart) window.URL.revokeObjectURL(params.printable);
|
159 | }
|
160 |
|
161 | function loadIframeImages(printDocument, params) {
|
162 | var promises = [];
|
163 |
|
164 | params.printable.forEach(function (image, index) {
|
165 | return promises.push(loadIframeImage(printDocument, index));
|
166 | });
|
167 |
|
168 | return Promise.all(promises);
|
169 | }
|
170 |
|
171 | function loadIframeImage(printDocument, index) {
|
172 | return new Promise(function (resolve) {
|
173 | var image = printDocument ? printDocument.getElementById('printableImage' + index) : null;
|
174 |
|
175 | if (!image || typeof image.naturalWidth === 'undefined' || image.naturalWidth === 0) {
|
176 | setTimeout(function () {
|
177 | loadIframeImage(printDocument, index);
|
178 | }, 500);
|
179 | } else {
|
180 | resolve();
|
181 | }
|
182 | });
|
183 | }
|
184 |
|
185 | __webpack_exports__["a"] = (Print);
|
186 |
|
187 | }),
|
188 |
|
189 | (function(module, __webpack_exports__, __webpack_require__) {
|
190 |
|
191 | "use strict";
|
192 | __webpack_exports__["a"] = addWrapper;
|
193 | __webpack_exports__["b"] = capitalizePrint;
|
194 | __webpack_exports__["c"] = collectStyles;
|
195 | __webpack_exports__["d"] = loopNodesCollectStyles;
|
196 | __webpack_exports__["e"] = addHeader;
|
197 | function addWrapper(htmlData, params) {
|
198 | var bodyStyle = 'font-family:' + params.font + ' !important; font-size: ' + params.font_size + ' !important; width:100%;';
|
199 | return '<div style="' + bodyStyle + '">' + htmlData + '</div>';
|
200 | }
|
201 |
|
202 | function capitalizePrint(string) {
|
203 | return string.charAt(0).toUpperCase() + string.slice(1);
|
204 | }
|
205 |
|
206 | function collectStyles(element, params) {
|
207 | var win = document.defaultView || window;
|
208 |
|
209 | var styles = win.getComputedStyle;
|
210 |
|
211 |
|
212 | var elementStyle = '';
|
213 |
|
214 |
|
215 | if (params.honorMarginPadding) params.targetStyles.push('margin', 'padding');
|
216 |
|
217 |
|
218 | if (params.honorColor) params.targetStyles.push('color');
|
219 |
|
220 |
|
221 | styles = win.getComputedStyle(element, '');
|
222 |
|
223 | Object.keys(styles).map(function (key) {
|
224 |
|
225 | if (params.targetStyles === ['*'] || params.targetStyle.indexOf(styles[key]) !== -1 || targetStylesMatch(params.targetStyles, styles[key])) {
|
226 | elementStyle += styles[key] + ':' + styles.getPropertyValue(styles[key]) + ';';
|
227 | }
|
228 | });
|
229 |
|
230 |
|
231 | elementStyle += 'max-width: ' + params.maxWidth + 'px !important;' + params.font_size + ' !important;';
|
232 |
|
233 | return elementStyle;
|
234 | }
|
235 |
|
236 | function targetStylesMatch(styles, value) {
|
237 | for (var i = 0; i < styles.length; i++) {
|
238 | if (value.indexOf(styles[i]) !== -1) return true;
|
239 | }
|
240 | return false;
|
241 | }
|
242 |
|
243 | function loopNodesCollectStyles(elements, params) {
|
244 | for (var n = 0; n < elements.length; n++) {
|
245 | var currentElement = elements[n];
|
246 |
|
247 |
|
248 | if (params.ignoreElements.indexOf(currentElement.getAttribute('id')) !== -1) {
|
249 | currentElement.parentNode.removeChild(currentElement);
|
250 | continue;
|
251 | }
|
252 |
|
253 |
|
254 | var tag = currentElement.tagName;
|
255 | if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') {
|
256 |
|
257 | var textStyle = collectStyles(currentElement, params);
|
258 |
|
259 |
|
260 | var parent = currentElement.parentNode;
|
261 |
|
262 |
|
263 | var textNode = tag === 'SELECT' ? document.createTextNode(currentElement.options[currentElement.selectedIndex].text) : document.createTextNode(currentElement.value);
|
264 |
|
265 |
|
266 | var textElement = document.createElement('div');
|
267 | textElement.appendChild(textNode);
|
268 |
|
269 |
|
270 | textElement.setAttribute('style', textStyle);
|
271 |
|
272 |
|
273 | parent.appendChild(textElement);
|
274 |
|
275 |
|
276 | parent.removeChild(currentElement);
|
277 | } else {
|
278 |
|
279 | currentElement.setAttribute('style', collectStyles(currentElement, params));
|
280 | }
|
281 |
|
282 |
|
283 | var children = currentElement.children;
|
284 |
|
285 | if (children && children.length) {
|
286 | loopNodesCollectStyles(children, params);
|
287 | }
|
288 | }
|
289 | }
|
290 |
|
291 | function addHeader(printElement, header, headerStyle) {
|
292 |
|
293 | var headerElement = document.createElement('h1');
|
294 |
|
295 |
|
296 | var headerNode = document.createTextNode(header);
|
297 |
|
298 |
|
299 | headerElement.appendChild(headerNode);
|
300 | headerElement.setAttribute('style', headerStyle);
|
301 |
|
302 | printElement.insertBefore(headerElement, printElement.childNodes[0]);
|
303 | }
|
304 |
|
305 | }),
|
306 |
|
307 | (function(module, __webpack_exports__, __webpack_require__) {
|
308 |
|
309 | "use strict";
|
310 | var Browser = {
|
311 |
|
312 | isFirefox: function isFirefox() {
|
313 | return typeof InstallTrigger !== 'undefined';
|
314 | },
|
315 |
|
316 | isIE: function isIE() {
|
317 | return navigator.userAgent.indexOf('MSIE') !== -1 || !!document.documentMode;
|
318 | },
|
319 |
|
320 | isEdge: function isEdge() {
|
321 | return !Browser.isIE() && !!window.StyleMedia;
|
322 | },
|
323 |
|
324 | isChrome: function isChrome() {
|
325 | return !!window.chrome && !!window.chrome.webstore;
|
326 | },
|
327 |
|
328 | isSafari: function isSafari() {
|
329 | return Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 || navigator.userAgent.toLowerCase().indexOf('safari') !== -1;
|
330 | }
|
331 | };
|
332 |
|
333 | __webpack_exports__["a"] = (Browser);
|
334 |
|
335 | }),
|
336 |
|
337 | (function(module, __webpack_exports__, __webpack_require__) {
|
338 |
|
339 | "use strict";
|
340 | var Modal = {
|
341 | show: function show(params) {
|
342 |
|
343 | 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;';
|
344 |
|
345 |
|
346 | var printModal = document.createElement('div');
|
347 | printModal.setAttribute('style', modalStyle);
|
348 | printModal.setAttribute('id', 'printJS-Modal');
|
349 |
|
350 |
|
351 | var contentDiv = document.createElement('div');
|
352 | contentDiv.setAttribute('style', 'display:table-cell; vertical-align:middle; padding-bottom:100px;');
|
353 |
|
354 |
|
355 | var closeButton = document.createElement('div');
|
356 | closeButton.setAttribute('class', 'printClose');
|
357 | closeButton.setAttribute('id', 'printClose');
|
358 | contentDiv.appendChild(closeButton);
|
359 |
|
360 |
|
361 | var spinner = document.createElement('span');
|
362 | spinner.setAttribute('class', 'printSpinner');
|
363 | contentDiv.appendChild(spinner);
|
364 |
|
365 |
|
366 | var messageNode = document.createTextNode(params.modalMessage);
|
367 | contentDiv.appendChild(messageNode);
|
368 |
|
369 |
|
370 | printModal.appendChild(contentDiv);
|
371 |
|
372 |
|
373 | document.getElementsByTagName('body')[0].appendChild(printModal);
|
374 |
|
375 |
|
376 | document.getElementById('printClose').addEventListener('click', function () {
|
377 | Modal.close();
|
378 | });
|
379 | },
|
380 | close: function close() {
|
381 | var printFrame = document.getElementById('printJS-Modal');
|
382 |
|
383 | printFrame.parentNode.removeChild(printFrame);
|
384 | }
|
385 | };
|
386 |
|
387 | __webpack_exports__["a"] = (Modal);
|
388 |
|
389 | }),
|
390 |
|
391 | (function(module, __webpack_exports__, __webpack_require__) {
|
392 |
|
393 | "use strict";
|
394 | Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
|
395 | var __WEBPACK_IMPORTED_MODULE_0__js_init__ = __webpack_require__(7);
|
396 |
|
397 |
|
398 | var printjs = __WEBPACK_IMPORTED_MODULE_0__js_init__["a" ].init;
|
399 |
|
400 | if (typeof window !== 'undefined') {
|
401 | window.printJS = printjs;
|
402 | }
|
403 |
|
404 | __webpack_exports__["default"] = (printjs);
|
405 |
|
406 | }),
|
407 |
|
408 | (function(module, __webpack_exports__, __webpack_require__) {
|
409 |
|
410 | "use strict";
|
411 | var __WEBPACK_IMPORTED_MODULE_0__functions__ = __webpack_require__(1);
|
412 | var __WEBPACK_IMPORTED_MODULE_1__print__ = __webpack_require__(0);
|
413 |
|
414 |
|
415 |
|
416 | __webpack_exports__["a"] = ({
|
417 | print: function print(params, printFrame) {
|
418 |
|
419 | var printElement = document.getElementById(params.printable);
|
420 |
|
421 |
|
422 | if (!printElement) {
|
423 | window.console.error('Invalid HTML element id: ' + params.printable);
|
424 |
|
425 | return false;
|
426 | }
|
427 |
|
428 |
|
429 | var printableElement = document.createElement('div');
|
430 | printableElement.appendChild(printElement.cloneNode(true));
|
431 |
|
432 |
|
433 | printableElement.setAttribute('style', 'height:0; overflow:hidden;');
|
434 | printableElement.setAttribute('id', 'printJS-html');
|
435 | printElement.parentNode.appendChild(printableElement);
|
436 |
|
437 |
|
438 | printableElement = document.getElementById('printJS-html');
|
439 |
|
440 |
|
441 | if (params.scanStyles === true) {
|
442 | printableElement.setAttribute('style', __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__functions__["c" ])(printableElement, params) + 'margin:0 !important;');
|
443 | }
|
444 |
|
445 |
|
446 | var elements = printableElement.children;
|
447 |
|
448 |
|
449 | if (params.scanStyles === true) {
|
450 | __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__functions__["d" ])(elements, params);
|
451 | }
|
452 |
|
453 |
|
454 | if (params.header) {
|
455 | __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__functions__["e" ])(printableElement, params.header, params.headerStyle);
|
456 | }
|
457 |
|
458 |
|
459 | printableElement.parentNode.removeChild(printableElement);
|
460 |
|
461 |
|
462 | params.htmlData = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__functions__["a" ])(printableElement.innerHTML, params);
|
463 |
|
464 |
|
465 | __WEBPACK_IMPORTED_MODULE_1__print__["a" ].send(params, printFrame);
|
466 | }
|
467 | });
|
468 |
|
469 | }),
|
470 |
|
471 | (function(module, __webpack_exports__, __webpack_require__) {
|
472 |
|
473 | "use strict";
|
474 | var __WEBPACK_IMPORTED_MODULE_0__functions__ = __webpack_require__(1);
|
475 | var __WEBPACK_IMPORTED_MODULE_1__print__ = __webpack_require__(0);
|
476 |
|
477 |
|
478 |
|
479 | __webpack_exports__["a"] = ({
|
480 | print: function print(params, printFrame) {
|
481 |
|
482 | if (params.printable.constructor !== Array) {
|
483 |
|
484 | params.printable = [params.printable];
|
485 | }
|
486 |
|
487 |
|
488 | var printableElement = document.createElement('div');
|
489 | printableElement.setAttribute('style', 'width:100%');
|
490 |
|
491 |
|
492 | loadImagesAndAppendToPrintableElement(printableElement, params).then(function () {
|
493 |
|
494 | if (params.header) __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__functions__["e" ])(printableElement, params.header, params.headerStyle);
|
495 |
|
496 |
|
497 | params.htmlData = printableElement.outerHTML;
|
498 |
|
499 |
|
500 | __WEBPACK_IMPORTED_MODULE_1__print__["a" ].send(params, printFrame);
|
501 | });
|
502 | }
|
503 | });
|
504 |
|
505 | function loadImagesAndAppendToPrintableElement(printableElement, params) {
|
506 | var promises = [];
|
507 |
|
508 | params.printable.forEach(function (image, index) {
|
509 |
|
510 | var img = document.createElement('img');
|
511 |
|
512 |
|
513 | img.src = image;
|
514 |
|
515 |
|
516 | promises.push(loadImageAndAppendToPrintableElement(printableElement, params, img, index));
|
517 | });
|
518 |
|
519 | return Promise.all(promises);
|
520 | }
|
521 |
|
522 | function loadImageAndAppendToPrintableElement(printableElement, params, img, index) {
|
523 | return new Promise(function (resolve) {
|
524 | img.onload = function () {
|
525 |
|
526 | var imageWrapper = document.createElement('div');
|
527 | imageWrapper.setAttribute('style', params.imageStyle);
|
528 |
|
529 | img.setAttribute('style', 'width:100%;');
|
530 | img.setAttribute('id', 'printableImage' + index);
|
531 |
|
532 |
|
533 | imageWrapper.appendChild(img);
|
534 |
|
535 |
|
536 | printableElement.appendChild(imageWrapper);
|
537 |
|
538 | resolve();
|
539 | };
|
540 | });
|
541 | }
|
542 |
|
543 | }),
|
544 |
|
545 | (function(module, __webpack_exports__, __webpack_require__) {
|
546 |
|
547 | "use strict";
|
548 | var __WEBPACK_IMPORTED_MODULE_0__browser__ = __webpack_require__(2);
|
549 | var __WEBPACK_IMPORTED_MODULE_1__modal__ = __webpack_require__(3);
|
550 | var __WEBPACK_IMPORTED_MODULE_2__pdf__ = __webpack_require__(9);
|
551 | var __WEBPACK_IMPORTED_MODULE_3__html__ = __webpack_require__(5);
|
552 | var __WEBPACK_IMPORTED_MODULE_4__image__ = __webpack_require__(6);
|
553 | var __WEBPACK_IMPORTED_MODULE_5__json__ = __webpack_require__(8);
|
554 |
|
555 |
|
556 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 | var printTypes = ['pdf', 'html', 'image', 'json'];
|
566 |
|
567 | __webpack_exports__["a"] = ({
|
568 | init: function init() {
|
569 | var params = {
|
570 | printable: null,
|
571 | fallbackPrintable: null,
|
572 | type: 'pdf',
|
573 | header: null,
|
574 | headerStyle: 'font-weight: 300;',
|
575 | maxWidth: 800,
|
576 | font: 'TimesNewRoman',
|
577 | font_size: '12pt',
|
578 | honorMarginPadding: true,
|
579 | honorColor: false,
|
580 | properties: null,
|
581 | gridHeaderStyle: 'font-weight: bold; padding: 5px; border: 1px solid #dddddd;',
|
582 | gridStyle: 'border: 1px solid lightgray; margin-bottom: -1px;',
|
583 | showModal: false,
|
584 | onLoadingStart: null,
|
585 | onLoadingEnd: null,
|
586 | modalMessage: 'Retrieving Document...',
|
587 | frameId: 'printJS',
|
588 | htmlData: '',
|
589 | documentTitle: 'Document',
|
590 | targetStyle: ['clear', 'display', 'width', 'min-width', 'height', 'min-height', 'max-height'],
|
591 | targetStyles: ['border', 'box', 'break', 'text-decoration'],
|
592 | ignoreElements: [],
|
593 | imageStyle: 'width:100%;',
|
594 | repeatTableHeader: true,
|
595 | css: null,
|
596 | style: null,
|
597 | scanStyles: true
|
598 | };
|
599 |
|
600 |
|
601 | var args = arguments[0];
|
602 | if (args === undefined) throw new Error('printJS expects at least 1 attribute.');
|
603 |
|
604 |
|
605 | switch (typeof args === 'undefined' ? 'undefined' : _typeof(args)) {
|
606 | case 'string':
|
607 | params.printable = encodeURI(args);
|
608 | params.fallbackPrintable = params.printable;
|
609 | params.type = arguments[1] || params.type;
|
610 | break;
|
611 | case 'object':
|
612 | params.printable = args.printable;
|
613 | params.fallbackPrintable = typeof args.fallbackPrintable !== 'undefined' ? args.fallbackPrintable : params.printable;
|
614 | params.type = typeof args.type !== 'undefined' ? args.type : params.type;
|
615 | params.frameId = typeof args.frameId !== 'undefined' ? args.frameId : params.frameId;
|
616 | params.header = typeof args.header !== 'undefined' ? args.header : params.header;
|
617 | params.headerStyle = typeof args.headerStyle !== 'undefined' ? args.headerStyle : params.headerStyle;
|
618 | params.maxWidth = typeof args.maxWidth !== 'undefined' ? args.maxWidth : params.maxWidth;
|
619 | params.font = typeof args.font !== 'undefined' ? args.font : params.font;
|
620 | params.font_size = typeof args.font_size !== 'undefined' ? args.font_size : params.font_size;
|
621 | params.honorMarginPadding = typeof args.honorMarginPadding !== 'undefined' ? args.honorMarginPadding : params.honorMarginPadding;
|
622 | params.properties = typeof args.properties !== 'undefined' ? args.properties : params.properties;
|
623 | params.gridHeaderStyle = typeof args.gridHeaderStyle !== 'undefined' ? args.gridHeaderStyle : params.gridHeaderStyle;
|
624 | params.gridStyle = typeof args.gridStyle !== 'undefined' ? args.gridStyle : params.gridStyle;
|
625 | params.showModal = typeof args.showModal !== 'undefined' ? args.showModal : params.showModal;
|
626 | params.onLoadingStart = typeof args.onLoadingStart !== 'undefined' ? args.onLoadingStart : params.onLoadingStart;
|
627 | params.onLoadingEnd = typeof args.onLoadingEnd !== 'undefined' ? args.onLoadingEnd : params.onLoadingEnd;
|
628 | params.modalMessage = typeof args.modalMessage !== 'undefined' ? args.modalMessage : params.modalMessage;
|
629 | params.documentTitle = typeof args.documentTitle !== 'undefined' ? args.documentTitle : params.documentTitle;
|
630 | params.targetStyle = typeof args.targetStyle !== 'undefined' ? args.targetStyle : params.targetStyle;
|
631 | params.targetStyles = typeof args.targetStyles !== 'undefined' ? args.targetStyles : params.targetStyles;
|
632 | params.ignoreElements = typeof args.ignoreElements !== 'undefined' ? args.ignoreElements : params.ignoreElements;
|
633 | params.imageStyle = typeof args.imageStyle !== 'undefined' ? args.imageStyle : params.imageStyle;
|
634 | params.repeatTableHeader = typeof args.repeatTableHeader !== 'undefined' ? args.repeatTableHeader : params.repeatTableHeader;
|
635 | params.css = typeof args.css !== 'undefined' ? args.css : params.css;
|
636 | params.style = typeof args.style !== 'undefined' ? args.style : params.style;
|
637 | params.scanStyles = typeof args.scanStyles !== 'undefined' ? args.scanStyles : params.scanStyles;
|
638 | break;
|
639 | default:
|
640 | throw new Error('Unexpected argument type! Expected "string" or "object", got ' + (typeof args === 'undefined' ? 'undefined' : _typeof(args)));
|
641 | }
|
642 |
|
643 |
|
644 | if (!params.printable) throw new Error('Missing printable information.');
|
645 |
|
646 |
|
647 | if (!params.type || typeof params.type !== 'string' || printTypes.indexOf(params.type.toLowerCase()) === -1) {
|
648 | throw new Error('Invalid print type. Available types are: pdf, html, image and json.');
|
649 | }
|
650 |
|
651 |
|
652 | if (params.showModal) __WEBPACK_IMPORTED_MODULE_1__modal__["a" ].show(params);
|
653 |
|
654 |
|
655 | if (params.onLoadingStart) params.onLoadingStart();
|
656 |
|
657 |
|
658 | var usedFrame = document.getElementById(params.frameId);
|
659 |
|
660 | if (usedFrame) usedFrame.parentNode.removeChild(usedFrame);
|
661 |
|
662 |
|
663 | var printFrame = void 0;
|
664 |
|
665 |
|
666 | printFrame = document.createElement('iframe');
|
667 |
|
668 |
|
669 | printFrame.setAttribute('style', 'visibility: hidden; height: 0; width: 0; position: absolute;');
|
670 |
|
671 |
|
672 | printFrame.setAttribute('id', params.frameId);
|
673 |
|
674 |
|
675 | if (params.type !== 'pdf') {
|
676 | printFrame.srcdoc = '<html><head><title>' + params.documentTitle + '</title>';
|
677 |
|
678 |
|
679 | if (params.css !== null) {
|
680 |
|
681 | if (!Array.isArray(params.css)) params.css = [params.css];
|
682 |
|
683 |
|
684 | params.css.forEach(function (file) {
|
685 | printFrame.srcdoc += '<link rel="stylesheet" href="' + file + '">';
|
686 | });
|
687 | }
|
688 |
|
689 | printFrame.srcdoc += '</head><body></body></html>';
|
690 | }
|
691 |
|
692 |
|
693 | switch (params.type) {
|
694 | case 'pdf':
|
695 |
|
696 | if (__WEBPACK_IMPORTED_MODULE_0__browser__["a" ].isFirefox() || __WEBPACK_IMPORTED_MODULE_0__browser__["a" ].isEdge() || __WEBPACK_IMPORTED_MODULE_0__browser__["a" ].isIE()) {
|
697 | console.info('PrintJS currently doesn\'t support PDF printing in Firefox, Internet Explorer and Edge.');
|
698 | var win = window.open(params.fallbackPrintable, '_blank');
|
699 | win.focus();
|
700 |
|
701 | if (params.showModal) __WEBPACK_IMPORTED_MODULE_1__modal__["a" ].close();
|
702 | if (params.onLoadingEnd) params.onLoadingEnd();
|
703 | } else {
|
704 | __WEBPACK_IMPORTED_MODULE_2__pdf__["a" ].print(params, printFrame);
|
705 | }
|
706 | break;
|
707 | case 'image':
|
708 | __WEBPACK_IMPORTED_MODULE_4__image__["a" ].print(params, printFrame);
|
709 | break;
|
710 | case 'html':
|
711 | __WEBPACK_IMPORTED_MODULE_3__html__["a" ].print(params, printFrame);
|
712 | break;
|
713 | case 'json':
|
714 | __WEBPACK_IMPORTED_MODULE_5__json__["a" ].print(params, printFrame);
|
715 | break;
|
716 | }
|
717 | }
|
718 | });
|
719 |
|
720 | }),
|
721 |
|
722 | (function(module, __webpack_exports__, __webpack_require__) {
|
723 |
|
724 | "use strict";
|
725 | var __WEBPACK_IMPORTED_MODULE_0__functions__ = __webpack_require__(1);
|
726 | var __WEBPACK_IMPORTED_MODULE_1__print__ = __webpack_require__(0);
|
727 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
728 |
|
729 |
|
730 |
|
731 |
|
732 | __webpack_exports__["a"] = ({
|
733 | print: function print(params, printFrame) {
|
734 |
|
735 | if (_typeof(params.printable) !== 'object') {
|
736 | throw new Error('Invalid javascript data object (JSON).');
|
737 | }
|
738 |
|
739 |
|
740 | if (typeof params.repeatTableHeader !== 'boolean') {
|
741 | throw new Error('Invalid value for repeatTableHeader attribute (JSON).');
|
742 | }
|
743 |
|
744 |
|
745 | if (!params.properties || _typeof(params.properties) !== 'object') throw new Error('Invalid properties array for your JSON data.');
|
746 |
|
747 |
|
748 | var htmlData = '';
|
749 |
|
750 |
|
751 | if (params.header) htmlData += '<h1 style="' + params.headerStyle + '">' + params.header + '</h1>';
|
752 |
|
753 |
|
754 | htmlData += jsonToHTML(params);
|
755 |
|
756 |
|
757 | params.htmlData = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__functions__["a" ])(htmlData, params);
|
758 |
|
759 |
|
760 | __WEBPACK_IMPORTED_MODULE_1__print__["a" ].send(params, printFrame);
|
761 | }
|
762 | });
|
763 |
|
764 | function jsonToHTML(params) {
|
765 |
|
766 | var data = params.printable;
|
767 | var properties = params.properties;
|
768 |
|
769 |
|
770 | var htmlData = '<table style="border-collapse: collapse; width: 100%;">';
|
771 |
|
772 |
|
773 | if (params.repeatTableHeader) {
|
774 | htmlData += '<thead>';
|
775 | }
|
776 |
|
777 |
|
778 | htmlData += '<tr>';
|
779 |
|
780 |
|
781 | for (var a = 0; a < properties.length; a++) {
|
782 | htmlData += '<th style="width:' + 100 / properties.length + '%; ' + params.gridHeaderStyle + '">' + __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__functions__["b" ])(properties[a]) + '</th>';
|
783 | }
|
784 |
|
785 |
|
786 | htmlData += '</tr>';
|
787 |
|
788 |
|
789 | if (params.repeatTableHeader) {
|
790 | htmlData += '</thead>';
|
791 | }
|
792 |
|
793 |
|
794 | htmlData += '<tbody>';
|
795 |
|
796 |
|
797 | for (var i = 0; i < data.length; i++) {
|
798 |
|
799 | htmlData += '<tr>';
|
800 |
|
801 |
|
802 | for (var n = 0; n < properties.length; n++) {
|
803 | var stringData = data[i];
|
804 |
|
805 |
|
806 | var property = properties[n].split('.');
|
807 | if (property.length > 1) {
|
808 | for (var p = 0; p < property.length; p++) {
|
809 | stringData = stringData[property[p]];
|
810 | }
|
811 | } else {
|
812 | stringData = stringData[properties[n]];
|
813 | }
|
814 |
|
815 |
|
816 | htmlData += '<td style="width:' + 100 / properties.length + '%;' + params.gridStyle + '">' + stringData + '</td>';
|
817 | }
|
818 |
|
819 |
|
820 | htmlData += '</tr>';
|
821 | }
|
822 |
|
823 |
|
824 | htmlData += '</tbody></table>';
|
825 |
|
826 | return htmlData;
|
827 | }
|
828 |
|
829 | }),
|
830 |
|
831 | (function(module, __webpack_exports__, __webpack_require__) {
|
832 |
|
833 | "use strict";
|
834 | var __WEBPACK_IMPORTED_MODULE_0__print__ = __webpack_require__(0);
|
835 |
|
836 |
|
837 | __webpack_exports__["a"] = ({
|
838 | print: function print(params, printFrame) {
|
839 |
|
840 | params.printable = params.printable.indexOf('http') !== -1 ? params.printable : window.location.origin + (params.printable.charAt(0) !== '/' ? '/' + params.printable : params.printable);
|
841 |
|
842 |
|
843 | if (params.showModal || params.onLoadingStart) {
|
844 |
|
845 | var req = new window.XMLHttpRequest();
|
846 | req.responseType = 'arraybuffer';
|
847 |
|
848 | req.addEventListener('load', function () {
|
849 |
|
850 | var localPdf = new window.Blob([req.response], { type: 'application/pdf' });
|
851 | localPdf = window.URL.createObjectURL(localPdf);
|
852 |
|
853 |
|
854 |
|
855 | params.printable = localPdf;
|
856 |
|
857 | send(params, printFrame);
|
858 | });
|
859 |
|
860 | req.open('GET', params.printable, true);
|
861 | req.send();
|
862 | } else {
|
863 | send(params, printFrame);
|
864 | }
|
865 | }
|
866 | });
|
867 |
|
868 | function send(params, printFrame) {
|
869 |
|
870 | printFrame.setAttribute('src', params.printable);
|
871 |
|
872 | __WEBPACK_IMPORTED_MODULE_0__print__["a" ].send(params, printFrame);
|
873 | }
|
874 |
|
875 | }),
|
876 |
|
877 | (function(module, exports, __webpack_require__) {
|
878 |
|
879 | module.exports = __webpack_require__(4);
|
880 |
|
881 |
|
882 | })
|
883 | ]);
|
884 | }); |
\ | No newline at end of file |