fix warnings reported by the closure compiler

This commit is contained in:
MoyuScript 2012-02-18 19:57:33 +01:00
parent 5ac70956db
commit 072e1645cf
4 changed files with 79 additions and 97 deletions

View File

@ -106,13 +106,9 @@ html2canvas.Parse = function (element, images, opts) {
} }
function getCSS (element, attribute, intOnly) { var getCSS = html2canvas.Util.getCSS;
function getCSSInt(element, attribute) {
if (intOnly !== undefined && intOnly === true) { return parseInt(getCSS(element, attribute), 10);
return parseInt(html2canvas.Util.getCSS(element, attribute), 10);
}else{
return html2canvas.Util.getCSS(element, attribute);
}
} }
// Drawing a rectangle // Drawing a rectangle
@ -231,19 +227,19 @@ html2canvas.Parse = function (element, images, opts) {
function renderText(el, textNode, stack) { function renderText(el, textNode, stack) {
var ctx = stack.ctx, var ctx = stack.ctx,
family = getCSS(el, "fontFamily", false), family = getCSS(el, "fontFamily"),
size = getCSS(el, "fontSize", false), size = getCSS(el, "fontSize"),
color = getCSS(el, "color", false), color = getCSS(el, "color"),
text_decoration = getCSS(el, "textDecoration", false), text_decoration = getCSS(el, "textDecoration"),
text_align = getCSS(el, "textAlign", false), text_align = getCSS(el, "textAlign"),
letter_spacing = getCSS(el, "letterSpacing", false), letter_spacing = getCSS(el, "letterSpacing"),
bounds, bounds,
text, text,
metrics, metrics,
renderList, renderList,
bold = getCSS(el, "fontWeight", false), bold = getCSS(el, "fontWeight"),
font_style = getCSS(el, "fontStyle", false), font_style = getCSS(el, "fontStyle"),
font_variant = getCSS(el, "fontVariant", false), font_variant = getCSS(el, "fontVariant"),
align = false, align = false,
newTextNode, newTextNode,
textValue, textValue,
@ -259,7 +255,7 @@ html2canvas.Parse = function (element, images, opts) {
textNode.nodeValue = textTransform(textNode.nodeValue, getCSS(el, "textTransform", false)); textNode.nodeValue = textTransform(textNode.nodeValue, getCSS(el, "textTransform"));
text = trimText(textNode.nodeValue); text = trimText(textNode.nodeValue);
if (text.length>0){ if (text.length>0){
@ -426,10 +422,10 @@ html2canvas.Parse = function (element, images, opts) {
function renderListItem(element, stack, elBounds) { function renderListItem(element, stack, elBounds) {
var position = getCSS(element, "listStylePosition", false), var position = getCSS(element, "listStylePosition"),
x, x,
y, y,
type = getCSS(element, "listStyleType", false), type = getCSS(element, "listStyleType"),
currentIndex, currentIndex,
text, text,
listBounds, listBounds,
@ -483,8 +479,8 @@ html2canvas.Parse = function (element, images, opts) {
ctx.setVariable( "fillStyle", getCSS(element, "color", false) ); ctx.setVariable( "fillStyle", getCSS(element, "color") );
ctx.setVariable( "font", getCSS(element, "fontVariant", false) + " " + bold + " " + getCSS(element, "fontStyle", false) + " " + getCSS(element, "fontFize", false) + " " + getCSS(element, "fontFamily", false) ); ctx.setVariable( "font", getCSS(element, "fontVariant") + " " + bold + " " + getCSS(element, "fontStyle") + " " + getCSS(element, "fontSize") + " " + getCSS(element, "fontFamily") );
if ( position === "inside" ) { if ( position === "inside" ) {
@ -549,13 +545,13 @@ html2canvas.Parse = function (element, images, opts) {
// TODO fix static elements overlapping relative/absolute elements under same stack, if they are defined after them // TODO fix static elements overlapping relative/absolute elements under same stack, if they are defined after them
if (!parentZ){ if (!parentZ){
this.zStack = new html2canvas.zContext(0); this.zStack = h2czContext(0);
return this.zStack; return this.zStack;
} }
if (zIndex !== "auto"){ if (zIndex !== "auto"){
needReorder = true; needReorder = true;
var newContext = new html2canvas.zContext(zIndex); var newContext = h2czContext(zIndex);
parentZ.children.push(newContext); parentZ.children.push(newContext);
return newContext; return newContext;
@ -589,8 +585,8 @@ html2canvas.Parse = function (element, images, opts) {
for (s = 0; s < 4; s+=1){ for (s = 0; s < 4; s+=1){
borders.push({ borders.push({
width: getCSS(el, 'border' + sides[s] + 'Width', true), width: getCSSInt(el, 'border' + sides[s] + 'Width'),
color: getCSS(el, 'border' + sides[s] + 'Color', false) color: getCSS(el, 'border' + sides[s] + 'Color')
}); });
} }
@ -666,7 +662,7 @@ html2canvas.Parse = function (element, images, opts) {
for (i = 0, arrLen = cssArr.length; i < arrLen; i+=1){ for (i = 0, arrLen = cssArr.length; i < arrLen; i+=1){
style = cssArr[i]; style = cssArr[i];
valueWrap.style[style] = getCSS(el, style, false); valueWrap.style[style] = getCSS(el, style);
} }
@ -675,7 +671,7 @@ html2canvas.Parse = function (element, images, opts) {
valueWrap.style.display = "block"; valueWrap.style.display = "block";
valueWrap.style.position = "absolute"; valueWrap.style.position = "absolute";
if (/^(submit|reset|button|text|password)$/.test(el.type) || el.nodeName === "SELECT"){ if (/^(submit|reset|button|text|password)$/.test(el.type) || el.nodeName === "SELECT"){
valueWrap.style.lineHeight = getCSS(el, "height", false); valueWrap.style.lineHeight = getCSS(el, "height");
} }
@ -844,8 +840,8 @@ html2canvas.Parse = function (element, images, opts) {
function renderBackground(el,bounds,ctx){ function renderBackground(el,bounds,ctx){
// TODO add support for multi background-images // TODO add support for multi background-images
var background_image = getCSS(el, "backgroundImage", false), var background_image = getCSS(el, "backgroundImage"),
background_repeat = getCSS(el, "backgroundRepeat", false).split(",")[0], background_repeat = getCSS(el, "backgroundRepeat").split(",")[0],
image, image,
bgp, bgp,
bgy, bgy,
@ -1007,10 +1003,10 @@ html2canvas.Parse = function (element, images, opts) {
w = bounds.width, w = bounds.width,
h = bounds.height, h = bounds.height,
image, image,
bgcolor = getCSS(el, "backgroundColor", false), bgcolor = getCSS(el, "backgroundColor"),
cssPosition = getCSS(el, "position", false), cssPosition = getCSS(el, "position"),
zindex, zindex,
opacity = getCSS(el, "opacity", false), opacity = getCSS(el, "opacity"),
stack, stack,
stackLength, stackLength,
borders, borders,
@ -1022,7 +1018,7 @@ html2canvas.Parse = function (element, images, opts) {
paddingRight, paddingRight,
paddingBottom; paddingBottom;
if (parentStack === undefined){ if (!parentStack){
docDim = docSize(); docDim = docSize();
parentStack = { parentStack = {
opacity: 1 opacity: 1
@ -1034,12 +1030,12 @@ html2canvas.Parse = function (element, images, opts) {
//var zindex = this.formatZ(this.getCSS(el,"zIndex"),cssPosition,parentStack.zIndex,el.parentNode); //var zindex = this.formatZ(this.getCSS(el,"zIndex"),cssPosition,parentStack.zIndex,el.parentNode);
zindex = setZ( getCSS( el, "zIndex", false ), parentStack.zIndex ); zindex = setZ( getCSS( el, "zIndex"), parentStack.zIndex );
stack = { stack = {
ctx: new html2canvas.canvasContext( docDim.width || w , docDim.height || h ), ctx: html2canvas.canvasContext( docDim.width || w , docDim.height || h ),
zIndex: zindex, zIndex: zindex,
opacity: opacity * parentStack.opacity, opacity: opacity * parentStack.opacity,
cssPosition: cssPosition cssPosition: cssPosition
@ -1072,7 +1068,7 @@ html2canvas.Parse = function (element, images, opts) {
ctx.setVariable("globalAlpha", stack.opacity); ctx.setVariable("globalAlpha", stack.opacity);
// draw element borders // draw element borders
borders = renderBorders(el, ctx, bounds); borders = renderBorders(el, ctx, bounds, false);
stack.borders = borders; stack.borders = borders;
@ -1130,10 +1126,10 @@ html2canvas.Parse = function (element, images, opts) {
image = loadImage(imgSrc); image = loadImage(imgSrc);
if (image){ if (image){
paddingLeft = getCSS(el, 'paddingLeft', true); paddingLeft = getCSSInt(el, 'paddingLeft');
paddingTop = getCSS(el, 'paddingTop', true); paddingTop = getCSSInt(el, 'paddingTop');
paddingRight = getCSS(el, 'paddingRight', true); paddingRight = getCSSInt(el, 'paddingRight');
paddingBottom = getCSS(el, 'paddingBottom', true); paddingBottom = getCSSInt(el, 'paddingBottom');
renderImage( renderImage(
@ -1188,10 +1184,10 @@ html2canvas.Parse = function (element, images, opts) {
renderListItem(el, stack, bgbounds); renderListItem(el, stack, bgbounds);
break; break;
case "CANVAS": case "CANVAS":
paddingLeft = getCSS(el, 'paddingLeft', true); paddingLeft = getCSSInt(el, 'paddingLeft');
paddingTop = getCSS(el, 'paddingTop', true); paddingTop = getCSSInt(el, 'paddingTop');
paddingRight = getCSS(el, 'paddingRight', true); paddingRight = getCSSInt(el, 'paddingRight');
paddingBottom = getCSS(el, 'paddingBottom', true); paddingBottom = getCSSInt(el, 'paddingBottom');
renderImage( renderImage(
ctx, ctx,
el, el,
@ -1241,7 +1237,7 @@ html2canvas.Parse = function (element, images, opts) {
} }
} }
stack = renderElement(element); stack = renderElement(element, null);
// parse every child element // parse every child element
for (i = 0, children = element.children, childrenLen = children.length; i < childrenLen; i+=1){ for (i = 0, children = element.children, childrenLen = children.length; i < childrenLen; i+=1){
@ -1252,7 +1248,7 @@ html2canvas.Parse = function (element, images, opts) {
}; };
html2canvas.zContext = function(zindex) { function h2czContext(zindex) {
return { return {
zindex: zindex, zindex: zindex,
children: [] children: []

View File

@ -313,19 +313,19 @@ html2canvas.Preload = function(element, opts){
timeoutTimer = window.setTimeout(methods.cleanupDOM, options.timeout); timeoutTimer = window.setTimeout(methods.cleanupDOM, options.timeout);
} }
var startTime = (new Date()).getTime(); var startTime = (new Date()).getTime();
this.log('html2canvas: Preload starts: finding background-images'); html2canvas.log('html2canvas: Preload starts: finding background-images');
images.firstRun = true; images.firstRun = true;
getImages( element ); getImages( element );
this.log('html2canvas: Preload: Finding images'); html2canvas.log('html2canvas: Preload: Finding images');
// load <img> images // load <img> images
for (i = 0; i < imgLen; i+=1){ for (i = 0; i < imgLen; i+=1){
methods.loadImage( domImages[i].getAttribute( "src" ) ); methods.loadImage( domImages[i].getAttribute( "src" ) );
} }
images.firstRun = false; images.firstRun = false;
this.log('html2canvas: Preload: Done.'); html2canvas.log('html2canvas: Preload: Done.');
if ( images.numTotal === images.numLoaded ) { if ( images.numTotal === images.numLoaded ) {
start(); start();
} }

View File

@ -6,52 +6,38 @@
Released under MIT License Released under MIT License
*/ */
html2canvas.canvasContext = function (width, height) { html2canvas.canvasContext = function (width, height) {
this.storage = []; var storage = [];
this.width = width; return {
this.height = height; storage: storage,
//this.zIndex; width: width,
height: height,
this.fillRect = function(){ fillRect: function () {
this.storage.push( storage.push({
{ type: "function",
type: "function", name: "fillRect",
name: "fillRect", 'arguments': arguments
'arguments': arguments });
}); },
drawImage: function () {
}; storage.push({
type: "function",
name: "drawImage",
this.drawImage = function () { 'arguments': arguments
this.storage.push( });
{ },
type: "function", fillText: function () {
name: "drawImage", storage.push({
'arguments': arguments type: "function",
}); name: "fillText",
}; 'arguments': arguments
});
},
this.fillText = function () { setVariable: function (variable, value) {
storage.push({
this.storage.push(
{
type: "function",
name: "fillText",
'arguments': arguments
});
};
this.setVariable = function(variable, value) {
this.storage.push(
{
type: "variable", type: "variable",
name: variable, name: variable,
'arguments': value 'arguments': value
}); });
}
}; };
return this;
}; };

View File

@ -368,13 +368,13 @@ html2canvas.Renderer = function(parseQueue, opts){
case "canvas": case "canvas":
canvas = doc.createElement('canvas'); canvas = doc.createElement('canvas');
if (canvas.getContext){ if (canvas.getContext){
this.log("html2canvas: Renderer: using canvas renderer"); html2canvas.log("html2canvas: Renderer: using canvas renderer");
return canvasRenderer(parseQueue); return canvasRenderer(parseQueue);
} }
break; break;
case "svg": case "svg":
if (doc.createElementNS){ if (doc.createElementNS){
this.log("html2canvas: Renderer: using SVG renderer"); html2canvas.log("html2canvas: Renderer: using SVG renderer");
return svgRenderer(parseQueue); return svgRenderer(parseQueue);
} }
break; break;