| 1 |
// $Id: collapse.js,v 1.10 2007/01/11 03:38:31 unconed Exp $
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Toggle the visibility of a fieldset using smooth animations
|
| 5 |
*/
|
| 6 |
Drupal.toggleFieldset = function(fieldset) {
|
| 7 |
if ($(fieldset).is('.collapsed')) {
|
| 8 |
var content = $('> div', fieldset).hide();
|
| 9 |
$(fieldset).removeClass('collapsed');
|
| 10 |
content.slideDown(300, {
|
| 11 |
complete: function() {
|
| 12 |
// Make sure we open to height auto
|
| 13 |
$(this).css('height', 'auto');
|
| 14 |
Drupal.collapseScrollIntoView(this.parentNode);
|
| 15 |
this.parentNode.animating = false;
|
| 16 |
},
|
| 17 |
step: function() {
|
| 18 |
// Scroll the fieldset into view
|
| 19 |
Drupal.collapseScrollIntoView(this.parentNode);
|
| 20 |
}
|
| 21 |
});
|
| 22 |
if (typeof Drupal.textareaAttach != 'undefined') {
|
| 23 |
// Initialize resizable textareas that are now revealed
|
| 24 |
Drupal.textareaAttach(null, fieldset);
|
| 25 |
}
|
| 26 |
}
|
| 27 |
else {
|
| 28 |
var content = $('> div', fieldset).slideUp('medium', function() {
|
| 29 |
$(this.parentNode).addClass('collapsed');
|
| 30 |
this.parentNode.animating = false;
|
| 31 |
});
|
| 32 |
}
|
| 33 |
}
|
| 34 |
|
| 35 |
/**
|
| 36 |
* Scroll a given fieldset into view as much as possible.
|
| 37 |
*/
|
| 38 |
Drupal.collapseScrollIntoView = function (node) {
|
| 39 |
var h = self.innerHeight || document.documentElement.clientHeight || $('body')[0].clientHeight || 0;
|
| 40 |
var offset = self.pageYOffset || document.documentElement.scrollTop || $('body')[0].scrollTop || 0;
|
| 41 |
var pos = Drupal.absolutePosition(node);
|
| 42 |
var fudge = 55;
|
| 43 |
if (pos.y + node.offsetHeight + fudge > h + offset) {
|
| 44 |
if (node.offsetHeight > h) {
|
| 45 |
window.scrollTo(0, pos.y);
|
| 46 |
} else {
|
| 47 |
window.scrollTo(0, pos.y + node.offsetHeight - h + fudge);
|
| 48 |
}
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
| 52 |
// Global Killswitch
|
| 53 |
if (Drupal.jsEnabled) {
|
| 54 |
$(document).ready(function() {
|
| 55 |
$('fieldset.collapsible > legend').each(function() {
|
| 56 |
var fieldset = $(this.parentNode);
|
| 57 |
// Expand if there are errors inside
|
| 58 |
if ($('input.error, textarea.error, select.error', fieldset).size() > 0) {
|
| 59 |
fieldset.removeClass('collapsed');
|
| 60 |
}
|
| 61 |
|
| 62 |
// Turn the legend into a clickable link and wrap the contents of the fieldset
|
| 63 |
// in a div for easier animation
|
| 64 |
var text = this.innerHTML;
|
| 65 |
$(this).empty().append($('<a href="#">'+ text +'</a>').click(function() {
|
| 66 |
var fieldset = $(this).parents('fieldset:first')[0];
|
| 67 |
// Don't animate multiple times
|
| 68 |
if (!fieldset.animating) {
|
| 69 |
fieldset.animating = true;
|
| 70 |
Drupal.toggleFieldset(fieldset);
|
| 71 |
}
|
| 72 |
return false;
|
| 73 |
})).after($('<div class="fieldset-wrapper"></div>').append(fieldset.children(':not(legend)')));
|
| 74 |
});
|
| 75 |
});
|
| 76 |
}
|