mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-01 13:32:23 +02:00
Remove unneccessary requestAnimation frame polyfill + type check before adding first predefined select option
This commit is contained in:
parent
81cef3090c
commit
7207ee543f
|
@ -618,6 +618,7 @@ Choices is compiled using [Babel](https://babeljs.io/) to enable support for [ES
|
||||||
* Array.prototype.reduce
|
* Array.prototype.reduce
|
||||||
* Array.prototype.indexOf
|
* Array.prototype.indexOf
|
||||||
* Element.prototype.classList
|
* Element.prototype.classList
|
||||||
|
* window.requestAnimationFrame
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
To setup a local environment: clone this repo, navigate into it's directory in a terminal window and run the following command:
|
To setup a local environment: clone this repo, navigate into it's directory in a terminal window and run the following command:
|
||||||
|
|
4
assets/scripts/dist/choices.min.js
vendored
4
assets/scripts/dist/choices.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -782,6 +782,7 @@ export default class Choices {
|
||||||
this.isSearching = false;
|
this.isSearching = false;
|
||||||
this.store.dispatch(activateChoices(true));
|
this.store.dispatch(activateChoices(true));
|
||||||
|
|
||||||
|
// We only hide the dropdown on a choice selection for single select boxes
|
||||||
if (this.passedElement.type === 'select-one' && hasActiveDropdown) {
|
if (this.passedElement.type === 'select-one' && hasActiveDropdown) {
|
||||||
this.hideDropdown();
|
this.hideDropdown();
|
||||||
}
|
}
|
||||||
|
@ -1004,7 +1005,9 @@ export default class Choices {
|
||||||
|
|
||||||
// All is good, add
|
// All is good, add
|
||||||
if (canAddItem.response) {
|
if (canAddItem.response) {
|
||||||
this.toggleDropdown();
|
if (hasActiveDropdown) {
|
||||||
|
this.hideDropdown();
|
||||||
|
}
|
||||||
this._addItem(value);
|
this._addItem(value);
|
||||||
this._triggerChange(value);
|
this._triggerChange(value);
|
||||||
this.clearInput(this.passedElement);
|
this.clearInput(this.passedElement);
|
||||||
|
@ -1022,9 +1025,15 @@ export default class Choices {
|
||||||
if (highlighted) {
|
if (highlighted) {
|
||||||
this._handleChoiceAction(activeItems, highlighted);
|
this._handleChoiceAction(activeItems, highlighted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We always want to hide the dropdown for single selects
|
||||||
|
// regardless of whether an item was added
|
||||||
|
if (hasActiveDropdown && this.passedElement.type === 'select-one') {
|
||||||
|
this.hideDropdown();
|
||||||
|
}
|
||||||
} else if (this.passedElement.type === 'select-one') {
|
} else if (this.passedElement.type === 'select-one') {
|
||||||
|
// Open single select dropdown if it's not active
|
||||||
if (!hasActiveDropdown) {
|
if (!hasActiveDropdown) {
|
||||||
// Show dropdown if focus
|
|
||||||
this.showDropdown(true);
|
this.showDropdown(true);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
@ -1885,7 +1894,7 @@ export default class Choices {
|
||||||
allChoices
|
allChoices
|
||||||
.concat(this.presetChoices)
|
.concat(this.presetChoices)
|
||||||
.forEach((o, index) => {
|
.forEach((o, index) => {
|
||||||
if (index === 0) {
|
if (index === 0 && this.passedElement.type === 'select-one') {
|
||||||
this._addChoice(true, o.disabled ? o.disabled : false, o.value, o.label);
|
this._addChoice(true, o.disabled ? o.disabled : false, o.value, o.label);
|
||||||
} else {
|
} else {
|
||||||
this._addChoice(o.selected ? o.selected : false, o.disabled ? o.disabled : false, o.value, o.label);
|
this._addChoice(o.selected ? o.selected : false, o.disabled ? o.disabled : false, o.value, o.label);
|
||||||
|
|
|
@ -110,36 +110,4 @@ if (!Array.prototype.find) {
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
(function() {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var lastTime = 0,
|
|
||||||
vendors = ['ms', 'moz', 'webkit', 'o'],
|
|
||||||
x;
|
|
||||||
|
|
||||||
for (x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
|
|
||||||
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
|
|
||||||
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] ||
|
|
||||||
window[vendors[x] + 'CancelRequestAnimationFrame'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!window.requestAnimationFrame) {
|
|
||||||
window.requestAnimationFrame = function(callback, element) {
|
|
||||||
var currTime = new Date().getTime(),
|
|
||||||
timeToCall = Math.max(0, 16 - (currTime - lastTime)),
|
|
||||||
id = window.setTimeout(function() {
|
|
||||||
callback(currTime + timeToCall);
|
|
||||||
}, timeToCall);
|
|
||||||
lastTime = currTime + timeToCall;
|
|
||||||
return id;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!window.cancelAnimationFrame) {
|
|
||||||
window.cancelAnimationFrame = function(id) {
|
|
||||||
window.clearTimeout(id);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}());
|
|
|
@ -66,9 +66,9 @@
|
||||||
<h2>Multiple select input</h2>
|
<h2>Multiple select input</h2>
|
||||||
<label for="choices-7">Default</label>
|
<label for="choices-7">Default</label>
|
||||||
<select class="form-control" data-choice name="choices-7" id="choices-7" placeholder="This is a placeholder" multiple>
|
<select class="form-control" data-choice name="choices-7" id="choices-7" placeholder="This is a placeholder" multiple>
|
||||||
<option value="Dropdown item 1">Dropdown item 1</option>
|
<option value="Dropdown item 1" selected>Dropdown item 1</option>
|
||||||
<option value="Dropdown item 2">Dropdown item 2</option>
|
<option value="Dropdown item 2">Dropdown item 2</option>
|
||||||
<option value="Dropdown item 3" selected>Dropdown item 3</option>
|
<option value="Dropdown item 3">Dropdown item 3</option>
|
||||||
<option value="Dropdown item 4" disabled>Dropdown item 4</option>
|
<option value="Dropdown item 4" disabled>Dropdown item 4</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue