easyprintand 1.0.4 → 1.0.6

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/prindiv.js +346 -0
  3. package/index.js +0 -289
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easyprintand",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Easily print the content of a DIV",
5
5
  "main": "EasyprintAnd.js",
6
6
  "scripts": {
package/prindiv.js ADDED
@@ -0,0 +1,346 @@
1
+
2
+
3
+
4
+ /**
5
+ * Version 2.4.1 Copyright (C) 2013
6
+ * Tested in IE 11, FF 28.0 and Chrome 33.0.1750.154
7
+ * No official support for other browsers, but will TRY to accommodate challenges in other browsers.
8
+ * Example:
9
+ * Print Button: <div id="print_button">Print</div>
10
+ * Print Area : <div class="PrintArea" id="MyId" class="MyClass"> ... html ... </div>
11
+ * Javascript : <script>
12
+ * $("div#print_button").click(function(){
13
+ * $("div.PrintArea").printArea( [OPTIONS] );
14
+ * });
15
+ * </script>
16
+ * options are passed as json (example: {mode: "popup", popClose: false})
17
+ *
18
+ * {OPTIONS} | [type] | (default), values | Explanation
19
+ * --------- | --------- | ---------------------- | -----------
20
+ * @mode | [string] | (iframe),popup | printable window is either iframe or browser popup
21
+ * @popHt | [number] | (500) | popup window height
22
+ * @popWd | [number] | (400) | popup window width
23
+ * @popX | [number] | (500) | popup window screen X position
24
+ * @popY | [number] | (500) | popup window screen Y position
25
+ * @popTitle | [string] | ('') | popup window title element
26
+ * @popClose | [boolean] | (false),true | popup window close after printing
27
+ * @extraCss | [string] | ('') | comma separated list of extra css to include
28
+ * @retainAttr | [string[]] | ["id","class","style"] | string array of attributes to retain for the containment area. (ie: id, style, class)
29
+ * @standard | [string] | strict, loose, (html5) | Only for popup. For html 4.01, strict or loose document standard, or html 5 standard
30
+ * @extraHead | [string] | ('') | comma separated list of extra elements to be appended to the head tag
31
+ * @defaultCss | [boolean] | true | Si es verdadero extrae todos los datos del css
32
+ *
33
+ *
34
+ *
35
+ *
36
+ *
37
+ *
38
+ * PARA INICIAR ASI:
39
+ *
40
+ *
41
+ *
42
+ *
43
+
44
+
45
+ import prindiv from 'easyprintand';
46
+
47
+ <div id='EasyPrintAnd'>
48
+ <div>
49
+ <h1>texto para imprmir </h1>
50
+ asdadadad
51
+ sada
52
+ </div>
53
+ </div>
54
+
55
+
56
+ <button onClick={ () => prindiv('EasyPrintAnd' , { extraCss : './tirilla.css' })}>Print</button>
57
+
58
+ */
59
+
60
+ 'use strict';
61
+
62
+ function onPrintDiv(event, elem, selector, handler) {
63
+ elem.addEventListener(event, ev => {
64
+ if (ev.target.matches(selector)) {
65
+ handler()
66
+ }
67
+ })
68
+ }
69
+
70
+ function prindiv ( id_elemento = 'EasyPrintAnd' , options , modo = 'produccion' )
71
+ {
72
+
73
+
74
+
75
+ var modos = modo;
76
+ var counter = 0;
77
+ var modes = { iframe : "iframe", popup : "popup" };
78
+ var standards = { strict : "strict", loose : "loose", html5 : "html5" };
79
+ var defaults = { mode : modes.iframe,
80
+ standard : standards.html5,
81
+ extraCss : '',
82
+ defaultCss : false,
83
+ extraHead : '',
84
+ retainAttr : ["id","class","style"] };
85
+
86
+ var settings = {};//global settings
87
+
88
+
89
+
90
+
91
+
92
+ //Combiamos el arrayd
93
+ Object.assign(settings, defaults, options);
94
+
95
+ //El Id del documento
96
+ counter++;
97
+
98
+
99
+
100
+ var idPrefix = "printArea_";
101
+
102
+ //Se Renova el documento actial
103
+ var data = document.querySelector("[id^=" + idPrefix + "]" );
104
+
105
+ if (data) {
106
+ data.remove();
107
+ }
108
+
109
+
110
+ // ID Siguiente
111
+ settings.id = idPrefix + counter;
112
+
113
+
114
+
115
+
116
+
117
+ var $printSource = document.querySelector("div#" + id_elemento );
118
+
119
+
120
+ var PrintAreaWindow = getPrintWindow();
121
+
122
+
123
+
124
+ write( PrintAreaWindow.doc, $printSource );
125
+
126
+ if( modos == "produccion"){
127
+
128
+ setTimeout( function () { print( PrintAreaWindow ); }, 300 );
129
+
130
+ }
131
+
132
+
133
+
134
+
135
+
136
+
137
+ function print ( PAWindow ) {
138
+ var paWindow = PAWindow.win;
139
+ setTimeout( function () {
140
+ paWindow.focus();
141
+ paWindow.print();
142
+
143
+ }, 300 );
144
+
145
+ }
146
+
147
+
148
+
149
+ function write ( PADocument, $ele ) {
150
+
151
+
152
+
153
+ PADocument.open();
154
+
155
+
156
+
157
+ //let HTML = docType() + "<html>" + getHead() + getBody( $/ele ) + "</html>";
158
+
159
+ let HTML = "<html>" + getHead() + getBody( $/ele ) + "</html>";
160
+
161
+
162
+ PADocument.write( HTML );
163
+
164
+ PADocument.close();
165
+ }
166
+
167
+
168
+
169
+
170
+
171
+
172
+ function getHead(){
173
+
174
+
175
+ var links = "";
176
+
177
+
178
+
179
+ /** Busca Todos los Css y los Carga **/
180
+ if (settings.defaultCss) {
181
+
182
+ /*$(document).find("link").each(function(){
183
+
184
+ links += '<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >';
185
+
186
+ });
187
+ */
188
+ }
189
+
190
+ /** En caso de que mandemos un CssExtra **/
191
+
192
+ if ( settings.extraCss ) {
193
+ settings.extraCss.replace( /([^,\s]+)/g , function(m){
194
+ links += '<link type="text/css" rel="stylesheet" href="' + m + '">'
195
+ });
196
+ }
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+ if(modos == "pruebas" ){
205
+ return "<head>" + links + getFooter()+ "</head>";
206
+
207
+ }else{
208
+ return "<head>" + links + "</head>";
209
+ }
210
+ }
211
+
212
+
213
+
214
+ function getBody ( elements ) {
215
+ return "<body>" + elements.innerHTML + "</body>";
216
+ }
217
+
218
+ function getFooter(){
219
+ if(modos == "pruebas" ){
220
+
221
+ return '<button onClick="this.remove();window.print();" id="printButton">Imprimir</button>';
222
+ }
223
+
224
+ }
225
+
226
+
227
+
228
+ function getFormData( ele ) {
229
+
230
+
231
+
232
+ }
233
+
234
+
235
+
236
+
237
+ function getPrintWindow () {
238
+
239
+ var f = new Iframe();
240
+
241
+ console.log(f);
242
+
243
+ let data = {
244
+
245
+ win : f.contentWindow || f,
246
+
247
+ doc : f.doc
248
+ };
249
+
250
+
251
+ return data;
252
+
253
+
254
+
255
+ }
256
+
257
+
258
+
259
+
260
+
261
+ function Iframe() {
262
+
263
+
264
+ var frameId = settings.id;
265
+
266
+ //Estilos para ocultarlo //'width:80mm;height:1000px'
267
+
268
+
269
+
270
+ if(modos == "produccion" ){
271
+ var iframeStyle = 'border:0;position:absolute;width:0px;height:0px;right:0px;top:0px;';
272
+ }else{
273
+ var iframeStyle = 'z-index:10000;border:0;position:relative;width:90%;height:900px;right:0px;top:0px;background: #a3a0a0; padding-left: 30px;padding-top: 20px;';
274
+ }
275
+ var iframe;
276
+
277
+
278
+
279
+
280
+ /* Creamos un elemento Iframe **/
281
+ iframe = document.createElement('iframe');
282
+
283
+
284
+ /* Agregamos el iframe al inucio del documento */
285
+ //
286
+ if(modos == "produccion" ){
287
+ //En produccion se agrega encima del HTML
288
+ document.body.appendChild(iframe);
289
+ }else{
290
+ //En Pruebas se agrega dentro de una eiqueta Html
291
+ const el = document.querySelector(".pintDivtest");
292
+ el.appendChild(iframe);
293
+ }
294
+
295
+
296
+
297
+
298
+ iframe.setAttribute("style", iframeStyle );
299
+ iframe.setAttribute("id", frameId );
300
+ iframe.setAttribute("src", "#" + new Date().getTime() );
301
+
302
+
303
+
304
+ iframe.doc = null;
305
+ iframe.doc = iframe.contentDocument ? iframe.contentDocument :( iframe.contentWindow ? iframe.contentWindow.document : iframe.document);
306
+ return iframe;
307
+ }
308
+
309
+ function Popup() {
310
+ var windowAttr = "location=yes,statusbar=no,directories=no,menubar=no,titlebar=no,toolbar=no,dependent=no";
311
+ windowAttr += ",width=" + settings.popWd + ",height=" + settings.popHt;
312
+ windowAttr += ",resizable=yes,screenX=" + settings.popX + ",screenY=" + settings.popY + ",personalbar=no,scrollbars=yes";
313
+ var newWin = window.open( "", "_blank", windowAttr );
314
+ newWin.doc = newWin.document;
315
+ return newWin;
316
+ }
317
+
318
+
319
+ }
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+ module.exports = prindiv;
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
package/index.js DELETED
@@ -1,289 +0,0 @@
1
-
2
-
3
-
4
- /**
5
- * Version 2.4.1 Copyright (C) 2013
6
- * Tested in IE 11, FF 28.0 and Chrome 33.0.1750.154
7
- * No official support for other browsers, but will TRY to accommodate challenges in other browsers.
8
- * Example:
9
- * Print Button: <div id="print_button">Print</div>
10
- * Print Area : <div class="PrintArea" id="MyId" class="MyClass"> ... html ... </div>
11
- * Javascript : <script>
12
- * $("div#print_button").click(function(){
13
- * $("div.PrintArea").printArea( [OPTIONS] );
14
- * });
15
- * </script>
16
- * options are passed as json (example: {mode: "popup", popClose: false})
17
- *
18
- * {OPTIONS} | [type] | (default), values | Explanation
19
- * --------- | --------- | ---------------------- | -----------
20
- * @mode | [string] | (iframe),popup | printable window is either iframe or browser popup
21
- * @popHt | [number] | (500) | popup window height
22
- * @popWd | [number] | (400) | popup window width
23
- * @popX | [number] | (500) | popup window screen X position
24
- * @popY | [number] | (500) | popup window screen Y position
25
- * @popTitle | [string] | ('') | popup window title element
26
- * @popClose | [boolean] | (false),true | popup window close after printing
27
- * @extraCss | [string] | ('') | comma separated list of extra css to include
28
- * @retainAttr | [string[]] | ["id","class","style"] | string array of attributes to retain for the containment area. (ie: id, style, class)
29
- * @standard | [string] | strict, loose, (html5) | Only for popup. For html 4.01, strict or loose document standard, or html 5 standard
30
- * @extraHead | [string] | ('') | comma separated list of extra elements to be appended to the head tag
31
- * @defaultCss | [boolean] | true | Si es verdadero extrae todos los datos del css
32
- *
33
- *
34
- *
35
- *
36
- *
37
- *
38
- * PARA INICIAR ASI:
39
- *
40
- *
41
- * var options = {extraCss:'extracss.css' , defaultCss : false };
42
- EasyPrintAnd( 'EasyPrintAnd' , options);
43
-
44
- */
45
-
46
-
47
-
48
-
49
- function prindiv ( id_elemento = 'EasyPrintAnd' , options )
50
- {
51
-
52
-
53
-
54
-
55
- var counter = 0;
56
- var modes = { iframe : "iframe", popup : "popup" };
57
- var standards = { strict : "strict", loose : "loose", html5 : "html5" };
58
- var defaults = { mode : modes.iframe,
59
- standard : standards.html5,
60
- popHt : 500,
61
- popWd : 400,
62
- popX : 200,
63
- popY : 200,
64
- popTitle : '',
65
- popClose : false,
66
- extraCss : '',
67
- defaultCss : true,
68
- extraHead : '',
69
- retainAttr : ["id","class","style"] };
70
-
71
- var settings = {};//global settings
72
-
73
-
74
-
75
-
76
-
77
- //Combiamos el arrayd
78
- Object.assign(settings, defaults, options);
79
-
80
- //El Id del documento
81
- counter++;
82
-
83
-
84
-
85
- var idPrefix = "printArea_";
86
-
87
- //Se Renova el documento actial
88
- data = document.querySelector("[id^=" + idPrefix + "]" )
89
- if (data) {
90
- data.remove();
91
- }
92
-
93
-
94
- // ID Siguiente
95
- settings.id = idPrefix + counter;
96
-
97
-
98
-
99
-
100
-
101
- var $printSource = document.querySelector("div#" + id_elemento );
102
-
103
-
104
- var PrintAreaWindow = getPrintWindow();
105
-
106
-
107
-
108
- write( PrintAreaWindow.doc, $printSource );
109
-
110
- setTimeout( function () { print( PrintAreaWindow ); }, 500 );
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
- function print ( PAWindow ) {
119
-
120
-
121
-
122
- var paWindow = PAWindow.win;
123
-
124
- $(PAWindow.doc).ready(function(){
125
-
126
- paWindow.focus();
127
- paWindow.print();
128
-
129
- });
130
- }
131
-
132
-
133
-
134
- function write ( PADocument, $ele ) {
135
-
136
-
137
-
138
- PADocument.open();
139
-
140
-
141
-
142
- //let HTML = docType() + "<html>" + getHead() + getBody( $ele ) + "</html>";
143
-
144
- let HTML = "<html>" + getHead() + getBody( $ele ) + "</html>";
145
-
146
-
147
- PADocument.write( HTML );
148
-
149
- PADocument.close();
150
- }
151
-
152
-
153
-
154
-
155
-
156
-
157
- function getHead(){
158
-
159
-
160
- var links = "";
161
-
162
-
163
-
164
- /** Busca Todos los Css y los Carga **/
165
- if (settings.defaultCss) {
166
-
167
- /*$(document).find("link").each(function(){
168
-
169
- links += '<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >';
170
-
171
- });
172
- */
173
- }
174
-
175
- /** En caso de que mandemos un CssExtra **/
176
- if ( settings.extraCss ) settings.extraCss.replace( /([^,\s]+)/g , function(m){ links += '<link type="text/css" rel="stylesheet" href="' + m + '">' });
177
-
178
-
179
- return "<head>" + links + "</head>";
180
- }
181
-
182
-
183
-
184
- function getBody ( elements ) {
185
-
186
-
187
- console.log(elements);
188
-
189
- return "<body>" + elements.innerHTML + "</body>";
190
- }
191
-
192
-
193
-
194
-
195
-
196
- function getFormData( ele ) {
197
-
198
-
199
-
200
- }
201
-
202
-
203
-
204
-
205
- function getPrintWindow () {
206
-
207
- var f = new Iframe();
208
-
209
- console.log(f);
210
-
211
- let data = {
212
-
213
- win : f.contentWindow || f,
214
-
215
- doc : f.doc
216
- };
217
-
218
-
219
- return data;
220
-
221
-
222
-
223
- }
224
-
225
-
226
-
227
-
228
-
229
- function Iframe() {
230
-
231
-
232
- var frameId = settings.id;
233
-
234
- //Estilos para ocultarlo
235
- var iframeStyle = 'border:0;position:absolute;width:0px;height:0px;right:0px;top:0px;';
236
-
237
- var iframe;
238
-
239
-
240
- /* Creamos un elemento Iframe **/
241
- iframe = document.createElement('iframe');
242
-
243
-
244
- /* Agregamos el iframe al inucio del documento */
245
- document.body.appendChild(iframe);
246
-
247
-
248
-
249
- $(iframe).attr(
250
-
251
- {
252
- style: iframeStyle,
253
- id: frameId,
254
- src: "#" + new Date().getTime()
255
- }
256
- );
257
-
258
-
259
-
260
- iframe.doc = null;
261
- iframe.doc = iframe.contentDocument ? iframe.contentDocument :( iframe.contentWindow ? iframe.contentWindow.document : iframe.document);
262
- return iframe;
263
- }
264
-
265
- function Popup() {
266
- var windowAttr = "location=yes,statusbar=no,directories=no,menubar=no,titlebar=no,toolbar=no,dependent=no";
267
- windowAttr += ",width=" + settings.popWd + ",height=" + settings.popHt;
268
- windowAttr += ",resizable=yes,screenX=" + settings.popX + ",screenY=" + settings.popY + ",personalbar=no,scrollbars=yes";
269
- var newWin = window.open( "", "_blank", windowAttr );
270
- newWin.doc = newWin.document;
271
- return newWin;
272
- }
273
-
274
-
275
- }
276
-
277
-
278
-
279
- module.exports = prindiv
280
-
281
-
282
-
283
-
284
-
285
-
286
-
287
-
288
-
289
-