-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added deprecation warning for old offset syntax, and a test for backw…
…ards compatibility
- Loading branch information
Showing
3 changed files
with
78 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Tell whether the rect is visible, given an offset | ||
// | ||
// return: boolean | ||
module.exports = function (offset, rect, containmentRect) { | ||
var offsetDir = offset.direction; | ||
var offsetVal = offset.value; | ||
|
||
// Rules for checking different kind of offsets. In example if the element is | ||
// 90px below viewport and offsetTop is 100, it is considered visible. | ||
switch (offsetDir) { | ||
case 'top': | ||
return ((containmentRect.top + offsetVal) < rect.top) && | ||
(containmentRect.bottom > rect.bottom) && | ||
(containmentRect.left < rect.left) && | ||
(containmentRect.right > rect.right); | ||
|
||
case 'left': | ||
return ((containmentRect.left + offsetVal) < rect.left) && | ||
(containmentRect.bottom > rect.bottom) && | ||
(containmentRect.top < rect.top) && | ||
(containmentRect.right > rect.right); | ||
|
||
case 'bottom': | ||
return ((containmentRect.bottom - offsetVal) > rect.bottom) && | ||
(containmentRect.left < rect.left) && | ||
(containmentRect.right > rect.right) && | ||
(containmentRect.top < rect.top); | ||
|
||
case 'right': | ||
return ((containmentRect.right - offsetVal) > rect.right) && | ||
(containmentRect.left < rect.left) && | ||
(containmentRect.top < rect.top) && | ||
(containmentRect.bottom > rect.bottom); | ||
} | ||
} |
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