Skip to content

Commit

Permalink
simplified API and cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasvh committed Mar 2, 2012
1 parent bf99484 commit c7d526c
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 143 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ For more information and examples, please visit the <a href="http://html2canvas.

### Changelog ###

v0.33 -
v0.33 - 2.3.2012

* SVG taint fix, and additional taint testing options for rendering (<a href="https://github.com/niklasvh/html2canvas/commit/2dc8b9385e656696cb019d615bdfa1d98b17d5d4">niklasvh</a>)
* Added support for CORS images and option to create canvas as tainted (<a href="https://github.com/niklasvh/html2canvas/commit/3ad49efa0032cde25c6ed32a39e35d1505d3b2ef">niklasvh</a>)
Expand Down
23 changes: 11 additions & 12 deletions src/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
Released under MIT License
*/
"use strict";

var html2canvas = {};
var _html2canvas = {},
html2canvas;

html2canvas.logging = false;

function h2clog(a) {
if (html2canvas.logging && window.console && window.console.log) {
if (_html2canvas.logging && window.console && window.console.log) {
window.console.log(a);
}
}

html2canvas.log = h2clog; // for compatibility with the jquery plugin
_html2canvas.Util = {};

html2canvas.Util = {};

html2canvas.Util.backgroundImage = function (src) {
_html2canvas.Util.backgroundImage = function (src) {

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

html2canvas.Util.Bounds = function getBounds (el) {
_html2canvas.Util.Bounds = function getBounds (el) {
var clientRect,
bounds = {};

Expand Down Expand Up @@ -70,9 +69,9 @@ html2canvas.Util.Bounds = function getBounds (el) {
} */
}
};

html2canvas.Util.getCSS = function (el, attribute) {
_html2canvas.Util.getCSS = function (el, attribute) {
// return jQuery(el).css(attribute);
/*
var val,
Expand Down Expand Up @@ -126,7 +125,7 @@ html2canvas.Util.getCSS = function (el, attribute) {

};

html2canvas.Util.Extend = function (options, defaults) {
_html2canvas.Util.Extend = function (options, defaults) {
var key;
for (key in options) {
if (options.hasOwnProperty(key)) {
Expand All @@ -136,7 +135,7 @@ html2canvas.Util.Extend = function (options, defaults) {
return defaults;
};

html2canvas.Util.Children = function(el) {
_html2canvas.Util.Children = function(el) {
// $(el).contents() !== el.childNodes, Opera / IE have issues with that
var children;
try {
Expand Down
26 changes: 14 additions & 12 deletions src/Generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
Released under MIT License
*/

html2canvas.Generate = {};
_html2canvas.Generate = {};



html2canvas.Generate.Gradient = function(src, bounds) {
_html2canvas.Generate.Gradient = function(src, bounds) {
var canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d'),
tmp,
Expand All @@ -35,22 +35,24 @@ html2canvas.Generate.Gradient = function(src, bounds) {
var j = -1,
color = '',
chr;

while( j++ < input.length ) {
chr = input.charAt( j );
if (chr === ')') {
color += chr;
steps.push( color );
color = '';
while (j++ < input.length && input.charAt( j ) !== ',') {
j = input.indexOf(",", j) + 1;
if (j === 0) {
break;
}
// while (j++ < input.length && input.charAt( j ) !== ',') {}
} else {
color += chr;
}
}
}

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

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

}

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

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

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

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

return img;

}
};

html2canvas.Generate.ListAlpha = function(number) {
_html2canvas.Generate.ListAlpha = function(number) {
var tmp = "",
modulus;

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

return tmp;
}
};

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

return roman;

}
};
Loading

0 comments on commit c7d526c

Please sign in to comment.