8
0
Aleksander Nowodzinski 8 лет назад
Родитель
Сommit
05c0169369

+ 18 - 0
packages/ckeditor5-utils/src/dom/iswindow.js

@@ -0,0 +1,18 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/**
+ * @module utils/dom/iswindow
+ */
+
+/**
+ * Checks if the object is a native DOM Window.
+ *
+ * @param {*} obj
+ * @returns {Boolean}
+ */
+export default function isWindow( obj ) {
+	return Object.prototype.toString.apply( obj ) == '[object Window]';
+}

+ 19 - 0
packages/ckeditor5-utils/tests/dom/iswindow.js

@@ -0,0 +1,19 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global window */
+
+import isWindow from '../../src/dom/iswindow';
+
+describe( 'isWindow()', () => {
+	it( 'detects DOM Window', () => {
+		expect( isWindow( window ) ).to.be.true;
+		expect( isWindow( {} ) ).to.be.false;
+		expect( isWindow( null ) ).to.be.false;
+		expect( isWindow( undefined ) ).to.be.false;
+		expect( isWindow( new Date() ) ).to.be.false;
+		expect( isWindow( 42 ) ).to.be.false;
+	} );
+} );