Przeglądaj źródła

Renamed Rect#_obj to Rect#_source. Code refactoring.

Aleksander Nowodzinski 8 lat temu
rodzic
commit
d6b2b2138c

+ 12 - 12
packages/ckeditor5-utils/src/dom/rect.js

@@ -37,28 +37,28 @@ export default class Rect {
 	 *		// Rect out of a ClientRect.
 	 *		const rectE = new Rect( document.body.getClientRects().item( 0 ) );
 	 *
-	 * @param {HTMLElement|Range|ClientRect|module:utils/dom/rect~Rect|Object} obj A source object to create the rect.
+	 * @param {HTMLElement|Range|ClientRect|module:utils/dom/rect~Rect|Object} source A source object to create the rect.
 	 */
-	constructor( obj ) {
+	constructor( source ) {
 		/**
 		 * The object this rect is for.
 		 *
 		 * @protected
 		 * @readonly
-		 * @member {HTMLElement|Range|ClientRect|module:utils/dom/rect~Rect|Object} #_obj
+		 * @member {HTMLElement|Range|ClientRect|module:utils/dom/rect~Rect|Object} #_source
 		 */
-		Object.defineProperty( this, '_obj', {
-			// obj._obj if already the Rect instance
-			value: obj._obj || obj,
+		Object.defineProperty( this, '_source', {
+			// source._source if already the Rect instance
+			value: source._source || source,
 			writable: false,
 			enumerable: false
 		} );
 
-		if ( isElement( obj ) || isRange( obj ) ) {
-			obj = obj.getBoundingClientRect();
+		if ( isElement( source ) || isRange( source ) ) {
+			source = source.getBoundingClientRect();
 		}
 
-		rectProperties.forEach( p => this[ p ] = obj[ p ] );
+		rectProperties.forEach( p => this[ p ] = source[ p ] );
 
 		/**
 		 * The "top" value of the rect.
@@ -204,12 +204,12 @@ export default class Rect {
 	 * @returns {module:utils/dom/rect~Rect|null} A visible rect instance or `null`, if there's none.
 	 */
 	getVisible() {
-		const obj = this._obj;
+		const source = this._source;
 		let visibleRect = this.clone();
 
 		// There's no ancestor to crop <body> with the overflow.
-		if ( obj != global.document.body ) {
-			let parent = obj.parentNode || obj.commonAncestorContainer;
+		if ( source != global.document.body ) {
+			let parent = source.parentNode || source.commonAncestorContainer;
 
 			// Check the ancestors all the way up to the <body>.
 			while ( parent && parent != global.document.body ) {

+ 1 - 5
packages/ckeditor5-utils/tests/dom/position.js

@@ -162,19 +162,15 @@ describe( 'getOptimalPosition()', () => {
 
 		// https://github.com/ckeditor/ckeditor5-utils/issues/148
 		it( 'should return coordinates (#3)', () => {
-			const overflowedAncestor = getElement( {
+			limiter.parentNode = getElement( {
 				top: 100,
 				left: 0,
 				bottom: 110,
 				right: 10,
 				width: 10,
 				height: 10
-			}, {
-				overflow: 'scroll'
 			} );
 
-			limiter.parentNode = overflowedAncestor;
-
 			assertPosition( {
 				element, target, limiter,
 				positions: [ attachRight, attachLeft ]

+ 4 - 4
packages/ckeditor5-utils/tests/dom/rect.js

@@ -26,11 +26,11 @@ describe( 'Rect', () => {
 	} );
 
 	describe( 'constructor()', () => {
-		it( 'should store passed object in #_obj property', () => {
+		it( 'should store passed object in #_source property', () => {
 			const obj = {};
 			const rect = new Rect( obj );
 
-			expect( rect._obj ).to.equal( obj );
+			expect( rect._source ).to.equal( obj );
 		} );
 
 		it( 'should accept HTMLElement', () => {
@@ -105,11 +105,11 @@ describe( 'Rect', () => {
 			assertRect( clone, rect );
 		} );
 
-		it( 'should preserve #_obj', () => {
+		it( 'should preserve #_source', () => {
 			const rect = new Rect( geometry );
 			const clone = rect.clone();
 
-			expect( clone._obj ).to.equal( rect._obj );
+			expect( clone._source ).to.equal( rect._source );
 			assertRect( clone, rect );
 		} );
 	} );