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