Added enyo.dom.calcViewportPositionForNode helper function #185

Merged
merged 3 commits into from Dec 13, 2012

Projects

None yet

2 participants

@onecrayon

Here's my calcViewportPositionForNode addition to enyo.dom, as per the discussion here:

https://groups.google.com/d/topic/enyo-development/S-eY8HNLktU/discussion

Although my use-case for this is pretty specific to my particular app, the function seemed generically useful enough to be worth submitting to Enyo core for consideration.

@onecrayon onecrayon Added enyo.dom.calcViewportPositionForNode as a helper function for l…
…ocating nodes within the viewport (to absolutely position a floating Popup near a particular DOM element, for instance)

Enyo-DCO-1.1-Signed-off-by: Ian Beck <ian@onecrayon.com>
72e6599
@unwiredben

Any chance you want to write a test case for this to put into \enyo\tools\test\core\tests? Without it being used elsewhere in core, I'd be afraid it could break without us knowing it.

onecrayon added some commits Dec 12, 2012
@onecrayon onecrayon Modified viewport measuring logic to ensure that it works regardless …
…of whether body element is 100% height/width or has margins

Added enyo.dom.getWindowHeight to compliment getWindowWidth
Enyo-DCO-1.1-Signed-off-by: Ian Beck <ian@onecrayon.com>
5fc8cdc
@onecrayon onecrayon Added test suite for relative viewport position measuring method in e…
…nyo.dom

Enyo-DCO-1.1-Signed-off-by: Ian Beck <ian@onecrayon.com>
b741947
@onecrayon

I totally spaced on the request for a test case for some reason, but now here it is! Good thing you had me write that, too, since it caused me to discover an oversight in the measurement logic for pages where the body is not 100% width/height without a scrollbar. :-)

@unwiredben

Yeah, I find writing tests helps me find corner cases a lot easier than just fixing a problem.

@unwiredben unwiredben merged commit 37b1a0c into enyojs:master Dec 13, 2012
@unwiredben unwiredben commented on the diff Dec 13, 2012
source/dom/dom.js
@@ -124,5 +138,38 @@ enyo.dom = {
//* Gets the calculated margin of a node.
calcMarginExtents: function(inNode) {
return this.calcBoxExtents(inNode, "margin");
+ },
+ //* Returns an object like `{top: 0, left: 0, bottom: 100, right: 100, height: 10, width: 10}` that represents the object's position within the viewport. Negative values mean part of the object is not visible.
+ calcViewportPositionForNode: function(inNode) {
+ // Parse upward and grab our positioning relative to the viewport
+ var left = top = 0,
@unwiredben
unwiredben Dec 13, 2012

just fixed a bug here in master, but wanted to point it out to you -- this doesn't declare a local variable named top, but instead uses a global named top.

@onecrayon
onecrayon Dec 13, 2012

Thanks for the FYI! I'm frankly unsure why I used that pattern at all; normally I separate everything into its own comma-delimited assignment. Good to know that the habit has a purpose behind it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment