2005-08-11 13:00:17 +00:00
|
|
|
// $Id$
|
2009-04-27 20:19:38 +00:00
|
|
|
(function ($) {
|
2005-08-11 13:00:17 +00:00
|
|
|
|
2006-12-10 09:05:47 +00:00
|
|
|
/**
|
2009-09-11 02:01:26 +00:00
|
|
|
* Toggle the visibility of a fieldset using smooth animations.
|
2006-12-10 09:05:47 +00:00
|
|
|
*/
|
2009-04-27 20:19:38 +00:00
|
|
|
Drupal.toggleFieldset = function (fieldset) {
|
2006-12-10 09:05:47 +00:00
|
|
|
if ($(fieldset).is('.collapsed')) {
|
2008-01-29 10:58:25 +00:00
|
|
|
// Action div containers are processed separately because of a IE bug
|
|
|
|
// that alters the default submit button behavior.
|
|
|
|
var content = $('> div:not(.action)', fieldset);
|
2009-10-16 19:20:34 +00:00
|
|
|
$(fieldset)
|
|
|
|
.removeClass('collapsed')
|
|
|
|
.trigger({ type: 'collapsed', value: false });
|
2007-07-12 18:24:24 +00:00
|
|
|
content.hide();
|
2009-04-26 19:18:46 +00:00
|
|
|
content.slideDown({
|
2007-07-12 18:24:24 +00:00
|
|
|
duration: 'fast',
|
|
|
|
easing: 'linear',
|
2009-04-27 20:19:38 +00:00
|
|
|
complete: function () {
|
2006-12-10 09:05:47 +00:00
|
|
|
Drupal.collapseScrollIntoView(this.parentNode);
|
|
|
|
this.parentNode.animating = false;
|
2008-01-29 10:58:25 +00:00
|
|
|
$('div.action', fieldset).show();
|
2007-06-04 10:36:42 +00:00
|
|
|
},
|
2009-04-27 20:19:38 +00:00
|
|
|
step: function () {
|
2009-09-11 02:01:26 +00:00
|
|
|
// Scroll the fieldset into view.
|
2007-06-04 10:36:42 +00:00
|
|
|
Drupal.collapseScrollIntoView(this.parentNode);
|
|
|
|
}
|
2006-12-10 09:05:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
2008-01-29 10:58:25 +00:00
|
|
|
$('div.action', fieldset).hide();
|
2009-10-16 19:20:34 +00:00
|
|
|
$(fieldset).trigger({ type: 'collapsed', value: true });
|
2009-04-27 20:19:38 +00:00
|
|
|
var content = $('> div:not(.action)', fieldset).slideUp('fast', function () {
|
2006-12-10 09:05:47 +00:00
|
|
|
$(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.
|
|
|
|
*/
|
2009-04-27 20:19:38 +00:00
|
|
|
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;
|
2007-09-12 18:29:32 +00:00
|
|
|
var posY = $(node).offset().top;
|
2006-08-31 23:31:25 +00:00
|
|
|
var fudge = 55;
|
2007-09-12 18:29:32 +00:00
|
|
|
if (posY + node.offsetHeight + fudge > h + offset) {
|
2006-08-31 23:31:25 +00:00
|
|
|
if (node.offsetHeight > h) {
|
2007-09-12 18:29:32 +00:00
|
|
|
window.scrollTo(0, posY);
|
2009-09-11 02:01:26 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-09-12 18:29:32 +00:00
|
|
|
window.scrollTo(0, posY + 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
|
|
|
|
2008-10-29 10:01:28 +00:00
|
|
|
Drupal.behaviors.collapse = {
|
2009-04-27 20:19:38 +00:00
|
|
|
attach: function (context, settings) {
|
2009-08-31 05:51:08 +00:00
|
|
|
$('fieldset.collapsible > legend', context).once('collapse', function () {
|
2008-10-29 10:01:28 +00:00
|
|
|
var fieldset = $(this.parentNode);
|
2009-09-11 02:01:26 +00:00
|
|
|
// Expand if there are errors inside.
|
2008-10-29 10:01:28 +00:00
|
|
|
if ($('input.error, textarea.error, select.error', fieldset).size() > 0) {
|
|
|
|
fieldset.removeClass('collapsed');
|
|
|
|
}
|
2006-12-10 09:05:47 +00:00
|
|
|
|
2009-04-11 22:19:46 +00:00
|
|
|
var summary = $('<span class="summary"></span>');
|
|
|
|
fieldset.
|
2009-04-27 20:19:38 +00:00
|
|
|
bind('summaryUpdated', function () {
|
2009-04-11 22:19:46 +00:00
|
|
|
var text = $.trim(fieldset.getSummary());
|
|
|
|
summary.html(text ? ' (' + text + ')' : '');
|
|
|
|
})
|
|
|
|
.trigger('summaryUpdated');
|
|
|
|
|
2009-09-11 02:01:26 +00:00
|
|
|
// Turn the legend into a clickable link and wrap the contents of the
|
|
|
|
// fieldset in a div for easier animation.
|
2008-10-29 10:01:28 +00:00
|
|
|
var text = this.innerHTML;
|
2009-04-27 20:19:38 +00:00
|
|
|
$(this).empty().append($('<a href="#">' + text + '</a>').click(function () {
|
2008-10-29 10:01:28 +00:00
|
|
|
var fieldset = $(this).parents('fieldset:first')[0];
|
2009-09-11 02:01:26 +00:00
|
|
|
// Don't animate multiple times.
|
2008-10-29 10:01:28 +00:00
|
|
|
if (!fieldset.animating) {
|
|
|
|
fieldset.animating = true;
|
|
|
|
Drupal.toggleFieldset(fieldset);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}))
|
2009-04-11 22:19:46 +00:00
|
|
|
.append(summary)
|
2009-08-31 05:51:08 +00:00
|
|
|
.after(
|
|
|
|
$('<div class="fieldset-wrapper"></div>')
|
|
|
|
.append(fieldset.children(':not(legend):not(.action)'))
|
|
|
|
);
|
2008-10-29 10:01:28 +00:00
|
|
|
});
|
|
|
|
}
|
2007-07-01 15:37:10 +00:00
|
|
|
};
|
2009-02-18 13:46:55 +00:00
|
|
|
|
|
|
|
})(jQuery);
|