2005-08-11 13:00:17 +00:00
|
|
|
// $Id$
|
|
|
|
|
2006-12-10 09:05:47 +00:00
|
|
|
/**
|
|
|
|
* Toggle the visibility of a fieldset using smooth animations
|
|
|
|
*/
|
|
|
|
Drupal.toggleFieldset = function(fieldset) {
|
|
|
|
if ($(fieldset).is('.collapsed')) {
|
|
|
|
var content = $('> div', fieldset).hide();
|
|
|
|
$(fieldset).removeClass('collapsed');
|
2007-06-04 10:36:42 +00:00
|
|
|
content.slideDown( {
|
|
|
|
duration: 300,
|
|
|
|
complete: function() {
|
2006-12-10 09:05:47 +00:00
|
|
|
// Make sure we open to height auto
|
|
|
|
$(this).css('height', 'auto');
|
|
|
|
Drupal.collapseScrollIntoView(this.parentNode);
|
|
|
|
this.parentNode.animating = false;
|
2007-06-04 10:36:42 +00:00
|
|
|
},
|
|
|
|
step: function() {
|
|
|
|
// Scroll the fieldset into view
|
|
|
|
Drupal.collapseScrollIntoView(this.parentNode);
|
|
|
|
}
|
2006-12-10 09:05:47 +00:00
|
|
|
});
|
2007-06-01 09:05:45 +00:00
|
|
|
if (typeof(Drupal.textareaAttach) != 'undefined') {
|
2006-12-10 09:05:47 +00:00
|
|
|
// Initialize resizable textareas that are now revealed
|
|
|
|
Drupal.textareaAttach(null, fieldset);
|
2005-06-21 09:45:45 +00:00
|
|
|
}
|
2006-12-10 09:05:47 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
var content = $('> div', fieldset).slideUp('medium', function() {
|
|
|
|
$(this.parentNode).addClass('collapsed');
|
|
|
|
this.parentNode.animating = false;
|
|
|
|
});
|
|
|
|
}
|
2007-06-01 09:05: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) {
|
2007-01-11 03:38:31 +00:00
|
|
|
var h = self.innerHeight || document.documentElement.clientHeight || $('body')[0].clientHeight || 0;
|
|
|
|
var offset = self.pageYOffset || document.documentElement.scrollTop || $('body')[0].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
|
|
|
}
|
|
|
|
}
|
2007-06-01 09:05:45 +00:00
|
|
|
};
|
2006-08-31 23:31:25 +00:00
|
|
|
|
|
|
|
// Global Killswitch
|
|
|
|
if (Drupal.jsEnabled) {
|
2006-12-10 09:05:47 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
$('fieldset.collapsible > legend').each(function() {
|
|
|
|
var fieldset = $(this.parentNode);
|
|
|
|
// Expand if there are errors inside
|
|
|
|
if ($('input.error, textarea.error, select.error', fieldset).size() > 0) {
|
|
|
|
fieldset.removeClass('collapsed');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Turn the legend into a clickable link and wrap the contents of the fieldset
|
|
|
|
// in a div for easier animation
|
|
|
|
var text = this.innerHTML;
|
|
|
|
$(this).empty().append($('<a href="#">'+ text +'</a>').click(function() {
|
|
|
|
var fieldset = $(this).parents('fieldset:first')[0];
|
|
|
|
// Don't animate multiple times
|
|
|
|
if (!fieldset.animating) {
|
|
|
|
fieldset.animating = true;
|
|
|
|
Drupal.toggleFieldset(fieldset);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
})).after($('<div class="fieldset-wrapper"></div>').append(fieldset.children(':not(legend)')));
|
|
|
|
});
|
|
|
|
});
|
2006-08-31 23:31:25 +00:00
|
|
|
}
|