From 7818e2d4603d352c0a20574051ec72c9727a190d Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 3 Mar 2010 19:46:26 +0000 Subject: - Patch #676800 by casey, sun, james.elliott, cosmicdreams, seutje, Jacine: made fieldsets work on all browser. --- misc/collapse.js | 97 ++++++++++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 52 deletions(-) (limited to 'misc') diff --git a/misc/collapse.js b/misc/collapse.js index a976345dc..ffacce9cb 100644 --- a/misc/collapse.js +++ b/misc/collapse.js @@ -5,40 +5,33 @@ * Toggle the visibility of a fieldset using smooth animations. */ Drupal.toggleFieldset = function (fieldset) { - if ($(fieldset).is('.collapsed')) { - // Action div containers are processed separately because of a IE bug - // that alters the default submit button behavior. - var content = $('> div:not(.action)', fieldset); - $(fieldset) + var $fieldset = $(fieldset); + if ($fieldset.is('.collapsed')) { + var $content = $('> .fieldset-wrapper', fieldset).hide(); + $fieldset .removeClass('collapsed') .trigger({ type: 'collapsed', value: false }) - .find('> legend > a > span.element-invisible') - .empty() - .append(Drupal.t('Hide')); - content.hide(); - content.slideDown({ + .find('> legend span.fieldset-legend-prefix').html(Drupal.t('Hide')); + $content.slideDown({ duration: 'fast', easing: 'linear', complete: function () { - Drupal.collapseScrollIntoView(this.parentNode); - this.parentNode.animating = false; - $('div.action', fieldset).show(); + Drupal.collapseScrollIntoView(fieldset); + fieldset.animating = false; }, step: function () { // Scroll the fieldset into view. - Drupal.collapseScrollIntoView(this.parentNode); + Drupal.collapseScrollIntoView(fieldset); } }); } else { - $('div.action', fieldset).hide(); - $(fieldset).trigger({ type: 'collapsed', value: true }); - var content = $('> div:not(.action)', fieldset).slideUp('fast', function () { - $(this.parentNode).addClass('collapsed') - .find('> legend > a > span.element-invisible') - .empty() - .append(Drupal.t('Show')); - this.parentNode.animating = false; + $fieldset.trigger({ type: 'collapsed', value: true }); + $('> .fieldset-wrapper', fieldset).slideUp('fast', function () { + $fieldset + .addClass('collapsed') + .find('> legend span.fieldset-legend-prefix').html(Drupal.t('Show')); + fieldset.animating = false; }); } }; @@ -63,45 +56,45 @@ Drupal.collapseScrollIntoView = function (node) { Drupal.behaviors.collapse = { attach: function (context, settings) { - $('fieldset.collapsible > legend', context).once('collapse', function () { - var fieldset = $(this.parentNode); + $('fieldset.collapsible', context).once('collapse', function () { + var $fieldset = $(this); // Expand if there are errors inside. - if ($('input.error, textarea.error, select.error', fieldset).size() > 0) { - fieldset.removeClass('collapsed'); + if ($('.error', $fieldset).length) { + $fieldset.removeClass('collapsed'); } var summary = $(''); - fieldset. + $fieldset. bind('summaryUpdated', function () { - var text = $.trim(fieldset.getSummary()); + var text = $.trim($fieldset.getSummary()); summary.html(text ? ' (' + text + ')' : ''); }) .trigger('summaryUpdated'); - // 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($('' + text + '') - .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; - }) - .prepend($('') - .append(fieldset.hasClass('collapsed') ? Drupal.t('Show') : Drupal.t('Hide')) - .after(' ') - ) - ) - .append(summary) - .after( - $('
') - .append(fieldset.children(':not(legend):not(.action)')) - ); + // Turn the legend into a clickable link, but retain span.fieldset-legend + // for CSS positioning. + var $legend = $('> legend .fieldset-legend', this); + + $('') + .append($fieldset.hasClass('collapsed') ? Drupal.t('Show') : Drupal.t('Hide')) + .prependTo($legend) + .after(' '); + + // .wrapInner() does not retain bound events. + var $link = $('') + .prepend($legend.contents()) + .appendTo($legend) + .click(function () { + var fieldset = $fieldset.get(0); + // Don't animate multiple times. + if (!fieldset.animating) { + fieldset.animating = true; + Drupal.toggleFieldset(fieldset); + } + return false; + }); + + $legend.append(summary); }); } }; -- cgit v1.2.3