Refactoring

This commit is contained in:
Niklas von Hertzen 2013-08-06 17:46:47 +03:00
parent 02ab96dc5f
commit 2777a3e079

View File

@ -223,14 +223,14 @@ _html2canvas.Parse = function (images, options) {
return bounds; return bounds;
} }
function elementIndex( el ) { function elementIndex(el) {
var i = -1, var i = -1,
count = 1, count = 1,
childs = el.parentNode.childNodes; childs = el.parentNode.childNodes;
if (el.parentNode) { if (el.parentNode) {
while( childs[ ++i ] !== el ) { while(childs[++i] !== el) {
if ( childs[ i ].nodeType === 1 ) { if (childs[i].nodeType === 1) {
count++; count++;
} }
} }
@ -241,8 +241,7 @@ _html2canvas.Parse = function (images, options) {
} }
function listItemText(element, type) { function listItemText(element, type) {
var currentIndex = elementIndex(element), var currentIndex = elementIndex(element), text;
text;
switch(type){ switch(type){
case "decimal": case "decimal":
text = currentIndex; text = currentIndex;
@ -264,8 +263,7 @@ _html2canvas.Parse = function (images, options) {
break; break;
} }
text += ". "; return text + ". ";
return text;
} }
function renderListItem(element, stack, elBounds) { function renderListItem(element, stack, elBounds) {
@ -293,11 +291,7 @@ _html2canvas.Parse = function (images, options) {
function loadImage (src){ function loadImage (src){
var img = images[src]; var img = images[src];
if (img && img.succeeded === true) { return (img && img.succeeded === true) ? img.img : false;
return img.img;
} else {
return false;
}
} }
function clipBounds(src, dst){ function clipBounds(src, dst){
@ -317,8 +311,8 @@ _html2canvas.Parse = function (images, options) {
function setZ(element, stack, parentStack){ function setZ(element, stack, parentStack){
var newContext, var newContext,
isPositioned = stack.cssPosition !== 'static', isPositioned = stack.cssPosition !== 'static',
zIndex = isPositioned ? getCSS(element, 'zIndex') : 'auto', // z-index only applies to positioned elements. zIndex = isPositioned ? getCSS(element, 'zIndex') : 'auto',
opacity = getCSS(element, 'opacity'), // can't use stack.opacity because it's blended opacity = getCSS(element, 'opacity'),
isFloated = getCSS(element, 'cssFloat') !== 'none'; isFloated = getCSS(element, 'cssFloat') !== 'none';
// https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context // https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context
@ -332,10 +326,7 @@ _html2canvas.Parse = function (images, options) {
newContext.isPositioned = isPositioned; newContext.isPositioned = isPositioned;
newContext.isFloated = isFloated; newContext.isFloated = isFloated;
newContext.opacity = opacity; newContext.opacity = opacity;
newContext.ownStacking = (zIndex !== 'auto' || opacity < 1);
if (zIndex !== 'auto' || opacity < 1) {
newContext.ownStacking = true;
}
if (parentStack) { if (parentStack) {
parentStack.zIndex.children.push(stack); parentStack.zIndex.children.push(stack);