mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-08 00:42:15 +02:00
Merge branch 'feature/fuse-config' of github.com:jshjohnson/Choices
This commit is contained in:
commit
7acf306aff
|
@ -108,6 +108,11 @@ Or include Choices directly:
|
|||
flippedState: 'is-flipped',
|
||||
loadingState: 'is-loading',
|
||||
},
|
||||
// Choices uses the great Fuse library for searching. You
|
||||
// can find more options here: https://github.com/krisk/Fuse#options
|
||||
fuseOptions: {
|
||||
include: 'score',
|
||||
},
|
||||
callbackOnInit: null,
|
||||
callbackOnCreateTemplates: null,
|
||||
});
|
||||
|
|
|
@ -105,6 +105,9 @@ class Choices {
|
|||
flippedState: 'is-flipped',
|
||||
loadingState: 'is-loading',
|
||||
},
|
||||
fuseOptions: {
|
||||
include: 'score',
|
||||
},
|
||||
callbackOnInit: null,
|
||||
callbackOnCreateTemplates: null,
|
||||
};
|
||||
|
@ -1138,12 +1141,10 @@ class Choices {
|
|||
const haystack = this.store.getChoicesFilteredBySelectable();
|
||||
const needle = newValue;
|
||||
const keys = isType('Array', this.config.sortFields) ? this.config.sortFields : [this.config.sortFields];
|
||||
const fuse = new Fuse(haystack, {
|
||||
keys,
|
||||
shouldSort: true,
|
||||
include: 'score',
|
||||
});
|
||||
const options = Object.assign(this.config.fuseOptions, { keys });
|
||||
const fuse = new Fuse(haystack, options);
|
||||
const results = fuse.search(needle);
|
||||
|
||||
this.currentValue = newValue;
|
||||
this.highlightPosition = 0;
|
||||
this.isSearching = true;
|
||||
|
|
|
@ -2,6 +2,30 @@ import 'whatwg-fetch';
|
|||
import 'es6-promise';
|
||||
import Choices from '../../assets/scripts/src/choices.js';
|
||||
|
||||
if (typeof Object.assign != 'function') {
|
||||
Object.assign = function (target, varArgs) { // .length of function is 2
|
||||
if (target == null) { // TypeError if undefined or null
|
||||
throw new TypeError('Cannot convert undefined or null to object');
|
||||
}
|
||||
|
||||
var to = Object(target);
|
||||
|
||||
for (var index = 1; index < arguments.length; index++) {
|
||||
var nextSource = arguments[index];
|
||||
|
||||
if (nextSource != null) { // Skip over if undefined or null
|
||||
for (var nextKey in nextSource) {
|
||||
// Avoid bugs when hasOwnProperty is shadowed
|
||||
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
||||
to[nextKey] = nextSource[nextKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return to;
|
||||
};
|
||||
}
|
||||
|
||||
describe('Choices', () => {
|
||||
|
||||
afterEach(function() {
|
||||
|
|
Loading…
Reference in a new issue