Sha256: 842af6ad3d58b6111fbd00d60aabe6d8ed181f3acab7a60670e6f3dc9d7db163

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

/* global Fae */

/**
 * Fae form
 * @namespace form
 * @memberof Fae
 */
Fae.form = {
  ready: function() {
    this.dates.init();
    this.text.init();
    this.select.init();
    this.checkbox.init();
    this.validator.init();
    this.cancel.init();
    this.ajax.init();
    this.filtering.init();
    this.slugger.init();

    // input type=file customization
    // This doesn't work in IE. It's not worth figuring out why by this point. IE9 gets plain file uploader.
    if (!FCH.IE9) {
      $('.input.file').fileinputer();
    }

    // Mutate DOM to support two column labels for all standard inputs
    this.makeTwoColumnLabels();

    // make all the hint areas
    $('.hint').hinter();
  },

  makeTwoColumnLabels: function() {
    $('.input label').each(function() {
      var $element = $(this);

      // Bail if we cannot find any helper_text
      if (!$element.find('.helper_text').length) { return; }

      // If present, get all DOM nodes w/ contents(), but ignore the .helper_text
      var label_inner = $element.contents().filter(function() {
        return !$(this).hasClass('helper_text');
      });
      var helper_text = $element.find('.helper_text');

      // Replace existing label w/ newly wrapped elements, sans .helper_text
      label_inner = $('<div class="label_inner" />').html(label_inner);
      $element.html(label_inner);

      // But then add .helper_text as a sibling
      $element.append(helper_text);

      // Ensure that we mark this input as having two column label support
      $element.addClass('label--two_col');
    });
  }
};

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fae-rails-1.5.1 app/assets/javascripts/fae/form/_form.js
fae-rails-1.5.0 app/assets/javascripts/fae/form/_form.js
fae-rails-1.4.1 app/assets/javascripts/fae/form/_form.js