Skip to content

Commit 0e73a6a

Browse files
committed
Update examples, make sure doc is available before updating preview
1 parent 42f0635 commit 0e73a6a

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

examples/js/basic.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,32 +110,32 @@ function demoUserInput() {
110110
doc.text(20, 20, 'Answers');
111111
doc.setFontSize(16);
112112

113-
for(var i = 1; i <= 12; i ++) {
113+
for (i = 1; i <= 12; i ++) {
114114
doc.text(20, 30 + (i * 10), i + ' x ' + multiplier + ' = ' + (i * multiplier));
115-
}
115+
}
116116
doc.save('Test.pdf');
117117

118118
}
119119

120-
function demoRectangles() {
120+
function demoRectangles() {
121121
var doc = new jsPDF();
122122

123123
doc.rect(20, 20, 10, 10); // empty square
124124

125125
doc.rect(40, 20, 10, 10, 'F'); // filled square
126126

127-
doc.setDrawColor(255,0,0);
127+
doc.setDrawColor(255, 0, 0);
128128
doc.rect(60, 20, 10, 10); // empty red square
129129

130-
doc.setDrawColor(255,0,0);
130+
doc.setDrawColor(255, 0, 0);
131131
doc.rect(80, 20, 10, 10, 'FD'); // filled square with red borders
132132

133133
doc.setDrawColor(0);
134-
doc.setFillColor(255,0,0);
134+
doc.setFillColor(255, 0, 0);
135135
doc.rect(100, 20, 10, 10, 'F'); // filled red square
136136

137137
doc.setDrawColor(0);
138-
doc.setFillColor(255,0,0);
138+
doc.setFillColor(255, 0, 0);
139139
doc.rect(120, 20, 10, 10, 'FD'); // filled red square with black borders
140140

141141
doc.setDrawColor(0);
@@ -145,7 +145,7 @@ function demoRectangles() {
145145
doc.save('Test.pdf');
146146
}
147147

148-
function demoLines() {
148+
function demoLines() {
149149
var doc = new jsPDF();
150150

151151
doc.line(20, 20, 60, 20); // horizontal line
@@ -213,11 +213,14 @@ function demoImages() {
213213
// when running local files. Run with: chromium --allow-file-access-from-files --allow-file-access
214214
// to temporarily get around this issue.
215215
var getImageFromUrl = function(url, callback) {
216-
var img = new Image, data, ret={data: null, pending: true};
216+
var img = new Image(), data, ret = {
217+
data: null,
218+
pending: true
219+
};
217220

218221
img.onError = function() {
219222
throw new Error('Cannot load image: "'+url+'"');
220-
}
223+
};
221224
img.onload = function() {
222225
var canvas = document.createElement('canvas');
223226
document.body.appendChild(canvas);
@@ -229,19 +232,19 @@ function demoImages() {
229232
// Grab the image as a jpeg encoded in base64, but only the data
230233
data = canvas.toDataURL('image/jpeg').slice('data:image/jpeg;base64,'.length);
231234
// Convert the data to binary form
232-
data = atob(data)
235+
data = atob(data);
233236
document.body.removeChild(canvas);
234237

235238
ret['data'] = data;
236239
ret['pending'] = false;
237240
if (typeof callback === 'function') {
238241
callback(data);
239242
}
240-
}
243+
};
241244
img.src = url;
242245

243246
return ret;
244-
}
247+
};
245248

246249
// Since images are loaded asyncronously, we must wait to create
247250
// the pdf until we actually have the image data.
@@ -306,7 +309,7 @@ function demoStringSplitting() {
306309
}
307310

308311
function demoFromHTML() {
309-
var pdf = new jsPDF('p','in','letter')
312+
var pdf = new jsPDF('p', 'in', 'letter');
310313

311314
// source can be HTML-formatted string, or a reference
312315
// to an actual DOM element from which the text will be scraped.

examples/js/editor.js

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)