2005-08-11 13:00:17 +00:00
|
|
|
// $Id$
|
|
|
|
|
2006-08-31 23:31:25 +00:00
|
|
|
Drupal.collapseAutoAttach = function () {
|
|
|
|
$('fieldset.collapsible legend').each(function () {
|
|
|
|
// Turn the legend into clickable link
|
2005-06-21 09:45:45 +00:00
|
|
|
var a = document.createElement('a');
|
|
|
|
a.href = '#';
|
2006-08-31 23:31:25 +00:00
|
|
|
$(a)
|
|
|
|
.click(function() {
|
|
|
|
var fieldset = this.parentNode.parentNode;
|
|
|
|
|
|
|
|
// Prevent double animations
|
|
|
|
if (fieldset.animating) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fieldset.animating = true;
|
|
|
|
|
|
|
|
if ($(fieldset).is('.collapsed')) {
|
|
|
|
// Open fieldset with animation
|
|
|
|
$(fieldset.contentWrapper).hide();
|
|
|
|
$(fieldset).removeClass('collapsed');
|
|
|
|
$(fieldset.contentWrapper).slideDown(300,
|
|
|
|
{
|
|
|
|
// Make sure we open to height auto
|
|
|
|
complete: function() {
|
|
|
|
$(fieldset.contentWrapper).css('height', 'auto');
|
|
|
|
Drupal.collapseScrollIntoView(fieldset);
|
|
|
|
fieldset.animating = false;
|
|
|
|
},
|
|
|
|
// Scroll the fieldset into view
|
|
|
|
step: function() {
|
|
|
|
Drupal.collapseScrollIntoView(fieldset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (typeof Drupal.textareaAttach != 'undefined') {
|
|
|
|
// Initialize resizable textareas that are now revealed
|
|
|
|
Drupal.textareaAttach(null, fieldset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Collapse fieldset with animation (reverse of opening)
|
|
|
|
$(fieldset.contentWrapper)
|
|
|
|
.slideUp('medium', function () { $(fieldset).addClass('collapsed'); fieldset.animating = false; } )
|
|
|
|
.show();
|
2006-04-12 16:07:39 +00:00
|
|
|
}
|
2006-08-31 23:31:25 +00:00
|
|
|
return false;
|
|
|
|
})
|
|
|
|
.html(this.innerHTML);
|
|
|
|
$(this)
|
|
|
|
.empty()
|
|
|
|
.append(a);
|
|
|
|
|
|
|
|
// Wrap fieldsets contents (except for the legend) into wrapper divs for animating.
|
|
|
|
// div1 is used to avoid margin problems inside fieldsets,
|
|
|
|
// div2 is the one that is actually animated.
|
|
|
|
var div1 = document.createElement('div');
|
|
|
|
var div2 = document.createElement('div');
|
|
|
|
this.parentNode.contentWrapper = div2;
|
|
|
|
$(this).after(div1);
|
|
|
|
$(div1).append(div2);
|
|
|
|
var el = div1.nextSibling;
|
|
|
|
while (el != null) {
|
|
|
|
var next = el.nextSibling;
|
|
|
|
$(el).remove();
|
|
|
|
$(div2).append(el);
|
|
|
|
el = next;
|
2005-06-21 09:45:45 +00:00
|
|
|
}
|
2006-08-31 23:31:25 +00:00
|
|
|
// Avoid jumping around due to margins collapsing into fieldset border
|
|
|
|
$(div1).css('overflow', 'hidden');
|
2005-06-21 09:45:45 +00:00
|
|
|
|
2006-08-31 23:31:25 +00:00
|
|
|
// Expand if there are errors inside
|
|
|
|
if ($('input.error, textarea.error, select.error', this.parentNode).size() > 0) {
|
|
|
|
$(this.parentNode).removeClass('collapsed');
|
2005-06-21 09:45:45 +00:00
|
|
|
}
|
2006-08-31 23:31:25 +00:00
|
|
|
});
|
2005-06-21 09:45:45 +00:00
|
|
|
}
|
2006-02-07 02:29:06 +00:00
|
|
|
|
2006-08-31 23:31:25 +00:00
|
|
|
/**
|
|
|
|
* Scroll a given fieldset into view as much as possible.
|
|
|
|
*/
|
|
|
|
Drupal.collapseScrollIntoView = function (node) {
|
2006-02-07 02:29:06 +00:00
|
|
|
var h = self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0;
|
|
|
|
var offset = self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
|
2006-08-31 23:31:25 +00:00
|
|
|
var pos = Drupal.absolutePosition(node);
|
|
|
|
var fudge = 55;
|
|
|
|
if (pos.y + node.offsetHeight + fudge > h + offset) {
|
|
|
|
if (node.offsetHeight > h) {
|
2006-02-07 02:29:06 +00:00
|
|
|
window.scrollTo(0, pos.y);
|
|
|
|
} else {
|
2006-08-31 23:31:25 +00:00
|
|
|
window.scrollTo(0, pos.y + node.offsetHeight - h + fudge);
|
2006-02-07 02:29:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-08-31 23:31:25 +00:00
|
|
|
|
|
|
|
// Global Killswitch
|
|
|
|
if (Drupal.jsEnabled) {
|
|
|
|
$(document).ready(Drupal.collapseAutoAttach);
|
|
|
|
}
|