Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #220 from ckeditor/t/219
Browse files Browse the repository at this point in the history
Other: Renamed `isDomNode()` to `isNode()`. Closes #219.

BREAKING CHANGE: `isDomNode()` was renamed to `isNode()`.
  • Loading branch information
Reinmar authored Feb 2, 2018
2 parents a9a6bec + d487dd7 commit 1823196
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/dom/emittermixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { default as EmitterMixin, _getEmitterListenedTo, _setEmitterId } from '../emittermixin';
import uid from '../uid';
import extend from '../lib/lodash/extend';
import isDomNode from './isdomnode';
import isNode from './isnode';
import isWindow from './iswindow';

/**
Expand Down Expand Up @@ -53,7 +53,7 @@ const DomEmitterMixin = extend( {}, EmitterMixin, {
listenTo( emitter, ...rest ) {
// Check if emitter is an instance of DOM Node. If so, replace the argument with
// corresponding ProxyEmitter (or create one if not existing).
if ( isDomNode( emitter ) || isWindow( emitter ) ) {
if ( isNode( emitter ) || isWindow( emitter ) ) {
const proxy = this._getProxyEmitter( emitter ) || new ProxyEmitter( emitter );

proxy.attach( ...rest );
Expand Down Expand Up @@ -82,7 +82,7 @@ const DomEmitterMixin = extend( {}, EmitterMixin, {
*/
stopListening( emitter, event, callback ) {
// Check if emitter is an instance of DOM Node. If so, replace the argument with corresponding ProxyEmitter.
if ( isDomNode( emitter ) || isWindow( emitter ) ) {
if ( isNode( emitter ) || isWindow( emitter ) ) {
const proxy = this._getProxyEmitter( emitter );

// Element has no listeners.
Expand Down
4 changes: 2 additions & 2 deletions src/dom/isdomnode.js → src/dom/isnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/**
* @module utils/dom/isdomnode
* @module utils/dom/isnode
*/

/**
Expand All @@ -13,7 +13,7 @@
* @param {*} obj
* @returns {Boolean}
*/
export default function isDomNode( obj ) {
export default function isNode( obj ) {
if ( obj ) {
if ( obj.defaultView ) {
return obj instanceof obj.defaultView.Document;
Expand Down
32 changes: 16 additions & 16 deletions tests/dom/isdomnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

/* global document, window */

import isDomNode from '../../src/dom/isdomnode';
import isNode from '../../src/dom/isnode';

describe( 'isDomNode()', () => {
describe( 'isNode()', () => {
it( 'detects native DOM nodes', () => {
expect( isDomNode( document ) ).to.be.true;
expect( isDomNode( document.createElement( 'div' ) ) ).to.be.true;
expect( isDomNode( document.createTextNode( 'Foo' ) ) ).to.be.true;

expect( isDomNode( {} ) ).to.be.false;
expect( isDomNode( null ) ).to.be.false;
expect( isDomNode( undefined ) ).to.be.false;
expect( isDomNode( new Date() ) ).to.be.false;
expect( isDomNode( 42 ) ).to.be.false;
expect( isDomNode( window ) ).to.be.false;
expect( isNode( document ) ).to.be.true;
expect( isNode( document.createElement( 'div' ) ) ).to.be.true;
expect( isNode( document.createTextNode( 'Foo' ) ) ).to.be.true;

expect( isNode( {} ) ).to.be.false;
expect( isNode( null ) ).to.be.false;
expect( isNode( undefined ) ).to.be.false;
expect( isNode( new Date() ) ).to.be.false;
expect( isNode( 42 ) ).to.be.false;
expect( isNode( window ) ).to.be.false;
} );

it( 'works for nodes in an iframe', done => {
Expand All @@ -27,11 +27,11 @@ describe( 'isDomNode()', () => {
iframe.addEventListener( 'load', () => {
const iframeDocument = iframe.contentWindow.document;

expect( isDomNode( iframeDocument ) ).to.be.true;
expect( isDomNode( iframeDocument.createElement( 'div' ) ) ).to.be.true;
expect( isDomNode( iframeDocument.createTextNode( 'Foo' ) ) ).to.be.true;
expect( isNode( iframeDocument ) ).to.be.true;
expect( isNode( iframeDocument.createElement( 'div' ) ) ).to.be.true;
expect( isNode( iframeDocument.createTextNode( 'Foo' ) ) ).to.be.true;

expect( isDomNode( iframe.contentWindow ) ).to.be.false;
expect( isNode( iframe.contentWindow ) ).to.be.false;

iframe.remove();
done();
Expand Down

0 comments on commit 1823196

Please sign in to comment.