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

t/105: Moved rect utilities from BalloonPanelView #106

Merged
merged 19 commits into from
Dec 8, 2016
Merged

t/105: Moved rect utilities from BalloonPanelView #106

merged 19 commits into from
Dec 8, 2016

Conversation

oleq
Copy link
Member

@oleq oleq commented Dec 2, 2016

@Reinmar
Copy link
Member

Reinmar commented Dec 6, 2016

Branches : 99.52% ( 413/415 )

R-.

…ion of rects which has negative width and height (disjoint rects).
@Reinmar
Copy link
Member

Reinmar commented Dec 7, 2016

Firefox doesn't have ClientRect global so the whole rect.js fails. Therefore, better use duck typing for isClientRect and isElement (in this case considering future iframe use).

@Reinmar
Copy link
Member

Reinmar commented Dec 7, 2016

Actually, we should have isElement and isRange in utils/dom/. I guess that the sufficient way to check whether something is an element is to check that it's an object and its nodeType == Node.ELEMENT. isRange should also avoid doing instanceof check, so perhaps Object.prototype.toString.apply( range ) == '[object Range]' would be sufficient.

/**
* Element that is to be positioned.
*
* @member {HTMLElement} module:utils/dom/position~Options#element
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to specify the whole path. Just the #element should be fine (but please do check).

*
* @property {Number} top Top position offset.
* @property {Number} left Left position offset.
* @property {String} name Name of the position.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And that's what?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Positions are named. This is useful because as the getOptimalPosition util selects the best position, some changes to the DOM may be needed, i.e. the position needs a proper class to be displayed (like an arrow in BalloonPanelView which changes with each position).

So, in fact, the knowledge about position geometry (top, left) is not enough. We need to know, which of the positioning functions passed to https://github.com/ckeditor/ckeditor5-ui-default/blob/t/131/src/balloonpanel/balloonpanelview.js#L145-L150 has been chosen.

That's why positioning functions are named, like https://github.com/ckeditor/ckeditor5-ui-default/blob/t/131/src/balloonpanel/balloonpanelview.js#L207-L211.


TBH, I don't like it either but I couldn't find any other way to simplify this API. I mean, to pass a number of functions, get the output data out of one of them (the best one) and to know precisely which function returned this output data. Ideas?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that, I didn't mean that it's wrong. I think we can live with it (TBH, I don't have energy to try to find a better solution because this one isn't that bad :D). I just wanted this to be better documented. A single example in this module would do enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the only place where position names look odd is https://github.com/ckeditor/ckeditor5-ui-default/blob/t/131/src/balloonpanel/balloonpanelview.js#L207. But it's reasonable there too. You can both, access the returned value satisfy the interface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually 2, you could mention there that these functions returns objects implementing this specific interface, just to make it clear.

* TODO: more docs and example.
*
* @param {module:utils/dom/position~Options} options Positioning options object.
* @returns {Object} An object containing CSS `top`, `left` coordinates ready to use with `position: absolute` and the `name`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So isn't the type Position?

/**
* Creates an instance of rect.
*
* // Rect of an HTMLElement.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something broke here with indentation.

@Reinmar Reinmar merged commit 5fe2e93 into master Dec 8, 2016
@Reinmar Reinmar deleted the t/105 branch December 8, 2016 12:18
@Reinmar
Copy link
Member

Reinmar commented Dec 8, 2016

Great job. I really like the new utils!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants