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
card-1.93.2 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.93.1 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.93.0 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
trestle-0.8.0 vendor/assets/bower_components/trestle/select2/src/js/select2/selection/placeholder.js
locomotivecms-3.2.0.rc1 vendor/assets/components/locomotive_sources/select2/src/js/select2/selection/placeholder.js
locomotivecms-3.1.1 vendor/assets/components/locomotive_sources/select2/src/js/select2/selection/placeholder.js
locomotivecms-3.1.0 vendor/assets/components/locomotive_sources/select2/src/js/select2/selection/placeholder.js
locomotivecms-3.1.0.rc3 vendor/assets/components/locomotive_sources/select2/src/js/select2/selection/placeholder.js
locomotivecms-3.1.0.rc2 vendor/assets/components/locomotive_sources/select2/src/js/select2/selection/placeholder.js
locomotivecms-3.1.0.rc1 vendor/assets/components/locomotive_sources/select2/src/js/select2/selection/placeholder.js
locomotivecms-3.0.1 vendor/assets/components/locomotive_sources/select2/src/js/select2/selection/placeholder.js
locomotivecms-3.0.0 vendor/assets/components/locomotive_sources/select2/src/js/select2/selection/placeholder.js
locomotivecms-3.0.0.rc7 vendor/assets/components/locomotive_sources/select2/src/js/select2/selection/placeholder.js