浏览代码

Imported dom/toPix util to pixelize any value.

Aleksander Nowodzinski 9 年之前
父节点
当前提交
0e557076f1
共有 2 个文件被更改,包括 34 次插入0 次删除
  1. 13 0
      packages/ckeditor5-utils/src/dom/topx.js
  2. 21 0
      packages/ckeditor5-utils/tests/dom/topx.js

+ 13 - 0
packages/ckeditor5-utils/src/dom/topx.js

@@ -0,0 +1,13 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/**
+ * Adds `px` unit to the passed value.
+ *
+ * @method utils.dom.toPx
+ * @param {*} value A value to be "pixelized".
+ * @returns {String} A value with the trailing "px" unit.
+ */
+export default ( value ) => `${ value }px`;

+ 21 - 0
packages/ckeditor5-utils/tests/dom/topx.js

@@ -0,0 +1,21 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* bender-tags: dom */
+
+import toPx from '/ckeditor5/utils/dom/topx.js';
+
+describe( 'toPx', () => {
+	it( 'should be a function', () => {
+		expect( toPx ).to.be.a( 'function' );
+	} );
+
+	it( 'should always pixelize the value', () => {
+		expect( toPx( null ) ).to.equal( 'nullpx' );
+		expect( toPx( undefined ) ).to.equal( 'undefinedpx' );
+		expect( toPx( '10' ) ).to.equal( '10px' );
+		expect( toPx( 10 ) ).to.equal( '10px' );
+	} );
+} );