Version 2.8.1

This commit is contained in:
Josh Johnson 2017-05-11 15:12:14 +01:00
parent 43f618822d
commit c8e9ce9f27
6 changed files with 37 additions and 31 deletions

View file

@ -1,4 +1,4 @@
/*! choices.js v2.7.8 | (c) 2017 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ /*! choices.js v2.8.1 | (c) 2017 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
(function webpackUniversalModuleDefinition(root, factory) { (function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object') if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(); module.exports = factory();
@ -497,11 +497,20 @@ return /******/ (function(modules) { // webpackBootstrap
choiceListFragment = this.renderChoices(activeChoices, choiceListFragment); choiceListFragment = this.renderChoices(activeChoices, choiceListFragment);
} }
var activeItems = this.store.getItemsFilteredByActive();
var canAddItem = this._canAddItem(activeItems, this.input.value);
// If we have choices to show
if (choiceListFragment.childNodes && choiceListFragment.childNodes.length > 0) { if (choiceListFragment.childNodes && choiceListFragment.childNodes.length > 0) {
// If we actually have anything to add to our dropdown // ...and we can select them
// append it and highlight the first choice if (canAddItem.response) {
this.choiceList.appendChild(choiceListFragment); // ...append them and highlight the first choice
this._highlightChoice(); this.choiceList.appendChild(choiceListFragment);
this._highlightChoice();
} else {
// ...otherwise show a notice
this.choiceList.appendChild(this._getTemplate('notice', canAddItem.notice));
}
} else { } else {
// Otherwise show a notice // Otherwise show a notice
var dropdownItem = void 0; var dropdownItem = void 0;
@ -509,9 +518,11 @@ return /******/ (function(modules) { // webpackBootstrap
if (this.isSearching) { if (this.isSearching) {
notice = (0, _utils.isType)('Function', this.config.noResultsText) ? this.config.noResultsText() : this.config.noResultsText; notice = (0, _utils.isType)('Function', this.config.noResultsText) ? this.config.noResultsText() : this.config.noResultsText;
dropdownItem = this._getTemplate('notice', notice); dropdownItem = this._getTemplate('notice', notice);
} else { } else {
notice = (0, _utils.isType)('Function', this.config.noChoicesText) ? this.config.noChoicesText() : this.config.noChoicesText; notice = (0, _utils.isType)('Function', this.config.noChoicesText) ? this.config.noChoicesText() : this.config.noChoicesText;
dropdownItem = this._getTemplate('notice', notice); dropdownItem = this._getTemplate('notice', notice);
} }
@ -522,11 +533,11 @@ return /******/ (function(modules) { // webpackBootstrap
// Items // Items
if (this.currentState.items !== this.prevState.items) { if (this.currentState.items !== this.prevState.items) {
var activeItems = this.store.getItemsFilteredByActive(); var _activeItems = this.store.getItemsFilteredByActive();
if (activeItems) { if (_activeItems) {
// Create a fragment to store our list items // Create a fragment to store our list items
// (so we don't have to update the DOM for each item) // (so we don't have to update the DOM for each item)
var itemListFragment = this.renderItems(activeItems); var itemListFragment = this.renderItems(_activeItems);
// Clear list // Clear list
this.itemList.innerHTML = ''; this.itemList.innerHTML = '';
@ -758,7 +769,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.dropdown.setAttribute('aria-expanded', 'true'); this.dropdown.setAttribute('aria-expanded', 'true');
var dimensions = this.dropdown.getBoundingClientRect(); var dimensions = this.dropdown.getBoundingClientRect();
var dropdownPos = Math.ceil(dimensions.top + window.scrollY + dimensions.height); var dropdownPos = Math.ceil(dimensions.top + window.scrollY + this.dropdown.offsetHeight);
// If flip is enabled and the dropdown bottom position is greater than the window height flip the dropdown. // If flip is enabled and the dropdown bottom position is greater than the window height flip the dropdown.
var shouldFlip = false; var shouldFlip = false;
@ -770,8 +781,6 @@ return /******/ (function(modules) { // webpackBootstrap
if (shouldFlip) { if (shouldFlip) {
this.containerOuter.classList.add(this.config.classNames.flippedState); this.containerOuter.classList.add(this.config.classNames.flippedState);
} else {
this.containerOuter.classList.remove(this.config.classNames.flippedState);
} }
// Optionally focus the input if we have a search input // Optionally focus the input if we have a search input
@ -1282,7 +1291,7 @@ return /******/ (function(modules) { // webpackBootstrap
var notice = (0, _utils.isType)('Function', this.config.addItemText) ? this.config.addItemText(value) : this.config.addItemText; var notice = (0, _utils.isType)('Function', this.config.addItemText) ? this.config.addItemText(value) : this.config.addItemText;
if (this.passedElement.type === 'select-multiple' || this.passedElement.type === 'text') { if (this.passedElement.type === 'select-multiple' || this.passedElement.type === 'text') {
if (this.config.maxItemCount > 0 && this.config.maxItemCount <= this.itemList.children.length) { if (this.config.maxItemCount > 0 && this.config.maxItemCount <= activeItems.length) {
// If there is a max entry limit and we have reached that limit // If there is a max entry limit and we have reached that limit
// don't update // don't update
canAddItem = false; canAddItem = false;
@ -1290,7 +1299,7 @@ return /******/ (function(modules) { // webpackBootstrap
} }
} }
if (this.passedElement.type === 'text' && this.config.addItems) { if (this.passedElement.type === 'text' && this.config.addItems && canAddItem) {
var isUnique = !activeItems.some(function (item) { var isUnique = !activeItems.some(function (item) {
return item.value === value.trim(); return item.value === value.trim();
}); });
@ -1705,15 +1714,15 @@ return /******/ (function(modules) { // webpackBootstrap
value: function _onKeyUp(e) { value: function _onKeyUp(e) {
if (e.target !== this.input) return; if (e.target !== this.input) return;
var value = this.input.value;
var activeItems = this.store.getItemsFilteredByActive();
var canAddItem = this._canAddItem(activeItems, value);
// We are typing into a text input and have a value, we want to show a dropdown // We are typing into a text input and have a value, we want to show a dropdown
// notice. Otherwise hide the dropdown // notice. Otherwise hide the dropdown
if (this.isTextElement) { if (this.isTextElement) {
var hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState); var hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState);
var value = this.input.value;
if (value) { if (value) {
var activeItems = this.store.getItemsFilteredByActive();
var canAddItem = this._canAddItem(activeItems, value);
if (canAddItem.notice) { if (canAddItem.notice) {
var dropdownItem = this._getTemplate('notice', canAddItem.notice); var dropdownItem = this._getTemplate('notice', canAddItem.notice);
@ -1741,7 +1750,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.isSearching = false; this.isSearching = false;
this.store.dispatch((0, _index3.activateChoices)(true)); this.store.dispatch((0, _index3.activateChoices)(true));
} }
} else if (this.canSearch) { } else if (this.canSearch && canAddItem.response) {
this._handleSearch(this.input.value); this._handleSearch(this.input.value);
} }
} }
@ -2689,10 +2698,7 @@ return /******/ (function(modules) { // webpackBootstrap
* @param {!Object<string, *>} options * @param {!Object<string, *>} options
*/ */
function Fuse (list, options) { function Fuse (list, options) {
var i
var len
var key var key
var keys
this.list = list this.list = list
this.options = options = options || {} this.options = options = options || {}
@ -2711,7 +2717,7 @@ return /******/ (function(modules) { // webpackBootstrap
} }
} }
Fuse.VERSION = '2.6.0' Fuse.VERSION = '2.6.2'
/** /**
* Sets a new list for Fuse to match against. * Sets a new list for Fuse to match against.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{ {
"name": "choices.js", "name": "choices.js",
"version": "2.7.8", "version": "2.8.1",
"description": "A vanilla JS customisable text input/select box plugin", "description": "A vanilla JS customisable text input/select box plugin",
"main": [ "main": [
"./assets/scripts/dist/choices.js", "./assets/scripts/dist/choices.js",

View file

@ -15,7 +15,7 @@
<meta name="theme-color" content="#ffffff"> <meta name="theme-color" content="#ffffff">
<!-- Ignore these --> <!-- Ignore these -->
<link rel="stylesheet" href="assets/styles/css/base.min.css?version=2.7.8"> <link rel="stylesheet" href="assets/styles/css/base.min.css?version=2.8.1">
<!-- End ignore these --> <!-- End ignore these -->
<!-- Optional includes --> <!-- Optional includes -->
@ -23,8 +23,8 @@
<!-- End optional includes --> <!-- End optional includes -->
<!-- Choices includes --> <!-- Choices includes -->
<link rel="stylesheet" href="assets/styles/css/choices.min.css?version=2.7.8"> <link rel="stylesheet" href="assets/styles/css/choices.min.css?version=2.8.1">
<script src="assets/scripts/dist/choices.min.js?version=2.7.8"></script> <script src="assets/scripts/dist/choices.min.js?version=2.8.1"></script>
<!-- End Choices includes --> <!-- End Choices includes -->
<!--[if lt IE 9]> <!--[if lt IE 9]>

View file

@ -1,6 +1,6 @@
{ {
"name": "choices.js", "name": "choices.js",
"version": "2.7.8", "version": "2.8.1",
"description": "A vanilla JS customisable text input/select box plugin", "description": "A vanilla JS customisable text input/select box plugin",
"main": "./assets/scripts/dist/choices.min.js", "main": "./assets/scripts/dist/choices.min.js",
"scripts": { "scripts": {