: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// Register any internal event handlers
this._registerDataEvents();
this._registerSelectionEvents();
this._registerDropdownEvents();
this._registerResultsEvents();
this.dataAdapter.current(function (initialData) {
self.trigger('selection:update', {
// Hide the original select
$element.addClass('pumselect2-hidden-accessible');
$element.attr('aria-hidden', 'true');
// Synchronize any monitored attributes
$element.data('pumselect2', this);
Utils.Extend(Select2, Utils.Observable);
Select2.prototype._generateId = function ($element) {
if ($element.attr('id') != null) {
id = $element.attr('id');
} else if ($element.attr('name') != null) {
id = $element.attr('name') + '-' + Utils.generateChars(2);
id = Utils.generateChars(4);
id = id.replace(/(:|\.|\[|\]|,)/g, '');
Select2.prototype._placeContainer = function ($container) {
$container.insertAfter(this.$element);
var width = this._resolveWidth(this.$element, this.options.get('width'));
$container.css('width', width);
Select2.prototype._resolveWidth = function ($element, method) {
var WIDTH = /^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i;
if (method == 'resolve') {
var styleWidth = this._resolveWidth($element, 'style');
if (styleWidth != null) {
return this._resolveWidth($element, 'element');
if (method == 'element') {
var elementWidth = $element.outerWidth(false);
return elementWidth + 'px';
var style = $element.attr('style');
if (typeof(style) !== 'string') {
var attrs = style.split(';');
for (var i = 0, l = attrs.length; i < l; i = i + 1) {
var attr = attrs[i].replace(/\s/g, '');
var matches = attr.match(WIDTH);
if (matches !== null && matches.length >= 1) {
Select2.prototype._bindAdapters = function () {
this.dataAdapter.bind(this, this.$container);
this.selection.bind(this, this.$container);
this.dropdown.bind(this, this.$container);
this.results.bind(this, this.$container);
Select2.prototype._registerDomEvents = function () {
this.$element.on('change.pumselect2', function () {
self.dataAdapter.current(function (data) {
self.trigger('selection:update', {
this._sync = Utils.bind(this._syncAttributes, this);
if (this.$element[0].attachEvent) {
this.$element[0].attachEvent('onpropertychange', this._sync);
var observer = window.MutationObserver ||
window.WebKitMutationObserver ||
window.MozMutationObserver
this._observer = new observer(function (mutations) {
$.each(mutations, self._sync);
this._observer.observe(this.$element[0], {
} else if (this.$element[0].addEventListener) {
this.$element[0].addEventListener('DOMAttrModified', self._sync, false);
Select2.prototype._registerDataEvents = function () {
this.dataAdapter.on('*', function (name, params) {
self.trigger(name, params);
Select2.prototype._registerSelectionEvents = function () {
var nonRelayEvents = ['toggle', 'focus'];
this.selection.on('toggle', function () {
this.selection.on('focus', function (params) {
this.selection.on('*', function (name, params) {
if ($.inArray(name, nonRelayEvents) !== -1) {
self.trigger(name, params);
Select2.prototype._registerDropdownEvents = function () {
this.dropdown.on('*', function (name, params) {
self.trigger(name, params);
Select2.prototype._registerResultsEvents = function () {
this.results.on('*', function (name, params) {
self.trigger(name, params);
Select2.prototype._registerEvents = function () {
this.on('open', function () {
self.$container.addClass('pumselect2-container--open');
this.on('close', function () {
self.$container.removeClass('pumselect2-container--open');
this.on('enable', function () {
self.$container.removeClass('pumselect2-container--disabled');
this.on('disable', function () {
self.$container.addClass('pumselect2-container--disabled');
this.on('blur', function () {
self.$container.removeClass('pumselect2-container--focus');
this.on('query', function (params) {
self.trigger('open', {});
this.dataAdapter.query(params, function (data) {
self.trigger('results:all', {
this.on('query:append', function (params) {
this.dataAdapter.query(params, function (data) {
self.trigger('results:append', {
this.on('keypress', function (evt) {
if (key === KEYS.ESC || key === KEYS.TAB ||
(key === KEYS.UP && evt.altKey)) {
} else if (key === KEYS.ENTER) {
self.trigger('results:select', {});
} else if ((key === KEYS.SPACE && evt.ctrlKey)) {
self.trigger('results:toggle', {});
} else if (key === KEYS.UP) {
self.trigger('results:previous', {});
} else if (key === KEYS.DOWN) {
self.trigger('results:next', {});
if (key === KEYS.ENTER || key === KEYS.SPACE ||
(key === KEYS.DOWN && evt.altKey)) {
Select2.prototype._syncAttributes = function () {
this.options.set('disabled', this.$element.prop('disabled'));
if (this.options.get('disabled')) {
this.trigger('disable', {});
this.trigger('enable', {});
* Override the trigger method to automatically trigger pre-events when
* there are events that can be prevented.
Select2.prototype.trigger = function (name, args) {
var actualTrigger = Select2.__super__.trigger;
'unselect': 'unselecting'
if (args === undefined) {
if (name in preTriggerMap) {
var preTriggerName = preTriggerMap[name];
actualTrigger.call(this, preTriggerName, preTriggerArgs);
if (preTriggerArgs.prevented) {
actualTrigger.call(this, name, args);
Select2.prototype.toggleDropdown = function () {
if (this.options.get('disabled')) {
Select2.prototype.open = function () {
this.trigger('query', {});
Select2.prototype.close = function () {
this.trigger('close', {});
Select2.prototype.isOpen = function () {
return this.$container.hasClass('pumselect2-container--open');
Select2.prototype.hasFocus = function () {
return this.$container.hasClass('pumselect2-container--focus');
Select2.prototype.focus = function (data) {
// No need to re-trigger focus events if we are already focused
this.$container.addClass('pumselect2-container--focus');
this.trigger('focus', {});
Select2.prototype.enable = function (args) {
if (this.options.get('debug') && window.console && console.warn) {
'Select2: The `pumselect2("enable")` method has been deprecated and will' +
' be removed in later Select2 versions. Use $element.prop("disabled")' +
if (args == null || args.length === 0) {
this.$element.prop('disabled', disabled);
Select2.prototype.data = function () {
if (this.options.get('debug') &&
arguments.length > 0 && window.console && console.warn) {
'Select2: Data can no longer be set using `pumselect2("data")`. You ' +
'should consider setting the value instead using `$element.val()`.'
this.dataAdapter.current(function (currentData) {
Select2.prototype.val = function (args) {
if (this.options.get('debug') && window.console && console.warn) {
'Select2: The `pumselect2("val")` method has been deprecated and will be' +
' removed in later Select2 versions. Use $element.val() instead.'
if (args == null || args.length === 0) {
return this.$element.val();
newVal = $.map(newVal, function (obj) {
this.$element.val(newVal).trigger('change');
Select2.prototype.destroy = function () {
this.$container.remove();
if (this.$element[0].detachEvent) {
this.$element[0].detachEvent('onpropertychange', this._sync);
if (this._observer != null) {
this._observer.disconnect();
} else if (this.$element[0].removeEventListener) {
.removeEventListener('DOMAttrModified', this._sync, false);
this.$element.off('.pumselect2');
this.$element.attr('tabindex', this.$element.data('old-tabindex'));
this.$element.removeClass('pumselect2-hidden-accessible');
this.$element.attr('aria-hidden', 'false');
this.$element.removeData('pumselect2');
this.dataAdapter.destroy();
this.selection.destroy();
Select2.prototype.render = function () {
'<span class="pumselect2 pumselect2-container">' +
'<span class="selection"></span>' +
'<span class="dropdown-wrapper" aria-hidden="true"></span>' +
$container.attr('dir', this.options.get('dir'));
this.$container = $container;
this.$container.addClass('pumselect2-container--' + this.options.get('theme'));
$container.data('element', this.$element);
S2.define('pumselect2/compat/utils',[
function syncCssClasses ($dest, $src, adapter) {
var classes, replacements = [], adapted;
classes = $.trim($dest.attr('class'));
classes = '' + classes; // for IE which returns object
$(classes.split(/\s+/)).each(function () {
// Save all Select2 classes
if (this.indexOf('pumselect2-') === 0) {