os0x / AutoPatchWork

http://code.google.com/p/autopatchwork/
32 stars 17 forks source link

calc_remain_height function accepts off-display nodes #4

Open Dither opened 11 years ago

Dither commented 11 years ago

The calc_remain_height shouldn't accept nodes that don't have visual representation, like script or style, but it does and it breaks extension on some pages. Here is the corrected version:

        function calc_remain_height() {
            var rect = null, bottom = null, _point = insert_point;
            while (_point) {
                if (typeof _point.getBoundingClientRect === 'function') {
                    rect = _point.getBoundingClientRect();
                    if (rect && !(rect.top === 0 && rect.right === 0 && rect.bottom === 0 && rect.left === 0)) break;
                    else rect = null;
                }
                if (_point.nextSibling) _point = _point.nextSibling;
                else break; 
            }
            if (rect) {
                bottom = rect.top + window.pageYOffset;
            } else if (append_point && typeof append_point.getBoundingClientRect === 'function') {
                rect = append_point.getBoundingClientRect();
                bottom = rect.top + rect.height + window.pageYOffset;
            }
            if (!bottom) bottom = Math.round(rootNode.scrollHeight * 0.8);
            return rootNode.scrollHeight - bottom + options.BASE_REMAIN_HEIGHT;
        }