Sha256: eabd410e243f5f1e95fe646548ed296666aed62a8120bec71efc7fa03baf6ce9

Contents?: true

Size: 1.68 KB

Versions: 46

Compression:

Stored size: 1.68 KB

Contents

/**
 * Text based input view that can display a placeholder.
 *
 * @param {string|function} [options.placeholder]
 *   Display a placeholder string if the input is blank. Either a
 *   string or a function taking the model as a first parameter and
 *   returning a string.
 *
 * @param {string} [options.placeholderBinding]
 *   Name of an attribute. Recompute the placeholder function whenever
 *   this attribute changes.
 *
 * @param {boolean} [options.hidePlaceholderIfDisabled]
 *   Do not display the placeholder if the input is disabled.
 *
 * @param {Backbone.Model} [options.placeholderModel]
 *   Obtain placeholder by looking up the configured `propertyName`
 *   inside a given model.
 *
 * @mixin
 * @memberof module:pageflow/ui
 */
pageflow.inputWithPlaceholderText = {
  onRender: function() {
    this.updatePlaceholder();

    if (this.options.placeholderBinding) {
      this.listenTo(this.model,
                    'change:' + this.options.placeholderBinding,
                    this.updatePlaceholder);
    }
  },

  updatePlaceholder: function() {
    this.ui.input.attr('placeholder', this.placeholderText());
  },

  placeholderText: function() {
    if (!this.options.disabled || !this.options.hidePlaceholderIfDisabled) {
      if (this.options.placeholder) {
        if (typeof this.options.placeholder == 'function') {
          return this.options.placeholder(this.model);
        }
        else {
          return this.options.placeholder;
        }
      }
      else {
        return this.placeholderModelValue();
      }
    }
  },

  placeholderModelValue: function() {
    return this.options.placeholderModel &&
      this.options.placeholderModel.get(this.options.propertyName);
  }
};

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
pageflow-14.5.2 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-15.0.2 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-15.0.1 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-15.0.0 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-14.5.1 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-14.5.0 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-15.0.0.rc2 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-15.0.0.rc1 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-15.0.0.beta4 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-15.0.0.beta3 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-14.4.0 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-15.0.0.beta2 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-15.0.0.beta1 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-14.3.0 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-14.2.1 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-14.2.0 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-14.1.1 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-14.1.0 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-14.0.0 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js
pageflow-14.0.0.rc2 app/assets/javascripts/pageflow/ui/views/mixins/input_with_placeholder_text.js