1/** 2 * Taken from "Javascript The Definitive Guide, 5th Edition" by David Flanagan 3 * www.DavidFlanagan.com/javascript5 4 * (Section 14-2) 5 * [Heavily Modified] 6 * 7 * Geometry.js: portable functions for querying window and document geometry 8 * 9 * This module defines functions for querying window and document geometry. 10 * 11 * getWindowX/Y(): return the position of the window on the screen 12 * getViewportWidth/Height(): return the size of the browser viewport area 13 * getDocumentWidth/Height(): return the size of the document. 14 * getHorizontalScroll(): return the position of the horizontal scrollbar 15 * getVerticalScroll(): return the position of the vertical scrollbar 16 * 17 * Note that there is no portable way to query the overall size of the 18 * browser window, so there are no getWindowWidth/Height() functions. 19 * 20 */ 21var Geometry = {}; 22 23Geometry.initialize = function() 24{ 25 26 if (window.screenLeft) 27 { 28 // IE and others 29 Geometry.getWindowX = function() { return window.screenLeft; }; 30 Geometry.getWindowY = function() { return window.screenTop; }; 31 } 32 else if (window.screenX) 33 { 34 // Firefox and others 35 Geometry.getWindowX = function() { return window.screenX; }; 36 Geometry.getWindowY = function() { return window.screenY; }; 37 } 38 39 if (window.innerWidth) 40 { 41 // All browsers but IE 42 Geometry.getViewportWidth = function() { return window.innerWidth; }; 43 Geometry.getViewportHeight = function() { return window.innerHeight; }; 44 Geometry.getHorizontalScroll = function() { return window.pageXOffset; }; 45 Geometry.getVerticalScroll = function() { return window.pageYOffset; }; 46 } 47 else if (document.documentElement && document.documentElement.clientWidth) 48 { 49 // These functions are for IE6 when there is a DOCTYPE 50 Geometry.getViewportWidth = 51 function() { return document.documentElement.clientWidth; }; 52 Geometry.getViewportHeight = 53 function() { return document.documentElement.clientHeight; }; 54 Geometry.getHorizontalScroll = 55 function() { return document.documentElement.scrollLeft; }; 56 Geometry.getVerticalScroll = 57 function() { return document.documentElement.scrollTop; }; 58 } 59 else if (document.body.clientWidth) 60 {
61 // These are for IE4, IE5, and IE6 without a DOCTYPE 62 Geometry.getViewportWidth = 63 function() { return document.body.clientWidth; }; 64 Geometry.getViewportHeight = 65 function() { return document.body.clientHeight; }; 66 Geometry.getHorizontalScroll = 67 function() { return document.body.scrollLeft; }; 68 Geometry.getVerticalScroll = 69 function() { return document.body.scrollTop; }; 70 } 71 72 // These functions return the size of the document. They are not window 73 // related, but they are useful to have here anyway. 74 if (window.innerHeight && window.scrollMaxY) 75 { 76 // *added* emw 2009-12-03 77 Geometry.getDocumentWidth = 78 function() { return document.body.scrollWidth; }; 79 Geometry.getDocumentHeight = 80 function() { return window.innerHeight + window.scrollMaxY; }; 81 } 82 else if (document.body.scrollWidth) 83 { 84 Geometry.getDocumentWidth = 85 function() { return document.body.scrollWidth; }; 86 Geometry.getDocumentHeight = 87 function() { return document.body.scrollHeight; }; 88 } 89 else if (document.documentElement && document.documentElement.scrollWidth) 90 { 91 Geometry.getDocumentWidth = 92 function() { return document.documentElement.scrollWidth; }; 93 Geometry.getDocumentHeight = 94 function() { return document.documentElement.scrollHeight; }; 95 } 96 else 97 { 98 // *added* emw 2009-12-03 99 // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 100 Geometry.getDocumentWidth = 101 function() { return document.body.offsetWidth; }; 102 Geometry.getDocumentHeight = 103 function() { return document.body.offsetHeight; }; 104 } 105} 106 107 108////////////////////////////////////////////////////////////////////////////////////////////////// 109// *added* emw 2009-12-03 110// Displays Geometry info for browser in which it's sometimes 111// difficult to get a hold on the DOM *coughIEcough* 112Geometry.getGeometryInfo = function() 113{ 114 var newline = '\n'; 115 var output = ''; 116 117 if (window.screenLeft) 118 { 119 // IE and others 120 output += 'window.screenLeft: ' + window.screenLeft + newline; 121 output += 'window.screenTop: ' + window.screenTop + newline; 122 } 123 if (window.screenX) 124 { 125 output += 'window.screenX: ' + window.screenX + newline; 126 output += 'window.screenY: ' + window.screenY + newline; 127 } 128 129 if (window.innerWidth) 130 { 131 output += 'window.innerWidth: ' + window.innerWidth + newline; 132 output += 'window.innerHeight: ' + window.innerHeight + newline; 133 output += 'window.pageXOffset: ' + window.pageXOffset + newline; 134 output += 'window.pageYOffset: ' + window.pageYOffset + newline; 135 } 136 if (document.documentElement && document.documentElement.clientWidth) 137 { 138 // These functions are for IE6 when there is a DOCTYPE 139 output += 'document.documentElement.clientWidth: ' + document.documentElement.clientWidth + newline; 140 output += 'document.documentElement.clientHeight: ' + document.documentElement.clientHeight + newline; 141 output += 'document.documentElement.scrollLeft: ' + document.documentElement.scrollLeft + newline; 142 output += 'document.documentElement.scrollTop: ' + document.documentElement.scrollTop + newline; 143 } 144 if (document.body.clientWidth) 145 {
146 // These are for IE4, IE5, and IE6 without a DOCTYPE 147 output += 'document.body.clientWidth: ' + document.body.clientWidth + newline; 148 output += 'document.body.clientHeight: ' + document.body.clientHeight + newline; 149 output += 'document.body.scrollLeft: ' + document.body.scrollLeft + newline; 150 output += 'document.body.scrollTop: ' + document.body.scrollTop + newline; 151 } 152 153 // These functions return the size of the document. They are not window 154 // related, but they are useful to have here anyway. 155 if (window.innerHeight && window.scrollMaxY) 156 { 157 output += 'window.innerHeight + window.scrollMaxY: ' + window.innerHeight + window.scrollMaxY + newline; 158 } 159 if (document.documentElement && document.documentElement.scrollWidth) 160 { 161 output += 'document.documentElement.scrollWidth: ' + document.documentElement.scrollWidth + newline; 162 output += 'document.documentElement.scrollHeight: ' + document.documentElement.scrollHeight + newline; 163 } 164 if (document.body.scrollWidth) 165 { 166 output += 'document.body.scrollWidth: ' + document.body.scrollWidth + newline; 167 output += 'document.body.scrollHeight: ' + document.body.scrollHeight + newline; 168 } 169 if (document.body.offsetWidth) 170 { 171 output += 'document.body.offsetWidth: ' + document.body.offsetWidth + newline; 172 output += 'document.body.offsetHeight: ' + document.body.offsetHeight + newline; 173 } 174 return output; 175}//end getGeometryInfo 176 177 178jQuery(Geometry.initialize);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.