|
|
@@ -49,6 +49,8 @@ const DomEmitterMixin = extend( {}, EmitterMixin, {
|
|
|
* order they were added.
|
|
|
* @param {Boolean} [options.useCapture=false] Indicates that events of this type will be dispatched to the registered
|
|
|
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
|
+ * @param {Boolean} [options.usePassive=false] Indicates that the function specified by listener will never call preventDefault()
|
|
|
+ * and prevents blocking browser's main thread by this event handler.
|
|
|
*/
|
|
|
listenTo( emitter, ...rest ) {
|
|
|
// Check if emitter is an instance of DOM Node. If so, replace the argument with
|
|
|
@@ -179,6 +181,8 @@ extend( ProxyEmitter.prototype, EmitterMixin, {
|
|
|
* @param {Object} [options={}] Additional options.
|
|
|
* @param {Boolean} [options.useCapture=false] Indicates that events of this type will be dispatched to the registered
|
|
|
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
|
+ * @param {Boolean} [options.usePassive=false] Indicates that the function specified by listener will never call preventDefault()
|
|
|
+ * and prevents blocking browser's main thread by this event handler.
|
|
|
*/
|
|
|
attach( event, callback, options = {} ) {
|
|
|
// If the DOM Listener for given event already exist it is pointless
|
|
|
@@ -187,10 +191,15 @@ extend( ProxyEmitter.prototype, EmitterMixin, {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const domListener = this._createDomListener( event, !!options.useCapture );
|
|
|
+ const listenerOptions = {
|
|
|
+ capture: !!options.useCapture,
|
|
|
+ passive: !!options.usePassive
|
|
|
+ };
|
|
|
+
|
|
|
+ const domListener = this._createDomListener( event, listenerOptions );
|
|
|
|
|
|
// Attach the native DOM listener to DOM Node.
|
|
|
- this._domNode.addEventListener( event, domListener, !!options.useCapture );
|
|
|
+ this._domNode.addEventListener( event, domListener, listenerOptions );
|
|
|
|
|
|
if ( !this._domListeners ) {
|
|
|
this._domListeners = {};
|
|
|
@@ -227,10 +236,13 @@ extend( ProxyEmitter.prototype, EmitterMixin, {
|
|
|
* @private
|
|
|
* @method module:utils/dom/emittermixin~ProxyEmitter#_createDomListener
|
|
|
* @param {String} event The name of the event.
|
|
|
- * @param {Boolean} useCapture Indicates whether the listener was created for capturing event.
|
|
|
+ * @param {Object} [options] Additional options.
|
|
|
+ * @param {Boolean} [options.capture=false] Indicates whether the listener was created for capturing event.
|
|
|
+ * @param {Boolean} [options.passive=false] Indicates that the function specified by listener will never call preventDefault()
|
|
|
+ * and prevents blocking browser's main thread by this event handler.
|
|
|
* @returns {Function} The DOM listener callback.
|
|
|
*/
|
|
|
- _createDomListener( event, useCapture ) {
|
|
|
+ _createDomListener( event, options ) {
|
|
|
const domListener = domEvt => {
|
|
|
this.fire( event, domEvt );
|
|
|
};
|
|
|
@@ -239,7 +251,7 @@ extend( ProxyEmitter.prototype, EmitterMixin, {
|
|
|
// detach it from the DOM Node, when it is no longer necessary.
|
|
|
// See: {@link detach}.
|
|
|
domListener.removeListener = () => {
|
|
|
- this._domNode.removeEventListener( event, domListener, useCapture );
|
|
|
+ this._domNode.removeEventListener( event, domListener, options );
|
|
|
delete this._domListeners[ event ];
|
|
|
};
|
|
|
|