isite 2022.9.15 → 2022.9.16

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.
@@ -1,208 +1,205 @@
1
1
  site.print = site.printHTML = function (options) {
2
- options = options || {};
3
- let content = '';
4
-
5
- if (typeof options === 'string') {
6
- options = {
7
- selector: options,
8
- };
2
+ options = options || {};
3
+ let content = '';
4
+
5
+ if (typeof options === 'string') {
6
+ options = {
7
+ selector: options,
8
+ };
9
+ }
10
+ if (!options.content) {
11
+ if (!options.selector) {
12
+ console.error('No Selector sets ...');
13
+ return false;
14
+ }
15
+ window.document.querySelectorAll('link[href]').forEach((l) => {
16
+ content += '<link rel="stylesheet" href="' + site.handle_url(l.href) + '" type="text/css" >';
17
+ });
18
+
19
+ window.document.querySelectorAll('style').forEach((s) => {
20
+ content += s.outerHTML;
21
+ });
22
+
23
+ if (options.links) {
24
+ options.links.forEach((link) => {
25
+ content += '<link rel="stylesheet" href="' + link + '" type="text/css" >';
26
+ });
9
27
  }
10
- if (!options.content) {
11
- if (!options.selector) {
12
- console.error('No Selector sets ...');
13
- return false;
14
- }
15
- window.document.querySelectorAll('link[rel=stylesheet]').forEach((l) => {
16
- l.href = site.handle_url(l.href);
17
- content += l.outerHTML;
18
- });
19
-
20
- window.document.querySelectorAll('style').forEach((s) => {
21
- content += s.outerHTML;
22
- });
23
-
24
- if (options.links) {
25
- options.links.forEach((link) => {
26
- content += '<link rel="stylesheet" href="' + link + '" type="text/css" >';
27
- });
28
- }
29
28
 
30
- if (options.preappends) {
31
- options.preappends.forEach((el) => {
32
- el = window.document.querySelector(el);
33
- if (el) {
34
- content += el.outerHTML;
35
- }
36
- });
29
+ if (options.preappends) {
30
+ options.preappends.forEach((el) => {
31
+ el = window.document.querySelector(el);
32
+ if (el) {
33
+ content += el.outerHTML;
37
34
  }
35
+ });
36
+ }
38
37
 
39
- document.querySelectorAll(options.selector + ' input').forEach((el) => {
40
- el.setAttribute('value', el.value);
41
- });
42
-
43
- document.querySelectorAll(options.selector + ' textarea').forEach((el) => {
44
- el.innerText = el.value;
45
- });
46
-
47
- document.querySelectorAll(options.selector).forEach((el) => {
48
- let display = el.style.display;
49
- el.style.display = 'block';
50
- content += el.outerHTML;
51
- el.style.display = display;
52
- });
53
-
54
- if (options.appends) {
55
- options.appends.forEach((el) => {
56
- el = window.document.querySelector(el);
57
- if (el) {
58
- content += el.outerHTML;
38
+ document.querySelectorAll(options.selector).forEach((el) => {
39
+ let el2 = el.cloneNode(true);
40
+ el2.querySelectorAll('input').forEach((input) => {
41
+ input.setAttribute('value', input.value);
42
+ });
43
+
44
+ el2.querySelectorAll('textarea').forEach((textarea) => {
45
+ textarea.innerText = textarea.value;
46
+ });
47
+ el2.style.display = 'block';
48
+ content += el2.outerHTML;
49
+ });
50
+
51
+ if (options.appends) {
52
+ options.appends.forEach((el) => {
53
+ el = window.document.querySelector(el);
54
+ if (el) {
55
+ content += el.outerHTML;
56
+ }
57
+ });
58
+ }
59
+ } else {
60
+ options.type = 'content';
61
+ content = options.content;
62
+ }
63
+
64
+ if (!options.ip) {
65
+ options.ip = '127.0.0.1';
66
+ }
67
+ if (!options.port) {
68
+ options.port = '60080';
69
+ }
70
+
71
+ site.postData(
72
+ { url: '/api/print', data: { content: content, type: options.type } },
73
+ (response) => {
74
+ if (response.done) {
75
+ if (options.printer) {
76
+ fetch(response.url, {
77
+ mode: 'cors',
78
+ method: 'get',
79
+ })
80
+ .then((res) => res.text())
81
+ .then((html) => {
82
+ options.html = html;
83
+ options.type = 'html';
84
+ site.postData(
85
+ {
86
+ url: `http://${options.ip}:${options.port}/print`,
87
+ data: options,
88
+ },
89
+ (res) => {
90
+ console.log(res);
91
+ },
92
+ (err) => {
93
+ console.log(err);
59
94
  }
95
+ );
96
+ })
97
+ .catch((err) => {
98
+ console.error(err);
60
99
  });
100
+ } else {
101
+ window.open(response.url);
61
102
  }
62
- } else {
63
- options.type = 'content';
64
- content = options.content;
65
- }
66
-
67
- if (!options.ip) {
68
- options.ip = '127.0.0.1';
69
- }
70
- if (!options.port) {
71
- options.port = '60080';
103
+ }
104
+ },
105
+ (error) => {
106
+ console.log(error);
72
107
  }
108
+ );
73
109
 
74
- site.postData(
75
- { url: '/api/print', data: { content: content, type: options.type } },
76
- (response) => {
77
- if (response.done) {
78
- if (options.printer) {
79
- fetch(response.url, {
80
- mode: 'cors',
81
- method: 'get',
82
- })
83
- .then((res) => res.text())
84
- .then((html) => {
85
- options.html = html;
86
- options.type = 'html';
87
- site.postData(
88
- {
89
- url: `http://${options.ip}:${options.port}/print`,
90
- data: options,
91
- },
92
- (res) => {
93
- console.log(res);
94
- },
95
- (err) => {
96
- console.log(err);
97
- },
98
- );
99
- })
100
- .catch((err) => {
101
- console.error(err);
102
- });
103
- } else {
104
- window.open(response.url);
105
- }
106
- }
107
- },
108
- (error) => {
109
- console.log(error);
110
- },
111
- );
112
-
113
- return !0;
110
+ return !0;
114
111
  };
115
112
 
116
113
  site.printAsImageBusy = false;
117
114
 
118
115
  site.printAsImage = function (options, callback) {
119
- if (site.printAsImageBusy) {
120
- setTimeout(() => {
121
- site.printAsImage(options, callback);
122
- }, 1000);
123
- return false;
124
- }
125
-
126
- site.printAsImageBusy = true;
127
- options = options || {};
128
-
129
- if (typeof options === 'string') {
130
- options = {
131
- selector: options,
132
- };
133
- }
134
- if (!options.selector) {
135
- console.error('No Selector sets ...');
136
- site.printAsImageBusy = false;
137
- return false;
138
- }
139
- if (!options.ip) {
140
- options.ip = '127.0.0.1';
141
- }
142
- if (!options.port) {
143
- options.port = '60080';
144
- }
145
- if (!options.type) {
146
- options.type = 'image';
147
- }
148
-
149
- let node = typeof options.selector === 'string' ? document.querySelector(options.selector) : options.selector;
150
- if (!node) {
151
- console.error('No Node Selector ');
152
- site.printAsImageBusy = false;
153
- return false;
154
- }
155
-
156
- domtoimage
157
- .toPng(node, { quality: 1, bgcolor: '#ffffff' })
158
- .then(function (dataUrl) {
159
- var img = new Image();
160
- img.src = dataUrl;
161
- if (callback) {
162
- callback(img);
163
- }
164
- options.content = dataUrl;
165
- site.printDataUrl(options);
166
- site.printAsImageBusy = false;
167
- })
168
- .catch(function (error) {
169
- console.error(error);
170
- site.printAsImageBusy = false;
171
- });
116
+ if (site.printAsImageBusy) {
117
+ setTimeout(() => {
118
+ site.printAsImage(options, callback);
119
+ }, 1000);
120
+ return false;
121
+ }
122
+
123
+ site.printAsImageBusy = true;
124
+ options = options || {};
125
+
126
+ if (typeof options === 'string') {
127
+ options = {
128
+ selector: options,
129
+ };
130
+ }
131
+ if (!options.selector) {
132
+ console.error('No Selector sets ...');
133
+ site.printAsImageBusy = false;
134
+ return false;
135
+ }
136
+ if (!options.ip) {
137
+ options.ip = '127.0.0.1';
138
+ }
139
+ if (!options.port) {
140
+ options.port = '60080';
141
+ }
142
+ if (!options.type) {
143
+ options.type = 'image';
144
+ }
145
+
146
+ let node = typeof options.selector === 'string' ? document.querySelector(options.selector) : options.selector;
147
+ if (!node) {
148
+ console.error('No Node Selector ');
149
+ site.printAsImageBusy = false;
150
+ return false;
151
+ }
152
+
153
+ domtoimage
154
+ .toPng(node, { quality: 1, bgcolor: '#ffffff' })
155
+ .then(function (dataUrl) {
156
+ var img = new Image();
157
+ img.src = dataUrl;
158
+ if (callback) {
159
+ callback(img);
160
+ }
161
+ options.content = dataUrl;
162
+ site.printDataUrl(options);
163
+ site.printAsImageBusy = false;
164
+ })
165
+ .catch(function (error) {
166
+ console.error(error);
167
+ site.printAsImageBusy = false;
168
+ });
172
169
  };
173
170
 
174
171
  site.printDataUrl = function (options) {
175
- site.postData(
176
- { url: '/api/print', data: options },
177
- (response) => {
178
- if (response.done) {
179
- if (options.printer) {
180
- fetch(response.url, {
181
- mode: 'cors',
182
- method: 'get',
183
- })
184
- .then((res) => res.text())
185
- .then((html) => {
186
- options.html = html;
187
- options.type = 'html';
188
- site.postData(
189
- {
190
- url: `http://${options.ip}:${options.port}/print`,
191
- data: options,
192
- },
193
- (res) => {},
194
- );
195
- })
196
- .catch((err) => {
197
- console.error(err);
198
- });
199
- } else {
200
- window.open(response.url);
201
- }
202
- }
203
- },
204
- (error) => {
205
- console.log(error);
206
- },
207
- );
172
+ site.postData(
173
+ { url: '/api/print', data: options },
174
+ (response) => {
175
+ if (response.done) {
176
+ if (options.printer) {
177
+ fetch(response.url, {
178
+ mode: 'cors',
179
+ method: 'get',
180
+ })
181
+ .then((res) => res.text())
182
+ .then((html) => {
183
+ options.html = html;
184
+ options.type = 'html';
185
+ site.postData(
186
+ {
187
+ url: `http://${options.ip}:${options.port}/print`,
188
+ data: options,
189
+ },
190
+ (res) => {}
191
+ );
192
+ })
193
+ .catch((err) => {
194
+ console.error(err);
195
+ });
196
+ } else {
197
+ window.open(response.url);
198
+ }
199
+ }
200
+ },
201
+ (error) => {
202
+ console.log(error);
203
+ }
204
+ );
208
205
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isite",
3
- "version": "2022.09.15",
3
+ "version": "2022.09.16",
4
4
  "description": "Create Secure Multi-Language Web Site [Fast and Easy] ",
5
5
  "main": "index.js",
6
6
  "repository": {