Changeset 2098

Show
Ignore:
Timestamp:
2008-06-20 00:48:29 (7 months ago)
Author:
fredck
Message:

Introduced the on-demand loading.
Introduced the plugin system.

Location:
CKEditor/branches/prototype
Files:
3 added
2 removed
12 modified

Legend:

Unmodified
Added
Removed
  • CKEditor/branches/prototype/ckeditor.js

    r2083 r2098  
    2323if (!window.CKEDITOR){window.CKEDITOR=(function(){return {status:'unloaded',basePath:(function(){var A='';var B=document.getElementsByTagName('script');for (var i=0;i<B.length;i++){var C=B[i].src.match(/(^|.*[\\\/])ckeditor(?:_basic)?.js(?:\?.*)?$/i);if (C){A=C[1];break;}};if (A.indexOf('://')==-1){if (A.indexOf('/')==0) A=location.href.match(/^.*?:\/\/[^\/]*/)[0]+A;else A=location.href.match(/^[^\?]*\//)[0]+A;};return A;})()};})();}; 
    2424 
    25 // Set the script name to be loaded by the loader. 
    26 CKEDITOR._autoLoad = 'core/ckeditor'; 
     25if ( CKEDITOR.loader ) 
     26        CKEDITOR.loader.load( 'core/ckeditor' ); 
     27else 
     28{ 
     29        // Set the script name to be loaded by the loader. 
     30        CKEDITOR._autoLoad = 'core/ckeditor'; 
    2731 
    28 // Include the loader script. 
    29 document.write( 
    30         '<script type="text/javascript" src="' + CKEDITOR.basePath + '_source/core/loader.js"></script>' ); 
     32        // Include the loader script. 
     33        document.write( 
     34                '<script type="text/javascript" src="' + CKEDITOR.basePath + '_source/core/loader.js"></script>' ); 
     35} 
  • CKEditor/branches/prototype/config.js

    r2083 r2098  
    1 /* 
     1/* 
    22 * CKEditor - The text editor for Internet - http://ckeditor.com 
    33 * Copyright (C) 2003-2008 Frederico Caldeira Knabben 
  • CKEditor/branches/prototype/_source/core/_bootstrap.js

    r2083 r2098  
    2020 */ 
    2121 
    22 (function() 
    23 { 
    24         // Process all pending replacements. 
    25         var pending = CKEDITOR.replace._pending; 
    26         if ( pending ) 
     22// Load core plugins. 
     23CKEDITOR.plugins.load( CKEDITOR.config.corePlugins.split( ',' ), function() 
    2724        { 
    28                 delete CKEDITOR.replace._pending; 
     25                // Process all pending <textarea> replacements. 
     26                var pending = CKEDITOR.replace._pending; 
     27                if ( pending ) 
     28                { 
     29                        delete CKEDITOR.replace._pending; 
    2930 
    30                 CKEDITOR.tools.each( pending, function() 
    31                         { 
    32                                 CKEDITOR.replace( this[0], this[1] ); 
    33                         } ); 
    34         } 
    35 })(); 
     31                        CKEDITOR.tools.each( pending, function( replaceInfo ) 
     32                                { 
     33                                        // replaceInfo[0] == <textarea> DOM element 
     34                                        // replaceInfo[1] == in-page configurations object 
     35                                        CKEDITOR.replace( replaceInfo[0], replaceInfo[1] ); 
     36                                } ); 
     37                } 
     38        }); 
  • CKEditor/branches/prototype/_source/core/ckeditor_base.js

    r2083 r2098  
    4646                         *                      <li><b>unloaded</b>: the API is not yet loaded.</li> 
    4747                         *                      <li><b>basic_loaded</b>: the basic API features are available.</li> 
     48                         *                      <li><b>basic_ready</b>: the basic API is ready to load the full core code.</li> 
    4849                         *                      <li><b>loading</b>: the full API is being loaded.</li> 
    4950                         *                      <li><b>ready</b>: the API can be fully used.</li> 
  • CKEditor/branches/prototype/_source/core/ckeditor_basic.js

    r2090 r2098  
    2121 
    2222CKEDITOR.event.implementOn( CKEDITOR ); 
     23 
     24CKEDITOR.loadFullCore = function() 
     25{ 
     26        delete CKEDITOR.loadFullCore; 
     27 
     28        var script = document.createElement( 'script' ); 
     29        script.type = 'text/javascript'; 
     30        script.src = CKEDITOR.basePath + 'ckeditor.js'; 
     31         
     32        document.getElementsByTagName( 'head' )[0].appendChild( script );        
     33}; 
    2334 
    2435/** 
     
    100111        var pending = CKEDITOR.replace._pending || ( CKEDITOR.replace._pending = [] ); 
    101112        pending.push( [ textarea, config ] ); 
     113 
     114        // Check if it is time to load the full core code. 
     115        if ( CKEDITOR.loadFullCore && CKEDITOR.status == 'basic_ready' ) 
     116                CKEDITOR.loadFullCore(); 
    102117}; 
    103118 
     
    176191                        if ( CKEDITOR.replaceByClassEnabled ) 
    177192                                CKEDITOR.replaceAll( CKEDITOR.replaceClass ); 
     193 
     194                        if ( CKEDITOR.replace._pending && CKEDITOR.status == 'basic_loaded' && CKEDITOR.loadFullCore ) 
     195                                CKEDITOR.loadFullCore(); 
     196 
     197                        CKEDITOR.status = 'basic_ready'; 
    178198                }; 
    179199 
  • CKEditor/branches/prototype/_source/core/ckeditor.js

    r2091 r2098  
    2020 */ 
    2121 
     22// Remove the CKEDITOR.loadFullCore reference defined on ckeditor_basic. 
     23delete CKEDITOR.loadFullCore; 
     24 
    2225CKEDITOR.instances = {}; 
    2326 
     
    2831        // instance. 
    2932        textarea = new CKEDITOR.dom.element( textarea ); 
    30          
     33 
    3134        // Create the editor instance. 
    3235        CKEDITOR.add( new CKEDITOR.editor( textarea, config ) ); 
  • CKEditor/branches/prototype/_source/core/config.js

    r2083 r2098  
    3939        baseHref : '', 
    4040 
     41        corePlugins : '', 
     42 
     43        plugins : '', 
     44 
    4145        /** 
    4246         * The theme to be used to build the UI. 
  • CKEditor/branches/prototype/_source/core/dom/element.js

    r2093 r2098  
    5454                element.append( this ); 
    5555        }, 
     56         
     57        insertAfter : function( element ) 
     58        { 
     59                element.$.parentNode.insertBefore( this.$, element.$.nextSibling ); 
     60        }, 
     61 
     62        insertBefore : function( element ) 
     63        { 
     64                element.$.parentNode.insertBefore( this.$, element.$ ); 
     65        }, 
    5666 
    5767        appendText : function( text ) 
     
    6373        { 
    6474                this.$.text = text; 
     75        }, 
     76 
     77        setHtml : function( html ) 
     78        { 
     79                this.$.innerHTML = html; 
    6580        }, 
    6681 
  • CKEditor/branches/prototype/_source/core/editor.js

    r2091 r2098  
    3636                return CKEDITOR.instances[ name ] ? getNewName() : name; 
    3737        }; 
     38         
     39        // ##### START: Config Privates 
    3840 
    3941        // These function loads custom configuration files and cache the 
     
    104106 
    105107                                // Fire the "configloaded" event. 
    106                                 editor.fire( 'configloaded' ); 
     108                                editor.fireOnce( 'configloaded' ); 
     109                                 
     110                                // Start loading the plugins. 
     111                                loadPlugins( editor ); 
    107112                        }); 
    108113 
     
    121126        {} 
    122127        config.prototype = CKEDITOR.config; 
     128 
     129        // ##### END: Config Privates 
     130 
     131        var loadPlugins = function( editor ) 
     132        { 
     133                // Load all plugins defined in the "plugins" setting. 
     134                CKEDITOR.plugins.load( editor.config.plugins.split( ',' ), function( plugins ) 
     135                        { 
     136                                // Cache the loaded plugin names. 
     137                                editor.plugins = plugins; 
     138                                 
     139                                // Initialize all plugins that have the "init" method defined. 
     140                                CKEDITOR.tools.each( plugins, function( plugin ) 
     141                                        { 
     142                                                var plugin = CKEDITOR.plugins.get( plugin ); 
     143                                                if ( plugin && plugin.init ) 
     144                                                        plugin.init( editor ); 
     145                                        }); 
     146                        }); 
     147        }; 
    123148 
    124149        return function( element, instanceConfig ) 
  • CKEditor/branches/prototype/_source/core/loader.js

    r2083 r2098  
    3333        var scripts = 
    3434        { 
    35                 'core/_bootstrap'               : [ 'core/config', 'core/ckeditor', 'core/scriptLoader', 'core/tools' ], 
     35                'core/_bootstrap'               : [ 'core/config', 'core/ckeditor', 'core/plugins', 'core/scriptLoader', 'core/tools' ], 
    3636                'core/ajax'                             : [ 'core/xml' ], 
    3737                'core/ckeditor'                 : [ 'core/ajax', 'core/ckeditor_basic', 'core/dom', 'core/editor', 'core/dom/element', 'core/event', 'core/tools' ], 
     
    4444                'core/env'                              : [], 
    4545                'core/event'                    : [], 
     46                'core/plugins'                  : [ 'core/scriptLoader', 'core/tools' ], 
    4647                'core/scriptLoader'             : [ 'core/dom/element', 'core/env' ], 
    4748                'core/tools'                    : [ 'core/env' ], 
     
    118119                        this.loadedScripts.push( scriptName ); 
    119120 
     121                        var scriptSrc = this.basePath + '_source/' + scriptName + '.js'; 
     122 
    120123                        // Append the <script> element to the DOM. 
    121                         document.write( '<script src="' + this.basePath + '_source/' + scriptName + '.js" type="text/javascript"><\/script>' ); 
     124                        if ( document.body ) 
     125                        { 
     126                                var script = document.createElement( 'script' ); 
     127                                script.type = 'text/javascript'; 
     128                                script.src = scriptSrc; 
     129                                 
     130                                document.body.appendChild( script );     
     131                        } 
     132                        else 
     133                                document.write( '<script src="' + scriptSrc + '" type="text/javascript"><\/script>' ); 
    122134                } 
    123135        }; 
  • CKEditor/branches/prototype/_source/core/scriptloader.js

    r2083 r2098  
    5050                                if ( CKEDITOR.env.ie ) 
    5151                                { 
     52                                        // FIXME: For IE, we are not able to return false on error (like 404). 
     53 
    5254                                        script.$.onreadystatechange = function () 
    5355                                        { 
    5456                                                if ( script.$.readyState == 'loaded' || script.$.readyState == 'complete' ) 
    55                                                         callback.call( scope || CKEDITOR ); 
     57                                                { 
     58                                                        script.$.onreadystatechange = null; 
     59                                                        callback.call( scope || CKEDITOR, true ); 
     60                                                } 
    5661                                        } 
    5762                                } 
     
    6065                                        script.$.onload = function() 
    6166                                        { 
    62                                                 callback.call( scope || CKEDITOR ); 
     67                                                callback.call( scope || CKEDITOR, true ); 
     68                                        } 
     69 
     70                                        // FIXME: Opera and Safari will not fire onerror. 
     71 
     72                                        script.$.onerror = function() 
     73                                        { 
     74                                                callback.call( scope || CKEDITOR, false ); 
    6375                                        } 
    6476                                } 
  • CKEditor/branches/prototype/_source/core/tools.js

    r2083 r2098  
    123123                        {} 
    124124                } 
     125        }, 
     126         
     127        isArray : function( object ) 
     128        { 
     129                return ( object && object instanceof Array ); 
    125130        } 
    126131};