This commit is contained in:
barsdeveloper
2022-04-02 11:13:34 +02:00
parent 9ab8801eee
commit e901932953
26 changed files with 392 additions and 279 deletions

View File

@@ -14,38 +14,33 @@ export default class IContext {
/** @type {Object} */
options
#hasFocus = false
get hasFocus() {
return this.#hasFocus
}
set hasFocus(_) {
}
constructor(target, blueprint, options) {
this.target = target
this.blueprint = blueprint
this.options = options
let self = this
this.blueprintFocusHandler = _ => {
this.#hasFocus = true
this.listenHandler = _ => {
self.listenEvents()
}
this.blueprintUnfocusHandler = _ => {
this.unlistenHandler = _ => {
self.unlistenEvents()
this.#hasFocus = false
}
if (options?.wantsFocusCallback ?? false) {
this.blueprint.addEventListener("blueprint-focus", this.blueprintFocusHandler)
this.blueprint.addEventListener("blueprint-unfocus", this.blueprintUnfocusHandler)
if (options?.listenOnFocus ?? false) {
this.blueprint.addEventListener("blueprint-focus", this.listenHandler)
this.blueprint.addEventListener("blueprint-unfocus", this.unlistenHandler)
}
if (options?.unlistenOnEditText ?? false) {
this.blueprint.addEventListener(this.blueprint.settings.editTextEventName.begin, this.unlistenHandler)
this.blueprint.addEventListener(this.blueprint.settings.editTextEventName.end, this.listenHandler)
}
}
unlistenDOMElement() {
this.unlistenEvents()
this.blueprint.removeEventListener("blueprint-focus", this.blueprintFocusHandler)
this.blueprint.removeEventListener("blueprint-unfocus", this.blueprintUnfocusHandler)
this.blueprint.removeEventListener("blueprint-focus", this.listenHandler)
this.blueprint.removeEventListener("blueprint-unfocus", this.unlistenHandler)
this.blueprint.removeEventListener(this.blueprint.settings.editTextEventName.begin, this.unlistenHandler)
this.blueprint.removeEventListener(this.blueprint.settings.editTextEventName.end, this.listenHandler)
}
/* Subclasses will probabily override the following methods */