/[drupal]/drupal/misc/collapse.js
ViewVC logotype

Contents of /drupal/misc/collapse.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.26 - (show annotations) (download) (as text)
Fri Oct 16 19:20:34 2009 UTC (6 weeks ago) by dries
Branch: MAIN
Changes since 1.25: +5 -2 lines
File MIME type: text/javascript
- Patch #557272 by kkaefer, Rob Loach, quicksketch: added FAPI JavaScript States system.
1 // $Id: collapse.js,v 1.25 2009/09/11 02:01:26 webchick Exp $
2 (function ($) {
3
4 /**
5 * Toggle the visibility of a fieldset using smooth animations.
6 */
7 Drupal.toggleFieldset = function (fieldset) {
8 if ($(fieldset).is('.collapsed')) {
9 // Action div containers are processed separately because of a IE bug
10 // that alters the default submit button behavior.
11 var content = $('> div:not(.action)', fieldset);
12 $(fieldset)
13 .removeClass('collapsed')
14 .trigger({ type: 'collapsed', value: false });
15 content.hide();
16 content.slideDown({
17 duration: 'fast',
18 easing: 'linear',
19 complete: function () {
20 Drupal.collapseScrollIntoView(this.parentNode);
21 this.parentNode.animating = false;
22 $('div.action', fieldset).show();
23 },
24 step: function () {
25 // Scroll the fieldset into view.
26 Drupal.collapseScrollIntoView(this.parentNode);
27 }
28 });
29 }
30 else {
31 $('div.action', fieldset).hide();
32 $(fieldset).trigger({ type: 'collapsed', value: true });
33 var content = $('> div:not(.action)', fieldset).slideUp('fast', function () {
34 $(this.parentNode).addClass('collapsed');
35 this.parentNode.animating = false;
36 });
37 }
38 };
39
40 /**
41 * Scroll a given fieldset into view as much as possible.
42 */
43 Drupal.collapseScrollIntoView = function (node) {
44 var h = self.innerHeight || document.documentElement.clientHeight || $('body')[0].clientHeight || 0;
45 var offset = self.pageYOffset || document.documentElement.scrollTop || $('body')[0].scrollTop || 0;
46 var posY = $(node).offset().top;
47 var fudge = 55;
48 if (posY + node.offsetHeight + fudge > h + offset) {
49 if (node.offsetHeight > h) {
50 window.scrollTo(0, posY);
51 }
52 else {
53 window.scrollTo(0, posY + node.offsetHeight - h + fudge);
54 }
55 }
56 };
57
58 Drupal.behaviors.collapse = {
59 attach: function (context, settings) {
60 $('fieldset.collapsible > legend', context).once('collapse', function () {
61 var fieldset = $(this.parentNode);
62 // Expand if there are errors inside.
63 if ($('input.error, textarea.error, select.error', fieldset).size() > 0) {
64 fieldset.removeClass('collapsed');
65 }
66
67 var summary = $('<span class="summary"></span>');
68 fieldset.
69 bind('summaryUpdated', function () {
70 var text = $.trim(fieldset.getSummary());
71 summary.html(text ? ' (' + text + ')' : '');
72 })
73 .trigger('summaryUpdated');
74
75 // Turn the legend into a clickable link and wrap the contents of the
76 // fieldset in a div for easier animation.
77 var text = this.innerHTML;
78 $(this).empty().append($('<a href="#">' + text + '</a>').click(function () {
79 var fieldset = $(this).parents('fieldset:first')[0];
80 // Don't animate multiple times.
81 if (!fieldset.animating) {
82 fieldset.animating = true;
83 Drupal.toggleFieldset(fieldset);
84 }
85 return false;
86 }))
87 .append(summary)
88 .after(
89 $('<div class="fieldset-wrapper"></div>')
90 .append(fieldset.children(':not(legend):not(.action)'))
91 );
92 });
93 }
94 };
95
96 })(jQuery);

  ViewVC Help
Powered by ViewVC 1.1.2