2011-03-14 17:14:20 -04:00
|
|
|
/*
|
|
|
|
* Paper.js
|
|
|
|
*
|
|
|
|
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
|
|
|
* based on Scriptographer.org and designed to be largely API compatible.
|
|
|
|
* http://paperjs.org/
|
|
|
|
* http://scriptographer.org/
|
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var Element = {
|
|
|
|
getOffset: function(el) {
|
|
|
|
var x = 0, y = 0;
|
|
|
|
while (el) {
|
|
|
|
x += el.offsetLeft;
|
|
|
|
y += el.offsetTop;
|
|
|
|
el = el.offsetParent;
|
|
|
|
}
|
|
|
|
return Point.create(x, y);
|
|
|
|
},
|
|
|
|
|
|
|
|
getSize: function(el) {
|
|
|
|
return Size.create(el.offsetWidth, el.offsetHeight);
|
|
|
|
},
|
|
|
|
|
|
|
|
getBounds: function(el) {
|
|
|
|
return new Rectangle(Element.getOffset(el), Element.getSize(el));
|
|
|
|
},
|
|
|
|
|
2011-03-14 17:37:31 -04:00
|
|
|
getScrollBounds: function() {
|
2011-03-14 17:14:20 -04:00
|
|
|
var doc = document.getElementsByTagName(
|
2011-04-28 08:23:17 -04:00
|
|
|
document.compatMode === 'CSS1Compat' ? 'html' : 'body')[0];
|
2011-03-14 17:14:20 -04:00
|
|
|
return Rectangle.create(
|
|
|
|
window.pageXOffset || doc.scrollLeft,
|
|
|
|
window.pageYOffset || doc.scrollTop,
|
|
|
|
window.innerWidth || doc.clientWidth,
|
|
|
|
window.innerHeight || doc.clientHeight
|
2011-03-14 17:37:31 -04:00
|
|
|
);
|
2011-03-15 07:30:44 -04:00
|
|
|
},
|
2011-03-14 17:37:31 -04:00
|
|
|
|
|
|
|
// Checks if element is visibile in current viewport
|
|
|
|
isVisible: function(el) {
|
|
|
|
// See if the two rectangle intersect
|
|
|
|
return Element.getScrollBounds().intersects(Element.getBounds(el));
|
2011-03-14 17:14:20 -04:00
|
|
|
}
|
|
|
|
};
|