The findParentRatio function:
function findParentRatio(jqObject) {
var p = jqObject.parent(),
displayType = p.css('display');
if (displayType == 'block' || displayType == '-webkit-box' && p.width() > 0) {
return { obj: p, width: p.width(), height: p.height(), ratio: (p.width() / p.height()) };
} else {
return findParentRatio(p);
}
}
can cause infinite recursion (e.g. when the element is not in the DOM yet).
I suggest something like:
function findParentRatio(jqObject) {
var p = jqObject.parent(),
displayType = p.css('display');
if (!p) {
return a default or throw error here.
}
if (displayType == 'block' || displayType == '-webkit-box' && p.width() > 0) {
return { obj: p, width: p.width(), height: p.height(), ratio: (p.width() / p.height()) };
} else {
return findParentRatio(p);
}
}
Also, this approach doesn't mesh well with some MVC frameworks (like Backbone),
where views are rendered before they're added to the DOM.
Can't think of another way to do it at the moment though :(
The findParentRatio function:
can cause infinite recursion (e.g. when the element is not in the DOM yet).
I suggest something like:
Also, this approach doesn't mesh well with some MVC frameworks (like Backbone),
where views are rendered before they're added to the DOM.
Can't think of another way to do it at the moment though :(