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