Bonjour,

j'utilise la bibliothèque JSPDF pour générer des fichiers PDF.
Ca marche pas trop mal mais pour apporter des améliorations, je cherche à comprendre le code.
Et je ne saisi pas vraiment toute la syntaxe (NDLR: je débute en JS )
Je met ci-dessous le code en question, largement élagué histoire de s'attarder sur le plus important :
- que veut dire (typeof self !== "undefined" && self || typeof window !== "undefined" && window || this)); ?
- que signifie cette répétition de blocs (function (jsPDFAPI) { code etc ..... })(jsPDF.API);
- dans ce bloc (jsPDF.API); ne me semble pas être une valeur de retour : du coup à quoi ça sert ?

Voilà, ce sont peut être des questions de noobs, mais j'en suis là
Merci pour votre aide

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
var jsPDF = (function(global) {
       'use strict';
       var pdfVersion = '1.3',
             pageFormats = { // Size in pt of various paper formats 
				etc....         };
 

       /**
       * @constructor  @private
       */
       function jsPDF(orientation, unit, format, compressPdf) {
			
                code etc .....			
             return API;
       }
      
       jsPDF.API = {events:[]};
       jsPDF.version = "1.0.272-debug 2014-09-29T15:09:diegocr";
       if (typeof define === 'function' && define.amd) {
             define('jsPDF', function() {
                    return jsPDF;
             });
       } else {
             global.jsPDF = jsPDF;
       }
       return jsPDF;
}(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this));


(function(jsPDFAPI) {
       'use strict'
       var namespace = 'addImage_',
       supported_image_types = ['jpeg', 'jpg', 'png'];

                   code etc .....	

       jsPDFAPI.processJPG = function(/*
       * data, index, alias, compression,
       * dataAsBinaryString
       */) {
             return this.processJPEG.apply(this, arguments);
       }
})(jsPDF.API);


(function (jsPDFAPI) {
       'use strict';
       jsPDFAPI.autoPrint = function () {
             'use strict'
             var refAutoPrintTag;
             this.internal.events.subscribe('postPutResources', function () {
                    refAutoPrintTag = this.internal.newObject()
                    this.internal.write("<< /S/Named /Type/Action /N/Print >>", "endobj");
             });
             this.internal.events.subscribe("putCatalog", function () {
                    this.internal.write("/OpenAction " + refAutoPrintTag + " 0" + " R");
             });
             return this;
       };
})(jsPDF.API);


(function (jsPDFAPI) {
       'use strict';
       /* jslint browser:true */
       /* global document: false, jsPDF */
       var fontName,
     
                code etc .....	
	 
             if (tempHeaderConf.length > 0){
                    this.setTableHeaderRow(tempHeaderConf);
             }
             this.setFontStyle('normal');
             this.printingHeaderRow = false;
       };
})(jsPDF.API);



(function (jsPDFAPI) {
       
code etc .....	
})(jsPDF.API);

;(function(API) {
       'use strict'
  	
                code etc .....	
  
             return output
       }
})(jsPDF.API);


;(function(API) {
       'use strict'
      
                      code etc .....	
}
]) // end of adding event handler
})(jsPDF.API);


(function (view) {
       "use strict";
       view.URL = view.URL || view.webkitURL;
     		
                code etc .....	
	 
       return builder.getBlob(type);
};
}(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this));

code etc .....