Skip to content

Commit 3d7a637

Browse files
committed
bug fixes
1 parent 4579fb2 commit 3d7a637

6 files changed

Lines changed: 78 additions & 71 deletions

File tree

src/Core.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ _html2canvas.Util.Children = function(el) {
213213
var children;
214214
try {
215215
children = $(el).contents();
216+
// children = (el.nodeName && el.nodeName.toUpperCase() === "IFRAME") ? el.contentDocument || el.contentWindow.document : Array.prototype.push.call([], el.childNodes );
216217
} catch (ex) {
217218
h2clog("html2canvas.Util.Children failed with exception: " + ex.message);
218219
children = [];

src/Preload.js

Lines changed: 68 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
_html2canvas.Preload = function( options ) {
10-
10+
1111
var images = {
1212
numLoaded: 0, // also failed are counted here
1313
numFailed: 0,
@@ -31,30 +31,30 @@ _html2canvas.Preload = function( options ) {
3131
link.href = window.location.href;
3232
pageOrigin = link.protocol + link.host;
3333

34-
35-
36-
37-
38-
34+
35+
36+
37+
38+
3939
function isSameOrigin(url){
40-
link.href = url;
40+
link.href = url;
4141
link.href = link.href; // YES, BELIEVE IT OR NOT, that is required for IE9 - http://jsfiddle.net/niklasvh/2e48b/
42-
var origin = link.protocol + link.host;
42+
var origin = link.protocol + link.host;
4343
return (origin === pageOrigin);
4444
}
45-
45+
4646
function start(){
4747
h2clog("html2canvas: start: images: " + images.numLoaded + " / " + images.numTotal + " (failed: " + images.numFailed + ")");
4848
if (!images.firstRun && images.numLoaded >= images.numTotal){
4949
h2clog("Finished loading images: # " + images.numTotal + " (failed: " + images.numFailed + ")");
50-
50+
5151
if (typeof options.complete === "function"){
5252
options.complete(images);
5353
}
54-
54+
5555
}
5656
}
57-
57+
5858
// TODO modify proxy to serve images with CORS enabled, where available
5959
function proxyGetImage(url, img, imageObj){
6060
var callback_name,
@@ -66,7 +66,7 @@ _html2canvas.Preload = function( options ) {
6666

6767
callback_name = 'html2canvas_' + (count++);
6868
imageObj.callbackname = callback_name;
69-
69+
7070
if (scriptUrl.indexOf("?") > -1) {
7171
scriptUrl += "&";
7272
} else {
@@ -80,10 +80,10 @@ _html2canvas.Preload = function( options ) {
8080
imageObj.succeeded = false;
8181
images.numLoaded++;
8282
images.numFailed++;
83-
start();
83+
start();
8484
} else {
8585
setImageLoadHandlers(img, imageObj);
86-
img.src = a;
86+
img.src = a;
8787
}
8888
window[callback_name] = undefined; // to work with IE<9 // NOTE: that the undefined callback property-name still exists on the window object (for IE<9)
8989
try {
@@ -101,13 +101,13 @@ _html2canvas.Preload = function( options ) {
101101
window.document.body.appendChild(script);
102102

103103
}
104-
104+
105105
function getImages (el) {
106-
107-
108-
106+
107+
108+
109109
// if (!this.ignoreRe.test(el.nodeName)){
110-
//
110+
//
111111

112112
var contents = _html2canvas.Util.Children(el),
113113
i,
@@ -116,14 +116,14 @@ _html2canvas.Preload = function( options ) {
116116
src,
117117
img,
118118
elNodeType = false;
119-
119+
120120
for (i = 0; i < contentsLen; i+=1 ){
121121
// var ignRe = new RegExp("("+this.ignoreElements+")");
122122
// if (!ignRe.test(element.nodeName)){
123123
getImages(contents[i]);
124124
// }
125125
}
126-
126+
127127
// }
128128
try {
129129
elNodeType = el.nodeType;
@@ -133,59 +133,59 @@ _html2canvas.Preload = function( options ) {
133133
}
134134

135135
if (elNodeType === 1 || elNodeType === undefined){
136-
136+
137137
// opera throws exception on external-content.html
138138
try {
139139
background_image = _html2canvas.Util.getCSS(el, 'backgroundImage');
140140
}catch(e) {
141141
h2clog("html2canvas: failed to get background-image - Exception: " + e.message);
142142
}
143-
if ( background_image && background_image !== "1" && background_image !== "none" ) {
144-
143+
if ( background_image && background_image !== "1" && background_image !== "none" ) {
144+
145145
// TODO add multi image background support
146-
146+
147147
if (background_image.substring(0,7) === "-webkit" || background_image.substring(0,3) === "-o-" || background_image.substring(0,4) === "-moz") {
148-
148+
149149
img = _html2canvas.Generate.Gradient( background_image, _html2canvas.Util.Bounds( el ) );
150150

151151
if ( img !== undefined ){
152152
images[background_image] = {
153-
img: img,
153+
img: img,
154154
succeeded: true
155155
};
156156
images.numTotal++;
157157
images.numLoaded++;
158158
start();
159-
159+
160160
}
161-
162-
} else {
163-
src = _html2canvas.Util.backgroundImage(background_image.match(/data:image\/.*;base64,/i) ? background_image : background_image.split(",")[0]);
161+
162+
} else {
163+
src = _html2canvas.Util.backgroundImage(background_image.match(/data:image\/.*;base64,/i) ? background_image : background_image.split(",")[0]);
164164
methods.loadImage(src);
165165
}
166-
166+
167167
/*
168168
if (background_image && background_image !== "1" && background_image !== "none" && background_image.substring(0,7) !== "-webkit" && background_image.substring(0,3)!== "-o-" && background_image.substring(0,4) !== "-moz"){
169169
// TODO add multi image background support
170-
src = html2canvas.Util.backgroundImage(background_image.split(",")[0]);
171-
methods.loadImage(src); */
170+
src = html2canvas.Util.backgroundImage(background_image.split(",")[0]);
171+
methods.loadImage(src); */
172172
}
173173
}
174-
}
175-
174+
}
175+
176176
function setImageLoadHandlers(img, imageObj) {
177177
img.onload = function() {
178178
if ( imageObj.timer !== undefined ) {
179179
// CORS succeeded
180180
window.clearTimeout( imageObj.timer );
181181
}
182-
182+
183183
images.numLoaded++;
184184
imageObj.succeeded = true;
185185
start();
186186
};
187187
img.onerror = function() {
188-
188+
189189
if (img.crossOrigin === "anonymous") {
190190
// CORS failed
191191
window.clearTimeout( imageObj.timer );
@@ -201,40 +201,41 @@ _html2canvas.Preload = function( options ) {
201201
return;
202202
}
203203
}
204-
205-
204+
205+
206206
images.numLoaded++;
207207
images.numFailed++;
208208
imageObj.succeeded = false;
209209
start();
210-
210+
211211
};
212-
212+
213213
// TODO Opera has no load/error event for SVG images
214-
214+
215215
// Opera ninja onload's cached images
216+
/*
216217
window.setTimeout(function(){
217218
if ( img.width !== 0 && imageObj.succeeded === undefined ) {
218219
img.onload();
219-
}
220+
}
220221
}, 100); // needs a reflow for base64 encoded images? interestingly timeout of 0 doesn't work but 1 does.
221-
222+
*/
222223
}
223-
224+
224225

225226
methods = {
226227
loadImage: function( src ) {
227-
var img, imageObj;
228+
var img, imageObj;
228229
if ( src && images[src] === undefined ) {
229-
img = new Image();
230+
img = new Image();
230231
if ( src.match(/data:image\/.*;base64,/i) ) {
231232
img.src = src.replace(/url\(['"]{0,}|['"]{0,}\)$/ig, '');
232233
imageObj = images[src] = {
233234
img: img
234235
};
235236
images.numTotal++;
236237
setImageLoadHandlers(img, imageObj);
237-
} else if ( isSameOrigin( src ) || options.allowTaint === true ) {
238+
} else if ( isSameOrigin( src ) || options.allowTaint === true ) {
238239
imageObj = images[src] = {
239240
img: img
240241
};
@@ -243,34 +244,34 @@ _html2canvas.Preload = function( options ) {
243244
img.src = src;
244245
} else if ( supportCORS && !options.allowTaint && options.useCORS ) {
245246
// attempt to load with CORS
246-
247-
img.crossOrigin = "anonymous";
247+
248+
img.crossOrigin = "anonymous";
248249
imageObj = images[src] = {
249250
img: img
250251
};
251252
images.numTotal++;
252253
setImageLoadHandlers(img, imageObj);
253-
img.src = src;
254-
254+
img.src = src;
255+
255256
// work around for https://bugs.webkit.org/show_bug.cgi?id=80028
256257
img.customComplete = function () {
257-
if (!this.img.complete) {
258+
if (!this.img.complete) {
258259
this.timer = window.setTimeout(this.img.customComplete, 100);
259-
} else {
260-
this.img.onerror();
260+
} else {
261+
this.img.onerror();
261262
}
262-
}.bind(imageObj);
263+
}.bind(imageObj);
263264
img.customComplete();
264-
265+
265266
} else if ( options.proxy ) {
266267
imageObj = images[src] = {
267268
img: img
268269
};
269270
images.numTotal++;
270271
proxyGetImage( src, img, imageObj );
271272
}
272-
}
273-
273+
}
274+
274275
},
275276
cleanupDOM: function(cause) {
276277
var img, src;
@@ -321,7 +322,7 @@ _html2canvas.Preload = function( options ) {
321322
window.clearTimeout(timeoutTimer);
322323
}
323324
}
324-
325+
325326
};
326327

327328
if (options.timeout > 0) {
@@ -331,21 +332,21 @@ _html2canvas.Preload = function( options ) {
331332
images.firstRun = true;
332333

333334
getImages( element );
334-
335+
335336
h2clog('html2canvas: Preload: Finding images');
336337
// load <img> images
337338
for (i = 0; i < imgLen; i+=1){
338339
methods.loadImage( domImages[i].getAttribute( "src" ) );
339340
}
340-
341+
341342
images.firstRun = false;
342343
h2clog('html2canvas: Preload: Done.');
343344
if ( images.numTotal === images.numLoaded ) {
344345
start();
345-
}
346-
346+
}
347+
347348
return methods;
348-
349+
349350
};
350351

351352

src/Renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ _html2canvas.Renderer = function(parseQueue, options){
5959

6060
sortZ(parseQueue.zIndex);
6161
if ( typeof options.renderer._create !== "function" ) {
62-
throw Error("Invalid renderer defined");
62+
throw new Error("Invalid renderer defined");
6363
}
6464
return options.renderer._create( parseQueue, options, document, queue, _html2canvas );
6565

src/renderers/Canvas.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ html2canvas.Renderer.Canvas = function( options ) {
219219

220220
return canvas;
221221
}
222-
}
222+
};
223223

224224
return methods;
225225

tests/origin.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
<head>
44
<script type="text/javascript" src="test.js"></script>
55
<script type="text/javascript">
6-
h2cSelector = '#bar';
6+
function setUp(){
7+
h2cSelector = '#bar';
8+
}
9+
710
</script>
811
<title>
912
display/box/float/clear test

tests/test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ var h2cSelector, h2cOptions;
1414
document.write(scrStart + '../src/' + html2canvas[i] + '.js' + scrEnd);
1515
}
1616
window.onload = function() {
17+
h2cSelector = [document.body];
18+
1719
if (window.setUp) {
1820
window.setUp();
1921
}
20-
h2cSelector = [document.body];
22+
2123
setTimeout(function() {
2224

2325
$(h2cSelector).html2canvas($.extend({

0 commit comments

Comments
 (0)