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

Commit

Permalink
Renamed Rect#_obj to Rect#_source. Code refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Apr 19, 2017
1 parent 24e1d14 commit 1123afd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
24 changes: 12 additions & 12 deletions src/dom/rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 ) {
Expand Down
6 changes: 1 addition & 5 deletions tests/dom/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
8 changes: 4 additions & 4 deletions tests/dom/rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 );
} );
} );
Expand Down

0 comments on commit 1123afd

Please sign in to comment.