easyprintand 1.0.5 → 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 (2) hide show
  1. package/package.json +1 -1
  2. package/prindiv.js +280 -235
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easyprintand",
3
- "version": "1.0.5",
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 CHANGED
@@ -13,7 +13,7 @@
13
13
  * $("div.PrintArea").printArea( [OPTIONS] );
14
14
  * });
15
15
  * </script>
16
- * options are passed as json (example: {mode: "popup", popClose: false})
16
+ * options are passed as json (example: {mode: "popup", popClose: false})
17
17
  *
18
18
  * {OPTIONS} | [type] | (default), values | Explanation
19
19
  * --------- | --------- | ---------------------- | -----------
@@ -38,258 +38,303 @@
38
38
  * PARA INICIAR ASI:
39
39
  *
40
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
- var counter = 0;
54
- var modes = { iframe : "iframe", popup : "popup" };
55
- var standards = { strict : "strict", loose : "loose", html5 : "html5" };
56
- var defaults = { mode : modes.iframe,
57
- standard : standards.html5,
58
- popHt : 500,
59
- popWd : 400,
60
- popX : 200,
61
- popY : 200,
62
- popTitle : '',
63
- popClose : false,
64
- extraCss : '',
65
- defaultCss : true,
66
- extraHead : '',
67
- retainAttr : ["id","class","style"] };
68
-
69
- var settings = {};//global settings
70
-
71
-
72
-
73
-
74
-
75
- //Combiamos el arrayd
76
- Object.assign(settings, defaults, options);
77
-
78
- //El Id del documento
79
- counter++;
80
-
81
-
82
-
83
- var idPrefix = "printArea_";
84
-
85
- //Se Renova el documento actial
86
- data = document.querySelector("[id^=" + idPrefix + "]" )
87
- if (data) {
88
- data.remove();
89
- }
90
-
91
-
92
- // ID Siguiente
93
- settings.id = idPrefix + counter;
94
-
95
-
96
-
97
-
98
-
99
- var $printSource = document.querySelector("div#" + id_elemento );
100
-
101
-
102
- var PrintAreaWindow = getPrintWindow();
103
-
104
-
105
-
106
- write( PrintAreaWindow.doc, $printSource );
107
-
108
- setTimeout( function () { print( PrintAreaWindow ); }, 500 );
109
-
41
+ *
42
+ *
43
+
110
44
 
45
+ import prindiv from 'easyprintand';
111
46
 
47
+ <div id='EasyPrintAnd'>
48
+ <div>
49
+ <h1>texto para imprmir </h1>
50
+ asdadadad
51
+ sada
52
+ </div>
53
+ </div>
112
54
 
113
55
 
56
+ <button onClick={ () => prindiv('EasyPrintAnd' , { extraCss : './tirilla.css' })}>Print</button>
114
57
 
58
+ */
115
59
 
116
- function print ( PAWindow ) {
60
+ 'use strict';
117
61
 
118
- var paWindow = PAWindow.win;
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
+
119
73
 
120
-
121
-
122
-
123
-
124
- setTimeout( function () {
125
-
126
- paWindow.focus();
127
- paWindow.print();
128
-
129
- }, 300 );
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"] };
130
85
 
131
- }
132
-
133
-
134
-
135
- function write ( PADocument, $ele ) {
136
-
137
-
138
-
139
- PADocument.open();
140
-
141
-
142
-
143
- //let HTML = docType() + "<html>" + getHead() + getBody( $ele ) + "</html>";
144
-
145
- let HTML = "<html>" + getHead() + getBody( $ele ) + "</html>";
146
-
147
-
148
- PADocument.write( HTML );
149
-
150
- PADocument.close();
151
- }
152
-
153
-
154
-
155
-
156
-
157
-
158
- function getHead(){
159
-
160
-
161
- var links = "";
162
-
163
-
164
-
165
- /** Busca Todos los Css y los Carga **/
166
- if (settings.defaultCss) {
167
-
168
- /*$(document).find("link").each(function(){
169
-
170
- links += '<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >';
171
-
172
- });
173
- */
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();
174
107
  }
175
-
176
- /** En caso de que mandemos un CssExtra **/
177
- if ( settings.extraCss ) settings.extraCss.replace( /([^,\s]+)/g , function(m){ links += '<link type="text/css" rel="stylesheet" href="' + m + '">' });
178
-
108
+
109
+
110
+ // ID Siguiente
111
+ settings.id = idPrefix + counter;
112
+
113
+
179
114
 
180
- return "<head>" + links + "</head>";
181
- }
182
115
 
183
-
184
-
185
- function getBody ( elements ) {
186
-
187
-
188
- console.log(elements);
189
-
190
- return "<body>" + elements.innerHTML + "</body>";
191
- }
192
-
193
-
194
-
195
-
196
-
197
- function getFormData( ele ) {
198
-
199
-
200
-
201
- }
202
-
203
-
204
-
205
-
206
- function getPrintWindow () {
207
-
208
- var f = new Iframe();
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 **/
209
191
 
210
- console.log(f);
211
-
212
- let data = {
213
-
214
- win : f.contentWindow || f,
215
-
216
- doc : f.doc
217
- };
218
-
219
-
220
- return data;
221
-
222
-
223
-
224
- }
225
-
226
-
227
-
228
-
229
-
230
- function Iframe() {
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 ) {
231
229
 
232
-
233
- var frameId = settings.id;
234
-
235
- //Estilos para ocultarlo
236
- var iframeStyle = 'border:0;position:absolute;width:0px;height:0px;right:0px;top:0px;';
237
-
238
- var iframe;
239
-
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
+ }
240
317
 
241
- /* Creamos un elemento Iframe **/
242
- iframe = document.createElement('iframe');
243
-
244
-
245
- /* Agregamos el iframe al inucio del documento */
246
- document.body.appendChild(iframe);
247
-
248
-
249
-
250
-
251
-
252
- iframe.setAttribute("style", iframeStyle );
253
- iframe.setAttribute("id", frameId );
254
- iframe.setAttribute("src", "#" + new Date().getTime() );
255
-
256
318
 
257
-
258
- iframe.doc = null;
259
- iframe.doc = iframe.contentDocument ? iframe.contentDocument :( iframe.contentWindow ? iframe.contentWindow.document : iframe.document);
260
- return iframe;
261
319
  }
262
320
 
263
- function Popup() {
264
- var windowAttr = "location=yes,statusbar=no,directories=no,menubar=no,titlebar=no,toolbar=no,dependent=no";
265
- windowAttr += ",width=" + settings.popWd + ",height=" + settings.popHt;
266
- windowAttr += ",resizable=yes,screenX=" + settings.popX + ",screenY=" + settings.popY + ",personalbar=no,scrollbars=yes";
267
- var newWin = window.open( "", "_blank", windowAttr );
268
- newWin.doc = newWin.document;
269
- return newWin;
270
- }
271
-
272
-
273
- }
274
-
275
-
276
-
277
-
278
-
279
-
280
-
281
-
282
-
283
-
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
- module.exports = prindiv
292
-
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+ module.exports = prindiv;
293
338
 
294
339
 
295
340