1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | 'use strict';
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.DownloadManager = undefined;
|
28 |
|
29 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
30 |
|
31 | var _pdf = require('../pdf');
|
32 |
|
33 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
34 |
|
35 | ;
|
36 | var DISABLE_CREATE_OBJECT_URL = _pdf.apiCompatibilityParams.disableCreateObjectURL || false;
|
37 | function _download(blobUrl, filename) {
|
38 | var a = document.createElement('a');
|
39 | if (!a.click) {
|
40 | throw new Error('DownloadManager: "a.click()" is not supported.');
|
41 | }
|
42 | a.href = blobUrl;
|
43 | a.target = '_parent';
|
44 | if ('download' in a) {
|
45 | a.download = filename;
|
46 | }
|
47 | (document.body || document.documentElement).appendChild(a);
|
48 | a.click();
|
49 | a.remove();
|
50 | }
|
51 |
|
52 | var DownloadManager = function () {
|
53 | function DownloadManager(_ref) {
|
54 | var _ref$disableCreateObj = _ref.disableCreateObjectURL,
|
55 | disableCreateObjectURL = _ref$disableCreateObj === undefined ? DISABLE_CREATE_OBJECT_URL : _ref$disableCreateObj;
|
56 |
|
57 | _classCallCheck(this, DownloadManager);
|
58 |
|
59 | this.disableCreateObjectURL = disableCreateObjectURL;
|
60 | }
|
61 |
|
62 | _createClass(DownloadManager, [{
|
63 | key: 'downloadUrl',
|
64 | value: function downloadUrl(url, filename) {
|
65 | if (!(0, _pdf.createValidAbsoluteUrl)(url, 'http://example.com')) {
|
66 | return;
|
67 | }
|
68 | _download(url + '#pdfjs.action=download', filename);
|
69 | }
|
70 | }, {
|
71 | key: 'downloadData',
|
72 | value: function downloadData(data, filename, contentType) {
|
73 | if (navigator.msSaveBlob) {
|
74 | return navigator.msSaveBlob(new Blob([data], { type: contentType }), filename);
|
75 | }
|
76 | var blobUrl = (0, _pdf.createObjectURL)(data, contentType, this.disableCreateObjectURL);
|
77 | _download(blobUrl, filename);
|
78 | }
|
79 | }, {
|
80 | key: 'download',
|
81 | value: function download(blob, url, filename) {
|
82 | if (navigator.msSaveBlob) {
|
83 | if (!navigator.msSaveBlob(blob, filename)) {
|
84 | this.downloadUrl(url, filename);
|
85 | }
|
86 | return;
|
87 | }
|
88 | if (this.disableCreateObjectURL) {
|
89 | this.downloadUrl(url, filename);
|
90 | return;
|
91 | }
|
92 | var blobUrl = URL.createObjectURL(blob);
|
93 | _download(blobUrl, filename);
|
94 | }
|
95 | }]);
|
96 |
|
97 | return DownloadManager;
|
98 | }();
|
99 |
|
100 | exports.DownloadManager = DownloadManager; |
\ | No newline at end of file |