PageSourceSearch

https://www.tmitrail.org.tw/sites/all/modules/field_group/field_group.js?tm9kfd

js tmitrail.org.tw collected 2026-10-02 11:52:09 UTC 8,247 bytes, 240 lines download raw bytes

1
2(function($) {
3
4/**
5 * Drupal FieldGroup object.
6 */
7Drupal.FieldGroup = Drupal.FieldGroup || {};
8Drupal.FieldGroup.Effects = Drupal.FieldGroup.Effects || {};
9Drupal.FieldGroup.groupWithfocus = null;
10
11Drupal.FieldGroup.setGroupWithfocus = function(element) {
12  element.css({display: 'block'});
13  Drupal.FieldGroup.groupWithfocus = element;
14}
15
16/**
17 * Implements Drupal.FieldGroup.processHook().
18 */
19Drupal.FieldGroup.Effects.processFieldset = {
20  execute: function (context, settings, type) {
21    if (type == 'form') {
22      // Add required fields mark to any fieldsets containing required fields
23      $('fieldset.fieldset', context).once('fieldgroup-effects', function(i) {
24        if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
25          $('legend span.fieldset-legend', $(this)).eq(0).append(' ').append($('.form-required').eq(0).clone());
26        }
27        if ($('.error', $(this)).length) {
28          $('legend span.fieldset-legend', $(this)).eq(0).addClass('error');
29          Drupal.FieldGroup.setGroupWithfocus($(this));
30        }
31      });
32    }
33  }
34}
35
36/**
37 * Implements Drupal.FieldGroup.processHook().
38 */
39Drupal.FieldGroup.Effects.processAccordion = {
40  execute: function (context, settings, type) {
41    $('div.field-group-accordion-wrapper', context).once('fieldgroup-effects', function () {
42      var wrapper = $(this);
43
44      // Get the index to set active.
45      var active_index = false;
46      wrapper.find('.accordion-item').each(function(i) {
47        if ($(this).hasClass('field-group-accordion-active')) {
48          active_index = i;
49        }
50      });
51
52      wrapper.accordion({
53        heightStyle: "content",
54        active: active_index,
55        collapsible: true,
56        changestart: function(event, ui) {
57          if ($(this).hasClass('effect-none')) {
58            ui.options.animated = false;
59          }
60          else {
61            ui.options.animated = 'slide';
62          }
63        }
64      });
65
66      if (type == 'form') {
67
68        var $firstErrorItem = false;
69
70        // Add required fields mark to any element containing required fields
71        wrapper.find('div.field-group-accordion-item').each(function(i) {
72
73          if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
74            $('h3.ui-accordion-header a').eq(i).append(' ').append($('.form-required').eq(0).clone());
75          }
76          if ($('.error', $(this)).length) {
77            // Save first error item, for focussing it.
78            if (!$firstErrorItem) {
79              $firstErrorItem = $(this).parent().accordion("activate" , i);
80            }
81            $('h3.ui-accordion-header').eq(i).addClass('error');
82          }
83        });
84
85        // Save first error item, for focussing it.
86        if (!$firstErrorItem) {
87          $('.ui-accordion-content-active', $firstErrorItem).css({height: 'auto', width: 'auto', display: 'block'});
88        }
89
90      }
91    });
92  }
93}
94
95/**
96 * Implements Drupal.FieldGroup.processHook().
97 */
98Drupal.FieldGroup.Effects.processHtabs = {
99  execute: function (context, settings, type) {
100    if (type == 'form') {
101      // Add required fields mark to any element containing required fields
102      $('fieldset.horizontal-tabs-pane', context).once('fieldgroup-effects', function(i) {
103        if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
104          $(this).data('horizontalTab').link.find('strong:first').after($('.form-required').eq(0).clone()).after(' ');
105        }
106        if ($('.error', $(this)).length) {
107          $(this).data('horizontalTab').link.parent().addClass('error');
108          Drupal.FieldGroup.setGroupWithfocus($(this));
109          $(this).data('horizontalTab').focus();
110        }
111      });
112    }
113  }
114}
115
116/**
117 * Implements Drupal.FieldGroup.processHook().
118 */
119Drupal.FieldGroup.Effects.processTabs = {
120  execute: function (context, settings, type) {
121    if (type == 'form') {
122
123      var errorFocussed = false;
124
125      // Add required fields mark to any fieldsets containing required fields
126      $('fieldset.vertical-tabs-pane', context).once('fieldgroup-effects', function(i) {
127        if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
128          $(this).data('verticalTab').link.find('strong:first').after($('.form-required').eq(0).clone()).after(' ');
129        }
130        if ($('.error', $(this)).length) {
131          $(this).data('verticalTab').link.parent().addClass('error');
132          // Focus the first tab with error.
133          if (!errorFocussed) {
134            Drupal.FieldGroup.setGroupWithfocus($(this));
135            $(this).data('verticalTab').focus();
136            errorFocussed = true;
137          }
138        }
139      });
140    }
141  }
142}
143
144/**
145 * Implements Drupal.FieldGroup.processHook().
146 *
147 * TODO clean this up meaning check if this is really
148 *      necessary.
149 */
150Drupal.FieldGroup.Effects.processDiv = {
151  execute: function (context, settings, type) {
152
153    $('div.collapsible', context).once('fieldgroup-effects', function() {
154      var $wrapper = $(this);
155
156      // Turn the legend into a clickable link, but retain span.field-group-format-toggler
157      // for CSS positioning.
158
159      var $toggler = $('span.field-group-format-toggler:first', $wrapper);
160      var $link = $('<a class="field-group-format-title" href="#"></a>');
161      $link.prepend($toggler.contents());
162
163      // Add required field markers if needed
164      if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
165        $link.append(' ').append($('.form-required').eq(0).clone());
166      }
167
168      $link.appendTo($toggler);
169
170      // .wrapInner() does not retain bound events.
171      $link.click(function () {
172        var wrapper = $wrapper.get(0);
173        // Don't animate multiple times.
174        if (!wrapper.animating) {
175          wrapper.animating = true;
176          var speed = $wrapper.hasClass('speed-fast') ? 300 : 1000;
177          if ($wrapper.hasClass('effect-none') && $wrapper.hasClass('speed-none')) {
178            $('> .field-group-format-wrapper', wrapper).toggle();
179          }
180          else if ($wrapper.hasClass('effect-blind')) {
181            $('> .field-group-format-wrapper', wrapper).toggle('blind', {}, speed);
182          }
183          else {
184            $('> .field-group-format-wrapper', wrapper).toggle(speed);
185          }
186          wrapper.animating = false;
187        }
188        $wrapper.toggleClass('collapsed');
189        return false;
190      });
191
192    });
193  }
194};
195
196/**
197 * Behaviors.
198 */
199Drupal.behaviors.fieldGroup = {
200  attach: function (context, settings) {
201    settings.field_group = settings.field_group || Drupal.settings.field_group;
202    if (settings.field_group == undefined) {
203      return;
204    }
205
206    // Execute all of them.
207    $.each(Drupal.FieldGroup.Effects, function (func) {
208      // We check for a wrapper function in Drupal.field_group as
209      // alternative for dynamic string function calls.
210      var type = func.toLowerCase().replace("process", "");
211      if (settings.field_group[type] != undefined && $.isFunction(this.execute)) {
212        this.execute(context, settings, settings.field_group[type]);
213      }
214    });
215
216    // Fixes css for fieldgroups under vertical tabs.
217    $('.fieldset-wrapper .fieldset > legend').css({display: 'block'});
218    $('.vertical-tabs fieldset.fieldset').addClass('default-fallback');
219
220    // Add a new ID to each fieldset.
221    $('.group-wrapper .horizontal-tabs-panes > fieldset', context).once('group-wrapper-panes-processed', function() {
222      // Tats bad, but we have to keep the actual id to prevent layouts to break.
223      var fieldgroupID = 'field_group-' + $(this).attr('id');
224      $(this).attr('id', fieldgroupID);
225    });
226    // Set the hash in url to remember last userselection.
227    $('.group-wrapper ul li').once('group-wrapper-ul-processed', function() {
228      var fieldGroupNavigationListIndex = $(this).index();
229      $(this).children('a').click(function() {
230        var fieldset = $('.group-wrapper fieldset').get(fieldGroupNavigationListIndex);
231        // Grab the first id, holding the wanted hashurl.
232        var hashUrl = $(fieldset).attr('id').replace(/^field_group-/, '').split(' ')[0];
233        window.location.hash = hashUrl;
234      });
235    });
236
237  }
238};
239
240})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.