Rename 'Window' in DomElement to 'Viewport', and have getViewportSize return the size of the viewport the passed element is contained in.

This commit is contained in:
Jürg Lehni 2011-06-26 10:14:26 +02:00
parent d4b6d14f36
commit f18b5df99d
2 changed files with 18 additions and 16 deletions

View file

@ -41,15 +41,26 @@ var DomElement = new function() {
}
return {
getWindow: function(doc) {
getViewport: function(doc) {
return doc.defaultView || doc.parentWindow;
},
getViewportSize: function(el) {
var doc = el.ownerDocument,
view = DomElement.getViewport(doc),
body = doc.getElementsByTagName(
doc.compatMode === 'CSS1Compat' ? 'html' : 'body')[0];
return Size.create(
view.innerWidth || body.clientWidth,
view.innerHeight || body.clientHeight
);
},
getComputedStyle: function(el, name) {
if (el.currentStyle)
return el.currentStyle[Base.camelize(name)];
var style = DomElement.getWindow(el.ownerDocument).getComputedStyle(
el, null);
var style = DomElement.getViewport(el.ownerDocument)
.getComputedStyle(el, null);
return style ? style.getPropertyValue(Base.hyphenate(name)) : null;
},
@ -77,15 +88,6 @@ var DomElement = new function() {
DomElement.getSize(el));
},
getWindowSize: function() {
var doc = document.getElementsByTagName(
document.compatMode === 'CSS1Compat' ? 'html' : 'body')[0];
return Size.create(
window.innerWidth || doc.clientWidth,
window.innerHeight || doc.clientHeight
);
},
/**
* Checks if element is invisibile (display: none, ...)
*/
@ -100,7 +102,7 @@ var DomElement = new function() {
// See if the viewport bounds intersect with the windows rectangle
// which always starts at 0, 0
return !DomElement.isInvisible(el)
&& new Rectangle([0, 0], DomElement.getWindowSize())
&& new Rectangle([0, 0], DomElement.getViewportSize(el))
.intersects(DomElement.getBounds(el, false, true));
}
};

View file

@ -40,7 +40,7 @@ var View = this.View = Base.extend(/** @lends View# */{
// stretch it in
var offset = DomElement.getOffset(canvas, false, true),
that = this;
size = DomElement.getWindowSize().subtract(offset);
size = DomElement.getViewportSize(canvas).subtract(offset);
canvas.width = size.width;
canvas.height = size.height;
DomEvent.add(window, {
@ -50,8 +50,8 @@ var View = this.View = Base.extend(/** @lends View# */{
if (!DomElement.isInvisible(canvas))
offset = DomElement.getOffset(canvas, false, true);
// Set the size now, which internally calls onResize
that.setViewSize(
DomElement.getWindowSize().subtract(offset));
that.setViewSize(DomElement.getViewportSize(canvas)
.subtract(offset));
// If there's a _onFrameCallback, call it staight away,
// but without requesting another animation frame.
if (that._onFrameCallback) {