mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-13 11:22:46 +02:00
Move input specific events to input component
This commit is contained in:
parent
852837cd37
commit
fc7b53350a
|
@ -213,8 +213,6 @@ class Choices {
|
||||||
this._onTouchEnd = this._onTouchEnd.bind(this);
|
this._onTouchEnd = this._onTouchEnd.bind(this);
|
||||||
this._onMouseDown = this._onMouseDown.bind(this);
|
this._onMouseDown = this._onMouseDown.bind(this);
|
||||||
this._onMouseOver = this._onMouseOver.bind(this);
|
this._onMouseOver = this._onMouseOver.bind(this);
|
||||||
this._onPaste = this._onPaste.bind(this);
|
|
||||||
this._onInput = this._onInput.bind(this);
|
|
||||||
|
|
||||||
// Monitor touch taps/scrolls
|
// Monitor touch taps/scrolls
|
||||||
this.wasTap = true;
|
this.wasTap = true;
|
||||||
|
@ -1494,10 +1492,10 @@ class Choices {
|
||||||
this.containerOuter.element.addEventListener('blur', this._onBlur);
|
this.containerOuter.element.addEventListener('blur', this._onBlur);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.input.element.addEventListener('input', this._onInput);
|
|
||||||
this.input.element.addEventListener('paste', this._onPaste);
|
|
||||||
this.input.element.addEventListener('focus', this._onFocus);
|
this.input.element.addEventListener('focus', this._onFocus);
|
||||||
this.input.element.addEventListener('blur', this._onBlur);
|
this.input.element.addEventListener('blur', this._onBlur);
|
||||||
|
|
||||||
|
this.input.addEventListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1519,10 +1517,10 @@ class Choices {
|
||||||
this.containerOuter.element.removeEventListener('blur', this._onBlur);
|
this.containerOuter.element.removeEventListener('blur', this._onBlur);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.input.element.removeEventListener('input', this._onInput);
|
|
||||||
this.input.element.removeEventListener('paste', this._onPaste);
|
|
||||||
this.input.element.removeEventListener('focus', this._onFocus);
|
this.input.element.removeEventListener('focus', this._onFocus);
|
||||||
this.input.element.removeEventListener('blur', this._onBlur);
|
this.input.element.removeEventListener('blur', this._onBlur);
|
||||||
|
|
||||||
|
this.input.removeEventListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1751,17 +1749,6 @@ class Choices {
|
||||||
this.canSearch = this.config.searchEnabled;
|
this.canSearch = this.config.searchEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Input event
|
|
||||||
* @return
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_onInput() {
|
|
||||||
if (!this.isSelectOneElement) {
|
|
||||||
this.input.setWidth();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Touch move event
|
* Touch move event
|
||||||
* @return
|
* @return
|
||||||
|
@ -1911,19 +1898,6 @@ class Choices {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Paste event
|
|
||||||
* @param {Object} e Event
|
|
||||||
* @return
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_onPaste(e) {
|
|
||||||
// Disable pasting into the input if option has been set
|
|
||||||
if (e.target === this.input.element && !this.config.paste) {
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Focus event
|
* Focus event
|
||||||
* @param {Object} e Event
|
* @param {Object} e Event
|
||||||
|
|
|
@ -8,6 +8,44 @@ export default class Input {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
this.element = element;
|
this.element = element;
|
||||||
this.classNames = classNames;
|
this.classNames = classNames;
|
||||||
|
|
||||||
|
// Bind event listeners
|
||||||
|
this.onPaste = this.onPaste.bind(this);
|
||||||
|
this.onInput = this.onInput.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
addEventListeners() {
|
||||||
|
this.element.addEventListener('input', this.onInput);
|
||||||
|
this.element.addEventListener('paste', this.onPaste);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeEventListeners() {
|
||||||
|
this.element.removeEventListener('input', this.onInput);
|
||||||
|
this.element.removeEventListener('paste', this.onPaste);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Input event
|
||||||
|
* @return
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
onInput() {
|
||||||
|
if (!this.instance.isSelectOneElement) {
|
||||||
|
this.setWidth();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paste event
|
||||||
|
* @param {Object} e Event
|
||||||
|
* @return
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
onPaste(e) {
|
||||||
|
// Disable pasting into the input if option has been set
|
||||||
|
if (e.target === this.element && !this.instance.config.paste) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue