我已經構建了一個將指針事件偵聽器附加到DOM元素(here)的JavaScript庫。今天,我用它在聚合物1.9 Web組件來包裝它,使用PEP來填充工具在Firefox上指針的事件,並能正常工作:如何使用Polymer 2捕獲Firefox上webcomponent中的指針事件?
<link rel="import" href="./pepjs-import.html">
<link rel="import" href="./myscriptjs-import.html">
<dom-module id="myscript-common-element">
<template>
<style></style>
<div id="editorDomElement" class="ms-editor"></div>
</template>
<script>
Polymer({
is: 'myscript-common-element',
properties: {},
attached: function() {
this.editorDomElement = this.querySelector('#editorDomElement');
// Attach an editor to the DOM element and listen pointer events
this.editor = MyScript.register(this.editorDomElement, this.buildConfiguration(), this.buildCustomStyle());
}
}
);
</script>
我只是在做elementDomElement.addEventListener('pointerdown', (e) => { // Some code });
下寄存器, 沒什麼特別的。
遷移到聚合物2後,我有這樣的事情:
<dom-module id="myscript-common-element">
<template>
<style></style>
<div id="editorDomElement" class="ms-editor"></div>
</template>
<script>
class MyScriptCommonElement extends Polymer.mixinBehaviors([Polymer.IronResizableBehavior], Polymer.Element) {
static get is() {
return 'myscript-common-element'
}
connectedCallback() {
super.connectedCallback();
this.editorDomElement = this.shadowRoot.querySelector('#editorDomElement');
this.editor = MyScript.register(this.editorDomElement, this._buildConfiguration(), this._buildCustomStyle());
}
}
customElements.define(MyScriptCommonElement.is, MyScriptCommonElement);
</script>
指針事件Chrome和邊緣下正確處理,但在Firefox事件被卡在shadowRoot。如果我在this
上收聽,我可以處理它們。 shadowRoot,但不在editorDomElement
上。
我做錯了什麼,或者它是在Firefox上的聚合物2事件轉發問題?有沒有解決方法或解決方法,使其工作? 謝謝
全聚合物1.9代碼: https://github.com/MyScript/myscript-common-element/blob/2.0.0-alpha1/myscript-common-element.html – FXG