mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-03 06:22:25 +02:00
Observe store function - to be implemented
This commit is contained in:
parent
9679a42966
commit
818450dfa5
2
assets/scripts/dist/bundle.js
vendored
2
assets/scripts/dist/bundle.js
vendored
File diff suppressed because one or more lines are too long
|
@ -42,6 +42,7 @@ export class Choices {
|
||||||
maxItems: false,
|
maxItems: false,
|
||||||
delimiter: ',',
|
delimiter: ',',
|
||||||
allowDuplicates: true,
|
allowDuplicates: true,
|
||||||
|
allowPaste: true,
|
||||||
regexFilter: false,
|
regexFilter: false,
|
||||||
debug: false,
|
debug: false,
|
||||||
placeholder: false,
|
placeholder: false,
|
||||||
|
@ -100,6 +101,7 @@ export class Choices {
|
||||||
this.destroy = this.destroy.bind(this);
|
this.destroy = this.destroy.bind(this);
|
||||||
this.onKeyDown = this.onKeyDown.bind(this);
|
this.onKeyDown = this.onKeyDown.bind(this);
|
||||||
this.onClick = this.onClick.bind(this);
|
this.onClick = this.onClick.bind(this);
|
||||||
|
this.onPaste = this.onPaste.bind(this);
|
||||||
|
|
||||||
// Let's have it large
|
// Let's have it large
|
||||||
this.init();
|
this.init();
|
||||||
|
@ -289,7 +291,12 @@ export class Choices {
|
||||||
this.toggleDropdown();
|
this.toggleDropdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onPaste(e) {
|
||||||
|
if(!this.options.allowPaste) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
|
@ -676,6 +683,7 @@ export class Choices {
|
||||||
addEventListeners() {
|
addEventListeners() {
|
||||||
document.addEventListener('keydown', this.onKeyDown);
|
document.addEventListener('keydown', this.onKeyDown);
|
||||||
document.addEventListener('click', this.onClick);
|
document.addEventListener('click', this.onClick);
|
||||||
|
document.addEventListener('paste', this.onPaste);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -684,6 +692,23 @@ export class Choices {
|
||||||
removeEventListeners() {
|
removeEventListeners() {
|
||||||
document.removeEventListener('keydown', this.onKeyDown);
|
document.removeEventListener('keydown', this.onKeyDown);
|
||||||
document.removeEventListener('click', this.onClick);
|
document.removeEventListener('click', this.onClick);
|
||||||
|
document.removeEventListener('paste', this.onPaste);
|
||||||
|
}
|
||||||
|
|
||||||
|
observeStore(store, select, onChange) {
|
||||||
|
let currentState;
|
||||||
|
|
||||||
|
function handleChange() {
|
||||||
|
let nextState = select(store.getState());
|
||||||
|
if (nextState !== currentState) {
|
||||||
|
currentState = nextState;
|
||||||
|
onChange(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let unsubscribe = store.subscribe(handleChange);
|
||||||
|
handleChange();
|
||||||
|
return unsubscribe;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -823,6 +848,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const choices2 = new Choices('#choices-2', {
|
const choices2 = new Choices('#choices-2', {
|
||||||
|
allowPaste: false,
|
||||||
allowDuplicates: false,
|
allowDuplicates: false,
|
||||||
editItems: true,
|
editItems: true,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue