/* html2canvas @VERSION@ Copyright (c) 2011 Niklas von Hertzen. All rights reserved. http://www.twitter.com/niklasvh Released under MIT License */ _html2canvas.Renderer = function(parseQueue, options){ var queue = []; function sortZ(zStack){ var subStacks = [], stackValues = [], zStackChildren = zStack.children, s, i, stackLen, zValue, zLen, stackChild, b, subStackLen; for (s = 0, zLen = zStackChildren.length; s < zLen; s+=1){ stackChild = zStackChildren[s]; if (stackChild.children && stackChild.children.length > 0){ subStacks.push(stackChild); stackValues.push(stackChild.zindex); }else{ queue.push(stackChild); } } stackValues.sort(function(a, b) { return a - b; }); for (i = 0, stackLen = stackValues.length; i < stackLen; i+=1){ zValue = stackValues[i]; for (b = 0, subStackLen = subStacks.length; b <= subStackLen; b+=1){ if (subStacks[b].zindex === zValue){ stackChild = subStacks.splice(b, 1); sortZ(stackChild[0]); break; } } } } sortZ(parseQueue.zIndex); if ( typeof options._renderer._create !== "function" ) { throw new Error("Invalid renderer defined"); } return options._renderer._create( parseQueue, options, document, queue, _html2canvas ); };