1 /* 2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 /** 7 * @fileOverview Defines the {@link CKEDITOR.dom.document} class, which 8 * represents a DOM document. 9 */ 10 11 /** 12 * Represents a DOM window. 13 * @constructor 14 * @augments CKEDITOR.dom.domObject 15 * @param {Object} domWindow A native DOM window. 16 * @example 17 * var document = new CKEDITOR.dom.window( window ); 18 */ 19 CKEDITOR.dom.window = function( domWindow ) 20 { 21 CKEDITOR.dom.domObject.call( this, domWindow ); 22 }; 23 24 CKEDITOR.dom.window.prototype = new CKEDITOR.dom.domObject(); 25 26 CKEDITOR.tools.extend( CKEDITOR.dom.window.prototype, 27 /** @lends CKEDITOR.dom.window.prototype */ 28 { 29 /** 30 * Moves the selection focus to this window. 31 * @function 32 * @example 33 * var win = new CKEDITOR.dom.window( window ); 34 * <b>win.focus()</b>; 35 */ 36 focus : function() 37 { 38 this.$.focus(); 39 }, 40 41 /** 42 * Gets the width and height of this window's viewable area. 43 * @function 44 * @returns {Object} An object with the "width" and "height" 45 * properties containing the size. 46 * @example 47 * var win = new CKEDITOR.dom.window( window ); 48 * var size = <b>win.getViewPaneSize()</b>; 49 * alert( size.width ); 50 * alert( size.height ); 51 */ 52 getViewPaneSize : function() 53 { 54 var doc = this.$.document, 55 stdMode = doc.compatMode == 'CSS1Compat'; 56 return { 57 width : ( stdMode ? doc.documentElement.clientWidth : doc.body.clientWidth ) || 0, 58 height : ( stdMode ? doc.documentElement.clientHeight : doc.body.clientHeight ) || 0 59 }; 60 }, 61 62 /** 63 * Gets the current position of the window's scroll. 64 * @function 65 * @returns {Object} An object with the "x" and "y" properties 66 * containing the scroll position. 67 * @example 68 * var win = new CKEDITOR.dom.window( window ); 69 * var pos = <b>win.getScrollPosition()</b>; 70 * alert( pos.x ); 71 * alert( pos.y ); 72 */ 73 getScrollPosition : function() 74 { 75 var $ = this.$; 76 77 if ( 'pageXOffset' in $ ) 78 { 79 return { 80 x : $.pageXOffset || 0, 81 y : $.pageYOffset || 0 82 }; 83 } 84 else 85 { 86 var doc = $.document; 87 return { 88 x : doc.documentElement.scrollLeft || doc.body.scrollLeft || 0, 89 y : doc.documentElement.scrollTop || doc.body.scrollTop || 0 90 }; 91 } 92 } 93 }); 94