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.96.0 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.95.3 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.95.2 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.95.1 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.95.0 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
adminlte_rails-0.1.0 vendor/assets/javascripts/adminlte/plugins/select2/src/js/select2/selection/placeholder.js
card-1.94.1 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.94.0 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.93.13 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.93.12 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.93.11 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.93.10 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.93.9 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.93.8 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.93.7 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
jinda_lte-0.0.1 lib/generators/jinda_lte/templates/app/assets/jinda_assets/bower_components/select2/src/js/select2/selection/placeholder.js
card-1.93.6 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.93.5 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.93.4 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js
card-1.93.3 mod/bootstrap/vendor/select2/src/js/select2/selection/placeholder.js