-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added enyo.dom.calcViewportPositionForNode helper function #185
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
72e6599
Added enyo.dom.calcViewportPositionForNode as a helper function for l…
onecrayon 5fc8cdc
Modified viewport measuring logic to ensure that it works regardless …
onecrayon b741947
Added test suite for relative viewport position measuring method in e…
onecrayon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
enyo.kind({ | ||
name: "ViewportPositioningTest", | ||
kind: enyo.TestSuite, | ||
|
||
testMeasuringViewportCoordinates: function() { | ||
var K = enyo.kind({ | ||
kind: enyo.Control, | ||
style: "position: absolute; top: 10px; left: 10px; width: 10px; height: 10px;" | ||
}); | ||
|
||
// Similar to ControlTest, create a testing div to test DOM information with (delete at end) | ||
var div = document.createElement("div"); | ||
document.body.appendChild(div); | ||
// Apply fixed positioning so that we know where things should be relative to the viewport | ||
div.style.position = 'fixed'; | ||
div.style.top = '0px'; | ||
div.style.left = '0px'; | ||
div.style.width = '100%'; | ||
div.style.height = '100%'; | ||
|
||
var k = new K(); | ||
k.renderInto(div); | ||
|
||
var p = enyo.dom.calcViewportPositionForNode(k.hasNode()), | ||
// Bottom and right require calculating viewport size | ||
fromBottom = (document.body.parentNode.offsetHeight > enyo.dom.getWindowHeight() ? enyo.dom.getWindowHeight() - document.body.parentNode.scrollTop : document.body.parentNode.offsetHeight) - 20, | ||
fromRight = (document.body.parentNode.offsetWidth > enyo.dom.getWindowWidth() ? enyo.dom.getWindowWidth() - document.body.parentNode.scrollLeft : document.body.parentNode.offsetWidth) - 20; | ||
if (p.top !== 10) { | ||
this.log('top failed with value: ' + p.top + ' (should be 10)'); | ||
} | ||
if (p.left !== 10) { | ||
this.log('left failed with value: ' + p.left + ' (should be 10)'); | ||
} | ||
if (p.bottom !== fromBottom) { | ||
this.log('bottom measurement failed with value: ' + p.bottom + ' (should be ' + fromBottom + ')'); | ||
} | ||
if (p.right !== fromRight) { | ||
this.log('right measurement failed with value: ' + p.right + ' (should be ' + fromRight + ')'); | ||
} | ||
if (p.width !== 10) { | ||
this.log('width failed with value: ' + p.width + ' (should be 10)'); | ||
} | ||
if (p.height !== 10) { | ||
this.log('height failed with value: ' + p.height + ' (should be 10)'); | ||
} | ||
|
||
// Clean up | ||
k.destroy(); | ||
document.body.removeChild(div); | ||
|
||
this.finish(this.logMessages && this.logMessages.length ? 'Following measurements failed:' : ''); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.