Fix z-index ordering bug

This commit is contained in:
Niklas von Hertzen 2013-12-23 15:27:46 +02:00
parent 443fd17a12
commit 46cc8b6975

View File

@ -1,4 +1,13 @@
_html2canvas.Renderer = function(parseQueue, options){ _html2canvas.Renderer = function(parseQueue, options){
function sortZindex(a, b) {
if (a === 'children') {
return -1;
} else if (b === 'children') {
return 1;
} else {
return a - b;
}
}
// http://www.w3.org/TR/CSS21/zindex.html // http://www.w3.org/TR/CSS21/zindex.html
function createRenderQueue(parseQueue) { function createRenderQueue(parseQueue) {
@ -16,8 +25,9 @@ _html2canvas.Renderer = function(parseQueue, options){
childrenDest = specialParent; // where children without z-index should be pushed into childrenDest = specialParent; // where children without z-index should be pushed into
if (node.zIndex.ownStacking) { if (node.zIndex.ownStacking) {
// '!' comes before numbers in sorted array contextForChildren = stub.context = {
contextForChildren = stub.context = { '!': [{node:node, children: []}]}; children: [{node:node, children: []}]
};
childrenDest = undefined; childrenDest = undefined;
} else if (isPositioned || isFloated) { } else if (isPositioned || isFloated) {
childrenDest = stub.children = []; childrenDest = stub.children = [];
@ -39,7 +49,7 @@ _html2canvas.Renderer = function(parseQueue, options){
})(parseQueue); })(parseQueue);
function sortZ(context) { function sortZ(context) {
Object.keys(context).sort(function(a, b) { return a - b; }).forEach(function(zi) { Object.keys(context).sort(sortZindex).forEach(function(zi) {
var nonPositioned = [], var nonPositioned = [],
floated = [], floated = [],
positioned = [], positioned = [],