fix(ionHeaderBar): make it align after elements properly load

Addresses #945.
This commit is contained in:
Andy Joslin
2014-04-08 13:21:03 -06:00
parent 6a1ac355a8
commit d00aaa5945

View File

@@ -22,39 +22,40 @@
return;
}
var i, c, childSize;
var childNodes = this.el.childNodes;
var leftWidth = 0;
var rightWidth = 0;
var isCountingRightWidth = false;
var self = this;
//We have to rAF here so all of the elements have time to initialize
ionic.requestAnimationFrame(function() {
var i, c, childSize;
var childNodes = self.el.childNodes;
var leftWidth = 0;
var rightWidth = 0;
var isCountingRightWidth = false;
// Compute how wide the left children are
// Skip all titles (there may still be two titles, one leaving the dom)
// Once we encounter a titleEl, realize we are now counting the right-buttons, not left
for(i = 0; i < childNodes.length; i++) {
c = childNodes[i];
if (c.tagName && c.tagName.toLowerCase() == 'h1') {
isCountingRightWidth = true;
continue;
}
// Compute how wide the left children are
// Skip all titles (there may still be two titles, one leaving the dom)
// Once we encounter a titleEl, realize we are now counting the right-buttons, not left
for(i = 0; i < childNodes.length; i++) {
c = childNodes[i];
if (c.tagName && c.tagName.toLowerCase() == 'h1') {
isCountingRightWidth = true;
continue;
}
childSize = null;
if(c.nodeType == 3) {
childSize = ionic.DomUtil.getTextBounds(c);
} else if(c.nodeType == 1) {
childSize = c.getBoundingClientRect();
}
if(childSize) {
if (isCountingRightWidth) {
rightWidth += childSize.width;
} else {
leftWidth += childSize.width;
childSize = null;
if(c.nodeType == 3) {
childSize = ionic.DomUtil.getTextBounds(c).width;
} else if(c.nodeType == 1) {
childSize = c.offsetWidth;
}
if(childSize) {
if (isCountingRightWidth) {
rightWidth += childSize;
} else {
leftWidth += childSize;
}
}
}
}
var self = this;
ionic.requestAnimationFrame(function() {
var margin = Math.max(leftWidth, rightWidth) + 10;
// Size and align the header titleEl based on the sizes of the left and