Ticket #5774: 5774.patch

File 5774.patch, 5.1 KB (added by Garry Yao, 13 years ago)
  • _source/core/dom/domobject.js

     
    88 *              for other classes representing DOM objects.
    99 */
    1010
    11 /**
    12  * Represents a DOM object. This class is not intended to be used directly. It
    13  * serves as the base class for other classes representing specific DOM
    14  * objects.
    15  * @constructor
    16  * @param {Object} nativeDomObject A native DOM object.
    17  * @augments CKEDITOR.event
    18  * @example
    19  */
    20 CKEDITOR.dom.domObject = function( nativeDomObject )
    21 {
    22         if ( nativeDomObject )
    23         {
    24                 /**
    25                  * The native DOM object represented by this class instance.
    26                  * @type Object
    27                  * @example
    28                  * var element = new CKEDITOR.dom.element( 'span' );
    29                  * alert( element.$.nodeType );  // "1"
    30                  */
    31                 this.$ = nativeDomObject;
    32         }
    33 };
     11( function()
     12{
     13        // Prevent IE6 from leaking in-page elements, we have to break
     14        // references to native DOM elements.
     15        if ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 )
     16        {
     17                var domObjects = [];
     18                CKEDITOR.on( 'reset', function()
     19                {
     20                        for ( var i = 0, length = domObjects.length; i < length; i++ )
     21                                delete domObjects[ i ].$;
     22                });
     23        }
     24
     25        /**
     26         * Represents a DOM object. This class is not intended to be used directly. It
     27         * serves as the base class for other classes representing specific DOM
     28         * objects.
     29         * @constructor
     30         * @param {Object} nativeDomObject A native DOM object.
     31         * @augments CKEDITOR.event
     32         * @example
     33         */
     34        CKEDITOR.dom.domObject = function( nativeDomObject )
     35        {
     36                if ( nativeDomObject )
     37                {
     38                        /**
     39                         * The native DOM object represented by this class instance.
     40                         * @type Object
     41                         * @example
     42                         * var element = new CKEDITOR.dom.element( 'span' );
     43                         * alert( element.$.nodeType );  // "1"
     44                         */
     45                        this.$ = nativeDomObject;
     46                        if ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 )
     47                                domObjects.push( this );
     48                }
     49        };
    3450
     51} )();
     52
    3553CKEDITOR.dom.domObject.prototype = (function()
    3654{
    3755        // Do not define other local variables here. We want to keep the native
  • _source/core/ckeditor_basic.js

     
    232232                                }
    233233                        };
    234234
     235                        function unload()
     236                        {
     237                                // Allow page-off cleanup to happen,
     238                                // mainly for protect memory leaks.
     239                                CKEDITOR.fire( 'reset' );
     240
     241                                // Detach unload function
     242                                if ( window.detachEvent )
     243                                {
     244                                        window.detachEvent( 'onbeforeunload', beforeUnload );
     245                                        window.detachEvent( 'onunload', unload );
     246                                } else if ( window.removeEventListener )
     247                                        window.removeEventListener( 'unload', unload, false );
     248
     249                                // Destroy references
     250                                unload = null;
     251                        }
     252
     253                        function beforeUnload()
     254                        {
     255                                var doc = document;
     256
     257                                // The document may still in loading,
     258                                //  in this case the 'unload' even won't fire at all,
     259                                // we have look to for the 'stop' event instead.
     260                                if ( doc.readyState == 'interactive' )
     261                                {
     262                                        function stop()
     263                                        {
     264                                                // Prevent memory leak
     265                                                doc.detachEvent( 'onstop', stop );
     266
     267                                                // Call unload handler
     268                                                if ( unload )
     269                                                        unload();
     270
     271                                                doc = null;
     272                                        }
     273
     274                                        // Fire unload when the currently loading page is stopped
     275                                        if ( doc )
     276                                                doc.attachEvent( 'onstop', stop );
     277
     278                                        // Remove onstop listener after a while to prevent the unload function
     279                                        // to execute if the user presses cancel in an onbeforeunload
     280                                        // confirm dialog and then presses the browser stop button
     281                                        window.setTimeout( function()
     282                                        {
     283                                                if ( doc )
     284                                                        doc.detachEvent( 'onstop', stop );
     285                                        }, 0 );
     286                                }
     287                        }
     288
    235289                        if ( window.addEventListener )
    236290                                window.addEventListener( 'load', onload, false );
    237291                        else if ( window.attachEvent )
    238292                                window.attachEvent( 'onload', onload );
     293
     294                        if ( window.attachEvent )
     295                        {
     296                                window.attachEvent( 'onunload', unload );
     297                                window.attachEvent( 'onbeforeunload', beforeUnload );
     298                        }
     299                        else if ( window.addEventListener )
     300                                window.addEventListener( 'unload', unload, false );
     301
    239302                })();
    240303
    241304                CKEDITOR.status = 'basic_loaded';
  • _source/core/dom/document.js

     
    164164                 */
    165165                getHead : function()
    166166                {
    167                         var head = this.$.getElementsByTagName( 'head' )[0];
    168                         head = new CKEDITOR.dom.element( head );
    169 
    170                         return (
    171                         this.getHead = function()
    172                                 {
    173                                         return head;
    174                                 })();
     167                        return this.getElementsByTag( 'head' ).getItem( 0 );
    175168                },
    176169
    177170                /**
     
    183176                 */
    184177                getBody : function()
    185178                {
    186                         var body = new CKEDITOR.dom.element( this.$.body );
    187 
    188                         return (
    189                         this.getBody = function()
    190                                 {
    191                                         return body;
    192                                 })();
     179                        return new CKEDITOR.dom.element( this.$.body );
    193180                },
    194181
    195182                /**
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy