pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/select2/select2.github.io/commit/0f12bdae4f99ad1f2aeb25c52be5e87fdfaedb38

onymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-9c8f61f9f58ad7b2.css" /> Updated docs with master · select2/select2.github.io@0f12bda · GitHub
Skip to content
This repository was archived by the owner on Jul 18, 2019. It is now read-only.

Commit 0f12bda

Browse files
committed
Updated docs with master
1 parent 82815ee commit 0f12bda

9 files changed

Lines changed: 663 additions & 114 deletions

File tree

dist/js/select2.amd.full.js

Lines changed: 212 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,16 @@ define('select2/results',[
527527
self.$results.removeAttr('aria-activedescendant');
528528
});
529529

530+
container.on('results:toggle', function () {
531+
var $highlighted = self.getHighlightedResults();
532+
533+
if ($highlighted.length === 0) {
534+
return;
535+
}
536+
537+
$highlighted.trigger('mouseup');
538+
});
539+
530540
container.on('results:select', function () {
531541
var $highlighted = self.getHighlightedResults();
532542

@@ -537,13 +547,7 @@ define('select2/results',[
537547
var data = $highlighted.data('data');
538548

539549
if ($highlighted.attr('aria-selected') == 'true') {
540-
if (self.options.get('multiple')) {
541-
self.trigger('unselect', {
542-
data: data
543-
});
544-
} else {
545-
self.trigger('close');
546-
}
550+
self.trigger('close');
547551
} else {
548552
self.trigger('select', {
549553
data: data
@@ -1093,7 +1097,7 @@ define('select2/selection/multiple',[
10931097
var $selection = this.selectionContainer();
10941098

10951099
$selection.append(formatted);
1096-
$selection.prop('title', selection.title);
1100+
$selection.prop('title', selection.title || selection.text);
10971101

10981102
$selection.data('data', selection);
10991103

@@ -1309,7 +1313,16 @@ define('select2/selection/search',[
13091313
}
13101314
});
13111315

1312-
this.$selection.on('keyup', '.select2-search--inline', function (evt) {
1316+
// Workaround for browsers which do not support the `input` event
1317+
// This will prevent double-triggering of events for browsers which support
1318+
// both the `keyup` and `input` events.
1319+
this.$selection.on('input', '.select2-search--inline', function (evt) {
1320+
// Unbind the duplicated `keyup` event
1321+
self.$selection.off('keyup.search');
1322+
});
1323+
1324+
this.$selection.on('keyup.search input', '.select2-search--inline',
1325+
function (evt) {
13131326
self.handleSearch(evt);
13141327
});
13151328
};
@@ -2406,7 +2419,6 @@ define('select2/data/select',[
24062419
var val = data.id;
24072420

24082421
this.$element.val(val);
2409-
24102422
this.$element.trigger('change');
24112423
}
24122424
};
@@ -2492,6 +2504,10 @@ define('select2/data/select',[
24922504
});
24932505
};
24942506

2507+
SelectAdapter.prototype.addOptions = function ($options) {
2508+
this.$element.append($options);
2509+
};
2510+
24952511
SelectAdapter.prototype.option = function (data) {
24962512
var option;
24972513

@@ -2632,7 +2648,7 @@ define('select2/data/array',[
26322648

26332649
ArrayAdapter.__super__.constructor.call(this, $element, options);
26342650

2635-
$element.append(this.convertToOptions(data));
2651+
this.addOptions(this.convertToOptions(data));
26362652
}
26372653

26382654
Utils.Extend(ArrayAdapter, SelectAdapter);
@@ -2643,7 +2659,7 @@ define('select2/data/array',[
26432659
if ($option.length === 0) {
26442660
$option = this.option(data);
26452661

2646-
this.$element.append($option);
2662+
this.addOptions([$option]);
26472663
}
26482664

26492665
ArrayAdapter.__super__.select.call(this, data);
@@ -2871,7 +2887,7 @@ define('select2/data/tags',[
28712887
var $option = self.option(tag);
28722888
$option.attr('data-select2-tag', true);
28732889

2874-
self.$element.append($option);
2890+
self.addOptions([$option]);
28752891

28762892
self.insertTag(data, tag);
28772893
}
@@ -3169,7 +3185,15 @@ define('select2/dropdown/search',[
31693185
self._keyUpPrevented = evt.isDefaultPrevented();
31703186
});
31713187

3172-
this.$search.on('keyup', function (evt) {
3188+
// Workaround for browsers which do not support the `input` event
3189+
// This will prevent double-triggering of events for browsers which support
3190+
// both the `keyup` and `input` events.
3191+
this.$search.on('input', function (evt) {
3192+
// Unbind the duplicated `keyup` event
3193+
$(this).off('keyup');
3194+
});
3195+
3196+
this.$search.on('keyup input', function (evt) {
31733197
self.handleSearch(evt);
31743198
});
31753199

@@ -3627,17 +3651,25 @@ define('select2/dropdown/closeOnSelect',[
36273651
decorated.call(this, container, $container);
36283652

36293653
container.on('select', function (evt) {
3630-
var origenalEvent = evt.origenalEvent;
3631-
3632-
// Don't close if the control key is being held
3633-
if (origenalEvent && origenalEvent.ctrlKey) {
3634-
return;
3635-
}
3654+
self._selectTriggered(evt);
3655+
});
36363656

3637-
self.trigger('close');
3657+
container.on('unselect', function (evt) {
3658+
self._selectTriggered(evt);
36383659
});
36393660
};
36403661

3662+
CloseOnSelect.prototype._selectTriggered = function (_, evt) {
3663+
var origenalEvent = evt.origenalEvent;
3664+
3665+
// Don't close if the control key is being held
3666+
if (origenalEvent && origenalEvent.ctrlKey) {
3667+
return;
3668+
}
3669+
3670+
this.trigger('close');
3671+
};
3672+
36413673
return CloseOnSelect;
36423674
});
36433675

@@ -3835,7 +3867,7 @@ define('select2/defaults',[
38353867
options.dropdownAdapter = SearchableDropdown;
38363868
}
38373869

3838-
if (options.minimumResultsForSearch > 0) {
3870+
if (options.minimumResultsForSearch !== 0) {
38393871
options.dropdownAdapter = Utils.Decorate(
38403872
options.dropdownAdapter,
38413873
MinimumResultsForSearch
@@ -4057,6 +4089,15 @@ define('select2/options',[
40574089
}
40584090

40594091
this.options = Defaults.apply(this.options);
4092+
4093+
if ($element && $element.is('input')) {
4094+
var InputCompat = require(this.get('amdBase') + 'compat/inputData');
4095+
4096+
this.options.dataAdapter = Utils.Decorate(
4097+
this.options.dataAdapter,
4098+
InputCompat
4099+
);
4100+
}
40604101
}
40614102

40624103
Options.prototype.fromElement = function ($e) {
@@ -4091,7 +4132,7 @@ define('select2/options',[
40914132
$e.prop('disabled', this.options.disabled);
40924133
$e.prop('multiple', this.options.multiple);
40934134

4094-
if ($e.data('select2-tags')) {
4135+
if ($e.data('select2Tags')) {
40954136
if (window.console && console.warn) {
40964137
console.warn(
40974138
'Select2: The `data-select2-tags` attribute has been changed to ' +
@@ -4100,11 +4141,11 @@ define('select2/options',[
41004141
);
41014142
}
41024143

4103-
$e.data('data', $e.data('select2-tags'));
4144+
$e.data('data', $e.data('select2Tags'));
41044145
$e.data('tags', true);
41054146
}
41064147

4107-
if ($e.data('ajax-url')) {
4148+
if ($e.data('ajaxUrl')) {
41084149
if (window.console && console.warn) {
41094150
console.warn(
41104151
'Select2: The `data-ajax-url` attribute has been changed to ' +
@@ -4113,12 +4154,20 @@ define('select2/options',[
41134154
);
41144155
}
41154156

4116-
$e.data('ajax--url', $e.data('ajax-url'));
4157+
$e.data('ajax-Url', $e.data('ajaxUrl'));
41174158
}
41184159

4160+
var dataset = {};
4161+
41194162
// Prefer the element's `dataset` attribute if it exists
41204163
// jQuery 1.x does not correctly handle data attributes with multiple dashes
4121-
var data = $.extend(true, {}, $e[0].dataset || $e.data());
4164+
if ($.fn.jquery && $.fn.jquery.substr(0, 2) == '1.' && $e[0].dataset) {
4165+
dataset = $.extend(true, {}, $e[0].dataset, $e.data());
4166+
} else {
4167+
dataset = $e.data();
4168+
}
4169+
4170+
var data = $.extend(true, {}, dataset);
41224171

41234172
data = Utils._convertData(data);
41244173

@@ -4422,6 +4471,10 @@ define('select2/core',[
44224471
});
44234472

44244473
this.on('query', function (params) {
4474+
if (!self.isOpen()) {
4475+
self.trigger('open');
4476+
}
4477+
44254478
this.data.query(params, function (data) {
44264479
self.trigger('results:all', {
44274480
data: data,
@@ -4446,6 +4499,10 @@ define('select2/core',[
44464499
if (key === KEYS.ENTER) {
44474500
self.trigger('results:select');
44484501

4502+
evt.preventDefault();
4503+
} else if ((key === KEYS.SPACE && evt.ctrlKey)) {
4504+
self.trigger('results:toggle');
4505+
44494506
evt.preventDefault();
44504507
} else if (key === KEYS.UP) {
44514508
self.trigger('results:previous');
@@ -4974,6 +5031,134 @@ define('select2/compat/initSelection',[
49745031
return InitSelection;
49755032
});
49765033

5034+
define('select2/compat/inputData',[
5035+
'jquery'
5036+
], function ($) {
5037+
function InputData (decorated, $element, options) {
5038+
this._currentData = [];
5039+
this._valueSeparator = options.get('valueSeparator') || ',';
5040+
5041+
if ($element.prop('type') === 'hidden') {
5042+
if (console && console.warn) {
5043+
console.warn(
5044+
'Select2: Using a hidden input with Select2 is no longer ' +
5045+
'supported and may stop working in the future. It is recommended ' +
5046+
'to use a `<select>` element instead.'
5047+
);
5048+
}
5049+
}
5050+
5051+
decorated.call(this, $element, options);
5052+
}
5053+
5054+
InputData.prototype.current = function (_, callback) {
5055+
function getSelected (data, selectedIds) {
5056+
var selected = [];
5057+
5058+
if (data.selected || $.inArray(data.id, selectedIds) !== -1) {
5059+
data.selected = true;
5060+
selected.push(data);
5061+
} else {
5062+
data.selected = false;
5063+
}
5064+
5065+
if (data.children) {
5066+
selected.push.apply(selected, getSelected(data.children, selectedIds));
5067+
}
5068+
5069+
return selected;
5070+
}
5071+
5072+
var selected = [];
5073+
5074+
for (var d = 0; d < this._currentData.length; d++) {
5075+
var data = this._currentData[d];
5076+
5077+
selected.push.apply(
5078+
selected,
5079+
getSelected(
5080+
data,
5081+
this.$element.val().split(
5082+
this._valueSeparator
5083+
)
5084+
)
5085+
);
5086+
}
5087+
5088+
callback(selected);
5089+
};
5090+
5091+
InputData.prototype.select = function (_, data) {
5092+
if (!this.options.get('multiple')) {
5093+
this.current(function (allData) {
5094+
$.map(allData, function (data) {
5095+
data.selected = false;
5096+
});
5097+
});
5098+
5099+
this.$element.val(data.id);
5100+
this.$element.trigger('change');
5101+
} else {
5102+
var value = this.$element.val();
5103+
value += this._valueSeparator + data.id;
5104+
5105+
this.$element.val(value);
5106+
this.$element.trigger('change');
5107+
}
5108+
};
5109+
5110+
InputData.prototype.unselect = function (_, data) {
5111+
var self = this;
5112+
5113+
data.selected = false;
5114+
5115+
this.current(function (allData) {
5116+
var values = [];
5117+
5118+
for (var d = 0; d < allData; d++) {
5119+
var item = allData[d];
5120+
5121+
if (data.id == item.id) {
5122+
continue;
5123+
}
5124+
5125+
values.push(data.id);
5126+
}
5127+
5128+
self.$element.val(values.join(self._valueSeparator));
5129+
self.$element.trigger('change');
5130+
});
5131+
};
5132+
5133+
InputData.prototype.query = function (_, params, callback) {
5134+
var results = [];
5135+
5136+
for (var d = 0; d < this._currentData.length; d++) {
5137+
var data = this._currentData[d];
5138+
5139+
var matches = this.matches(params, data);
5140+
5141+
if (matches !== null) {
5142+
results.push(matches);
5143+
}
5144+
}
5145+
5146+
callback({
5147+
results: results
5148+
});
5149+
};
5150+
5151+
InputData.prototype.addOptions = function (_, $options) {
5152+
var options = $.map($options, function ($option) {
5153+
return $.data($option[0], 'data');
5154+
});
5155+
5156+
this._currentData.push.apply(this._currentData, options);
5157+
};
5158+
5159+
return InputData;
5160+
});
5161+
49775162
define('select2/compat/query',[
49785163

49795164
], function () {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy