Assembla home | Assembla project page
 

root/colbrowser/geometry.js

Revision 22, 3.4 kB (checked in by brettz9, 2 years ago)

adding back accidental deleted files!

Line 
1 // This code is from the book JavaScript: The Definitive Guide, 5th Edition,
2 // by David Flanagan. Copyright 2006 O'Reilly Media, Inc. (ISBN #0596101996)
3 // with any modifications by Brett Zamir noted by "Brett"
4 /**
5  * Geometry.js: portable functions for querying window and document geometry
6  *
7  * This module defines functions for querying window and document geometry.
8  *
9  * getWindowX/Y(): return the position of the window on the screen
10  * getViewportWidth/Height(): return the size of the browser viewport area
11  * getDocumentWidth/Height(): return the size of the document.
12  * getHorizontalScroll(): return the position of the horizontal scrollbar
13  * getVerticalScroll(): return the position of the vertical scrollbar
14  *
15  * Note that there is no portable way to query the overall size of the
16  * browser window, so there are no getWindowWidth/Height() functions.
17  *
18  * IMPORTANT: This module must be included in the <body> of a document
19  *            instead of the <head> of the document.
20  */
21 var Geometry = {};
22
23 function setGeometry() { // Brett added, so could add script tag to the head
24
25         if (window.screenLeft) { // IE and others
26             Geometry.getWindowX = function() { return window.screenLeft; };
27             Geometry.getWindowY = function() { return window.screenTop; };
28         }
29         else if (window.screenX) { // Firefox and others
30             Geometry.getWindowX = function() { return window.screenX; };
31             Geometry.getWindowY = function() { return window.screenY; };
32         }
33
34         if (window.innerWidth) { // All browsers but IE
35             Geometry.getViewportWidth = function() { return window.innerWidth; };
36             Geometry.getViewportHeight = function() { return window.innerHeight; };
37             Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
38             Geometry.getVerticalScroll = function() { return window.pageYOffset; };
39         }
40         else if (document.documentElement && document.documentElement.clientWidth) {
41             // These functions are for IE6 when there is a DOCTYPE
42             Geometry.getViewportWidth =
43                 function() { return document.documentElement.clientWidth; };
44             Geometry.getViewportHeight =
45                 function() { return document.documentElement.clientHeight; };
46             Geometry.getHorizontalScroll =
47                 function() { return document.documentElement.scrollLeft; };
48             Geometry.getVerticalScroll =
49                 function() { return document.documentElement.scrollTop; };
50         }
51         else if (document.body.clientWidth) {
52             // These are for IE4, IE5, and IE6 without a DOCTYPE
53             Geometry.getViewportWidth =
54                 function() { return document.body.clientWidth; };
55             Geometry.getViewportHeight =
56                 function() { return document.body.clientHeight; };
57             Geometry.getHorizontalScroll =
58                 function() { return document.body.scrollLeft; };
59             Geometry.getVerticalScroll =
60                 function() { return document.body.scrollTop; };
61         }
62
63         // These functions return the size of the document.  They are not window
64         // related, but they are useful to have here anyway.
65
66         if (document.documentElement && document.documentElement.scrollWidth) {
67             Geometry.getDocumentWidth =
68                 function() { return document.documentElement.scrollWidth; };
69             Geometry.getDocumentHeight =
70                 function() { return document.documentElement.scrollHeight; };
71         }
72         else if (document.body.scrollWidth) {
73                 Geometry.getDocumentWidth =
74                         function() { return document.body.scrollWidth; };
75                 Geometry.getDocumentHeight =
76                         function() { return document.body.scrollHeight; };
77         }
78 }
Note: See TracBrowser for help on using the browser.