var elementmaxheight = function() { this.initialize.apply(this, arguments); } elementmaxheight.prototype = { initialize: function(classname) { this.elements = document.getelementsbyclassname(classname || 'maxheight'); this.textelement = document.createelement('span'); this.textelement.appendchild(document.createtextnode('a')); this.textelement.style.display = 'block'; this.textelement.style.position = 'absolute'; this.textelement.style.fontsize = '1em'; this.textelement.style.top = '-1000px'; this.textelement.style.left = '-1000px'; document.body.appendchild(this.textelement); this.textelementheight = document.getdimensions(this.textelement).height; var __object = this; var __checkfontsize = this.checkfontsize; this.checkfontsizeinterval = window.setinterval(function() {return __checkfontsize.apply(__object)}, 500); this.expand(); // refresh elements height onresize event var __expand = this.expand; if (window.addeventlistener) { window.addeventlistener('resize', function(event) {return __expand.apply(__object, [( event || window.event)])}, false); } else if (window.attachevent) { window.attachevent('onresize', function(event) {return __expand.apply(__object, [( event || window.event)])}); } }, expand: function() { this.reset(); for (var i = 0; i < this.elements.length; i++) { this.elements[i].style.height = document.getdimensions(this.elements[i].parentnode).height + 'px'; } }, reset: function() { for (var i = 0; i < this.elements.length; i++) { this.elements[i].style.height = 'auto'; } }, checkfontsize: function() { var height = document.getdimensions(this.textelement).height; if(this.textelementheight != height) { this.textelementheight = height; this.expand(); } } } if (!!document.evaluate) { document._getelementsbyxpath = function(expression, parentelement) { var results = []; var query = document.evaluate(expression, parentelement || document, null, xpathresult.ordered_node_snapshot_type, null); for (var i = 0, length = query.snapshotlength; i < length; i++) results.push(query.snapshotitem(i)); return results; } } document.getelementsbyclassname = function(classname, parentelement) { if (!!document.evaluate) { var q = ".//*[contains(concat(' ', @class, ' '), ' " + classname + " ')]"; return document._getelementsbyxpath(q, parentelement); } else { var children = (parentelement || document.body).getelementsbytagname('*'); var elements = [], child; for (var i = 0, length = children.length; i < length; i++) { child = children[i]; if (child.classname.length != 0 && (child.classname == classname || child.classname.match(new regexp("(^|\\s)" + classname + "(\\s|$)")))) { elements.push(child); } } return elements; } } document.getdimensions = function (element) { var display = element.style.display; if (display != 'none' && display != null) { // safari bug return {width: element.offsetwidth, height: element.offsetheight}; } return {width: originalwidth, height: originalheight}; }