From d67a0503470dab86995196905494e47797ab0563 Mon Sep 17 00:00:00 2001 From: Steven Wittens Date: Tue, 7 Feb 2006 02:29:06 +0000 Subject: [PATCH] - #39674: Scroll fieldsets into view when expanding them --- misc/collapse.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/misc/collapse.js b/misc/collapse.js index 2f5c8dc064c9..387bf376fc27 100644 --- a/misc/collapse.js +++ b/misc/collapse.js @@ -20,6 +20,9 @@ function collapseAutoAttach() { a.href = '#'; a.onclick = function() { toggleClass(this.parentNode.parentNode, 'collapsed'); + if (!hasClass(this.parentNode.parentNode, 'collapsed')) { + collapseScrollIntoView(this.parentNode.parentNode); + } this.blur(); return false; }; @@ -48,3 +51,16 @@ function collapseEnsureErrorsVisible(fieldset) { } } } + +function collapseScrollIntoView(node) { + var h = self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0; + var offset = self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; + var pos = absolutePosition(node); + if (pos.y + node.scrollHeight > h + offset) { + if (node.scrollHeight > h) { + window.scrollTo(0, pos.y); + } else { + window.scrollTo(0, pos.y + node.scrollHeight - h); + } + } +}