Sha256: 5121d34e556f4d8bb3458bdc2850c5234d016573449440c6e0ac8112f05aa9af

Contents?: true

Size: 1.26 KB

Versions: 73

Compression:

Stored size: 1.26 KB

Contents

define([
  '../utils'
], function (Utils) {
  function Placeholder (decorated, $element, options) {
    this.placeholder = this.normalizePlaceholder(options.get('placeholder'));

    decorated.call(this, $element, options);
  }

  Placeholder.prototype.normalizePlaceholder = function (_, placeholder) {
    if (typeof placeholder === 'string') {
      placeholder = {
        id: '',
        text: placeholder
      };
    }

    return placeholder;
  };

  Placeholder.prototype.createPlaceholder = function (decorated, placeholder) {
    var $placeholder = this.selectionContainer();

    $placeholder.html(this.display(placeholder));
    $placeholder.addClass('select2-selection__placeholder')
                .removeClass('select2-selection__choice');

    return $placeholder;
  };

  Placeholder.prototype.update = function (decorated, data) {
    var singlePlaceholder = (
      data.length == 1 && data[0].id != this.placeholder.id
    );
    var multipleSelections = data.length > 1;

    if (multipleSelections || singlePlaceholder) {
      return decorated.call(this, data);
    }

    this.clear();

    var $placeholder = this.createPlaceholder(this.placeholder);

    this.$selection.find('.select2-selection__rendered').append($placeholder);
  };

  return Placeholder;
});

Version data entries

73 entries across 73 versions & 7 rubygems

Version Path
radius-rails-3.1.4 app/assets/components/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.14.2 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.14.1 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.14.0 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.13.4 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.13.3 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.13.2 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.13.1 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.13.0 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.11.7 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.12.0 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.11.6 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.11.5 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.11.4 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.11.3 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.11.2 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.11.1 vendor/select2/src/js/select2/selection/placeholder.js
card-mod-bootstrap-0.11.0 vendor/select2/src/js/select2/selection/placeholder.js
card-1.100.0 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.99.6 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js