Projet

Général

Profil

Révision 01f36513

Ajouté par Assos Assos il y a environ 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/webform/js/webform.js
76 76
          // Make sure that the default year fits in the available options.
77 77
          year = (year < startYear || year > endYear) ? startYear : year;
78 78

  
79
          // jQuery UI Datepicker will read the input field and base its date off
80
          // of that, even though in our case the input field is a button.
79
          // jQuery UI Datepicker will read the input field and base its date
80
          // off of that, even though in our case the input field is a button.
81 81
          $(input).val(year + '-' + month + '-' + day);
82 82
        }
83 83
      });
......
129 129
    var resultStack;
130 130

  
131 131
    /**
132
     * Initializes an execution stack for a conditional group's rules and
133
     * sub-conditional rules.
132
     * Initializes an execution stack for a conditional group's rules.
133
     *
134
     * Also initializes sub-conditional rules.
134 135
     */
135 136
    function executionStackInitialize(andor) {
136 137
      stackPointer = -1;
......
172 173
                : filteredResults.length === $conditionalResults.length;
173 174
    }
174 175

  
175
    // Track what has be set/shown for each target component.
176
    var targetLocked = [];
177

  
176
    // Track what has been set/hidden for each target component's elements.
177
    // Hidden elements must be disabled because if they are required and don't
178
    // have a value, they will prevent submission due to html5 validation.
179
    // Each execution of the conditionals adds a temporary class
180
    // webform-disabled-flag so that elements hidden or set can be disabled and
181
    // also be prevented from being re-enabled by another conditional (such as a
182
    // parent fieldset). After processing conditionals, this temporary class
183
    // must be removed in preparation for the next execution of the
184
    // conditionals.
178 185
    $.each(settings.ruleGroups, function (rgid_key, rule_group) {
179 186
      var ruleGroup = settings.ruleGroups[rgid_key];
180 187

  
......
205 212
        var actionResult = action['invert'] ? !conditionalResult : conditionalResult;
206 213
        switch (action['action']) {
207 214
          case 'show':
208
            if (actionResult != Drupal.webform.isVisible($target)) {
209
              var $targetElements = actionResult
210
                                      ? $target.find('.webform-conditional-disabled').removeClass('webform-conditional-disabled')
211
                                      : $target.find(':input').addClass('webform-conditional-disabled');
212
              $targetElements.webformProp('disabled', !actionResult);
213
              $target.toggleClass('webform-conditional-hidden', !actionResult);
214
              // Anything hidden needs to be disabled so that child elements of
215
              // fieldsets do not block submission by being required.
216
              $target.webformProp('disabled', !actionResult);
217
              if (actionResult) {
218
                $target.show();
219
              }
220
              else {
221
                $target.hide();
222
                // Record that the target was hidden.
223
                targetLocked[action['target']] = 'hide';
224
              }
225
              if ($target.is('tr')) {
226
                Drupal.webform.restripeTable($target.closest('table').first());
227
              }
215
            var changed = actionResult != Drupal.webform.isVisible($target);
216
            if (actionResult) {
217
              $target.find('.webform-conditional-disabled:not(.webform-disabled-flag)')
218
                .removeClass('webform-conditional-disabled')
219
                .webformProp('disabled', false);
220
              $target
221
                .removeClass('webform-conditional-hidden')
222
                .show();
223
              $form.find('.chosen-disabled').prev().trigger('chosen:updated.chosen');
224
            }
225
            else {
226
              $target
227
                .hide()
228
                .addClass('webform-conditional-hidden')
229
                .find(':input')
230
                  .addClass('webform-conditional-disabled webform-disabled-flag')
231
                  .webformProp('disabled', true);
232
            }
233
            if (changed && $target.is('tr')) {
234
              Drupal.webform.restripeTable($target.closest('table').first());
228 235
            }
229 236
            break;
230 237

  
......
232 239
            var $requiredSpan = $target.find('.form-required, .form-optional').first();
233 240
            if (actionResult != $requiredSpan.hasClass('form-required')) {
234 241
              var $targetInputElements = $target.find("input:text,textarea,input[type='email'],select,input:radio,input:file");
235
              // Rather than hide the required tag, remove it so that other jQuery can respond via Drupal behaviors.
242
              // Rather than hide the required tag, remove it so that other
243
              // jQuery can respond via Drupal behaviors.
236 244
              Drupal.detachBehaviors($requiredSpan);
237 245
              $targetInputElements
238 246
                .webformProp('required', actionResult)
......
248 256
            break;
249 257

  
250 258
          case 'set':
251
            var isLocked = targetLocked[action['target']];
252 259
            var $texts = $target.find("input:text,textarea,input[type='email']");
253 260
            var $selects = $target.find('select,select option,input:radio,input:checkbox');
254 261
            var $markups = $target.filter('.webform-component-markup');
255 262
            if (actionResult) {
256 263
              var multiple = $.map(action['argument'].split(','), $.trim);
257
              $selects.webformVal(multiple);
258
              $texts.val([action['argument']]);
259
              // A special case is made for markup. It is sanitized with filter_xss_admin on the server.
260
              // otherwise text() should be used to avoid an XSS vulnerability. text() however would
261
              // preclude the use of tags like <strong> or <a>.
264
              $selects
265
                .webformVal(multiple)
266
                .webformProp('disabled', true)
267
                  .addClass('webform-disabled-flag');
268
              $texts
269
                .val([action['argument']])
270
                .webformProp('readonly', true)
271
                .addClass('webform-disabled-flag');
272
              // A special case is made for markup. It is sanitized with
273
              // filter_xss_admin on the server. otherwise text() should be used
274
              // to avoid an XSS vulnerability. text() however would preclude
275
              // the use of tags like <strong> or <a>.
262 276
              $markups.html(action['argument']);
263 277
            }
264 278
            else {
279
              $selects.not('.webform-disabled-flag')
280
                .webformProp('disabled', false);
281
              $texts.not('.webform-disabled-flag')
282
                .webformProp('readonly', false);
265 283
              // Markup not set? Then restore original markup as provided in
266 284
              // the attribute data-webform-markup.
267 285
              $markups.each(function () {
......
272 290
                }
273 291
              });
274 292
            }
275
            if (!isLocked) {
276
              // If not previously hidden or set, disable the element readonly or readonly-like behavior.
277
              $selects.webformProp('disabled', actionResult);
278
              $texts.webformProp('readonly', actionResult);
279
              targetLocked[action['target']] = actionResult ? 'set' : false;
280
            }
281 293
            break;
282 294
        }
283
      }); // End look on each action for one conditional
295
      }); // End look on each action for one conditional.
284 296
    }); // End loop on each conditional.
297

  
298
    $form.find('.webform-disabled-flag').removeClass('webform-disabled-flag');
285 299
  };
286 300

  
287 301
  /**
288
   * Event handler to prevent propagation of events, typically click for disabling
289
   * radio and checkboxes.
302
   * Event handler to prevent propagation of events.
303
   *
304
   * Typically click for disabling radio and checkboxes.
290 305
   */
291 306
  Drupal.webform.stopEvent = function () {
292 307
    return false;
......
524 539
  };
525 540

  
526 541
  /**
527
   * Utility to return current visibility. Uses actual visibility, except for
528
   * hidden components which use the applied disabled class.
542
   * Utility to return current visibility.
543
   *
544
   * Uses actual visibility, except for hidden components which use the applied
545
   * disabled class.
529 546
   */
530 547
  Drupal.webform.isVisible = function ($element) {
531 548
    return $element.hasClass('webform-component-hidden')
......
534 551
  };
535 552

  
536 553
  /**
537
   * Utility function to get a string value from a select/radios/text/etc. field.
554
   * Function to get a string value from a select/radios/text/etc. field.
538 555
   */
539 556
  Drupal.webform.stringValue = function (element, existingValue) {
540 557
    var value = [];
......
557 574
            }
558 575
          }
559 576
        }
560
        // Simple text fields. This check is done last so that the select list in
561
        // select-or-other fields comes before the "other" text field.
577
        // Simple text fields. This check is done last so that the select list
578
        // in select-or-other fields comes before the "other" text field.
562 579
        if (!value.length) {
563 580
          $element.find('input:not([type=checkbox],[type=radio]),textarea').each(function () {
564 581
            value.push(this.value);
......
666 683
  };
667 684

  
668 685
  /**
669
   * Make a multi-valued val() function for setting checkboxes, radios, and select
670
   * elements.
686
   * Make a multi-valued val() function.
687
   *
688
   * This is for setting checkboxes, radios, and select elements.
671 689
   */
672 690
  $.fn.webformVal = function (values) {
673 691
    this.each(function () {

Formats disponibles : Unified diff