Skip to content

Commit c7d526c

Browse files
committed
simplified API and cleaned up code
1 parent bf99484 commit c7d526c

11 files changed

+203
-143
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ For more information and examples, please visit the <a href="http://html2canvas.
3737

3838
### Changelog ###
3939

40-
v0.33 -
40+
v0.33 - 2.3.2012
4141

4242
* SVG taint fix, and additional taint testing options for rendering (<a href="https://github.com/niklasvh/html2canvas/commit/2dc8b9385e656696cb019d615bdfa1d98b17d5d4">niklasvh</a>)
4343
* Added support for CORS images and option to create canvas as tainted (<a href="https://github.com/niklasvh/html2canvas/commit/3ad49efa0032cde25c6ed32a39e35d1505d3b2ef">niklasvh</a>)

src/Core.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@
55
66
Released under MIT License
77
*/
8+
"use strict";
89

9-
var html2canvas = {};
10+
var _html2canvas = {},
11+
html2canvas;
1012

11-
html2canvas.logging = false;
1213

1314
function h2clog(a) {
14-
if (html2canvas.logging && window.console && window.console.log) {
15+
if (_html2canvas.logging && window.console && window.console.log) {
1516
window.console.log(a);
1617
}
1718
}
1819

19-
html2canvas.log = h2clog; // for compatibility with the jquery plugin
20+
_html2canvas.Util = {};
2021

21-
html2canvas.Util = {};
22-
23-
html2canvas.Util.backgroundImage = function (src) {
22+
_html2canvas.Util.backgroundImage = function (src) {
2423

2524
if (/data:image\/.*;base64,/i.test( src ) || /^(-webkit|-moz|linear-gradient|-o-)/.test( src )) {
2625
return src;
@@ -37,7 +36,7 @@ html2canvas.Util.backgroundImage = function (src) {
3736
return src;
3837
};
3938

40-
html2canvas.Util.Bounds = function getBounds (el) {
39+
_html2canvas.Util.Bounds = function getBounds (el) {
4140
var clientRect,
4241
bounds = {};
4342

@@ -70,9 +69,9 @@ html2canvas.Util.Bounds = function getBounds (el) {
7069
7170
7271
} */
73-
}
72+
};
7473

75-
html2canvas.Util.getCSS = function (el, attribute) {
74+
_html2canvas.Util.getCSS = function (el, attribute) {
7675
// return jQuery(el).css(attribute);
7776
/*
7877
var val,
@@ -126,7 +125,7 @@ html2canvas.Util.getCSS = function (el, attribute) {
126125

127126
};
128127

129-
html2canvas.Util.Extend = function (options, defaults) {
128+
_html2canvas.Util.Extend = function (options, defaults) {
130129
var key;
131130
for (key in options) {
132131
if (options.hasOwnProperty(key)) {
@@ -136,7 +135,7 @@ html2canvas.Util.Extend = function (options, defaults) {
136135
return defaults;
137136
};
138137

139-
html2canvas.Util.Children = function(el) {
138+
_html2canvas.Util.Children = function(el) {
140139
// $(el).contents() !== el.childNodes, Opera / IE have issues with that
141140
var children;
142141
try {

src/Generate.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
Released under MIT License
77
*/
88

9-
html2canvas.Generate = {};
9+
_html2canvas.Generate = {};
1010

1111

1212

13-
html2canvas.Generate.Gradient = function(src, bounds) {
13+
_html2canvas.Generate.Gradient = function(src, bounds) {
1414
var canvas = document.createElement('canvas'),
1515
ctx = canvas.getContext('2d'),
1616
tmp,
@@ -35,22 +35,24 @@ html2canvas.Generate.Gradient = function(src, bounds) {
3535
var j = -1,
3636
color = '',
3737
chr;
38-
3938
while( j++ < input.length ) {
4039
chr = input.charAt( j );
4140
if (chr === ')') {
4241
color += chr;
4342
steps.push( color );
4443
color = '';
45-
while (j++ < input.length && input.charAt( j ) !== ',') {
44+
j = input.indexOf(",", j) + 1;
45+
if (j === 0) {
46+
break;
4647
}
48+
// while (j++ < input.length && input.charAt( j ) !== ',') {}
4749
} else {
4850
color += chr;
4951
}
5052
}
5153
}
5254

53-
if ( tmp = src.match(/-webkit-linear-gradient\((.*)\)/) ) {
55+
if ( (tmp = src.match(/-webkit-linear-gradient\((.*)\)/)) !== null ) {
5456

5557
position = tmp[1].split( ",", 1 )[0];
5658
getColors( tmp[1].substr( position.length + 2 ) );
@@ -78,7 +80,7 @@ html2canvas.Generate.Gradient = function(src, bounds) {
7880

7981
}
8082

81-
} else if (tmp = src.match(/-webkit-gradient\(linear, (\d+)[%]{0,1} (\d+)[%]{0,1}, (\d+)[%]{0,1} (\d+)[%]{0,1}, from\((.*)\), to\((.*)\)\)/)) {
83+
} else if ( (tmp = src.match(/-webkit-gradient\(linear, (\d+)[%]{0,1} (\d+)[%]{0,1}, (\d+)[%]{0,1} (\d+)[%]{0,1}, from\((.*)\), to\((.*)\)\)/)) !== null ) {
8284

8385
p0 = (tmp[1] * bounds.width) / 100;
8486
p1 = (tmp[2] * bounds.height) / 100;
@@ -88,7 +90,7 @@ html2canvas.Generate.Gradient = function(src, bounds) {
8890
steps.push(tmp[5]);
8991
steps.push(tmp[6]);
9092

91-
} else if (tmp = src.match(/-moz-linear-gradient\((\d+)[%]{0,1} (\d+)[%]{0,1}, (.*)\)/)) {
93+
} else if ( (tmp = src.match(/-moz-linear-gradient\((\d+)[%]{0,1} (\d+)[%]{0,1}, (.*)\)/)) !== null ) {
9294

9395
p0 = (tmp[1] * bounds.width) / 100;
9496
p1 = (tmp[2] * bounds.width) / 100;
@@ -122,9 +124,9 @@ html2canvas.Generate.Gradient = function(src, bounds) {
122124

123125
return img;
124126

125-
}
127+
};
126128

127-
html2canvas.Generate.ListAlpha = function(number) {
129+
_html2canvas.Generate.ListAlpha = function(number) {
128130
var tmp = "",
129131
modulus;
130132

@@ -135,9 +137,9 @@ html2canvas.Generate.ListAlpha = function(number) {
135137
}while((number*26) > 26);
136138

137139
return tmp;
138-
}
140+
};
139141

140-
html2canvas.Generate.ListRoman = function(number) {
142+
_html2canvas.Generate.ListRoman = function(number) {
141143
var romanArray = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"],
142144
decimal = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1],
143145
roman = "",
@@ -157,4 +159,4 @@ html2canvas.Generate.ListRoman = function(number) {
157159

158160
return roman;
159161

160-
}
162+
};

0 commit comments

Comments
 (0)