Ticket #3148: 3148_2.patch

File 3148_2.patch, 4.8 KB (added by Garry Yao, 15 years ago)
  • _source/tests/core/plugins.html

     
     1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2<html xmlns="http://www.w3.org/1999/xhtml">
     3<head>
     4        <title>CKEDITOR.plugins</title>
     5        <link rel="stylesheet" type="text/css" href="../test.css" />
     6        <script type="text/javascript" src="../../../ckeditor_source.js"></script> <!-- %REMOVE_LINE%
     7        <script type="text/javascript" src="../../ckeditor.js"></script>
     8        %REMOVE_LINE% -->
     9        <script type="text/javascript" src="../test.js"></script>
     10        <script type="text/javascript">
     11        //<![CDATA[
     12
     13CKEDITOR.test.addTestCase( (function()
     14{
     15        // Local reference to the "assert" object.
     16        var assert = CKEDITOR.test.assert;
     17       
     18        return {
     19
     20                /**
     21                 * Test loading self defined external plugin file paths.
     22                 */
     23                test_addExternal : function()
     24                {
     25                        CKEDITOR.plugins.addExternal( 'myplugin',
     26                        '_source/' + // %REMOVE_LINE%
     27                        'tests/core/plugins/myplugins/sample/', 'my_plugin.js' );
     28                       
     29                        CKEDITOR.plugins.load( 'myplugin', function(){
     30                                this.resume( function(){
     31                                       
     32                                        assert.isTrue( CKEDITOR.plugins.get( 'myplugin' ).definition );
     33                                } );                           
     34                        }, this );
     35                        this.wait();
     36                },
     37
     38                name : document.title
     39        };
     40})() );
     41
     42        //]]>
     43        </script>
     44</head>
     45<body>
     46</body>
     47</html>
  • _source/tests/core/plugins/myplugins/sample/my_plugin.js

     
     1CKEDITOR.plugins.add( 'myplugin' , {
     2        definition :  true
     3} );
  • _source/core/resourcemanager.js

     
    102102        },
    103103
    104104        /**
    105          * Get the full path for a specific loaded resource.
     105         * Get the folder path for a specific loaded resource.
    106106         * @param {String} name The resource name.
    107107         * @type String
    108108         * @example
     
    110110         */
    111111        getPath : function( name )
    112112        {
    113                 return this.externals[ name ] || this.basePath + name + '/';
     113                var external = this.externals[ name ]
     114                return CKEDITOR.getUrl( ( external && external.dir ) || this.basePath + name + '/' );
     115        },
     116
     117        /**
     118         * Get the file path for a specific loaded resource.
     119         * @param {String} name The resource name.
     120         * @type String
     121         * @example
     122         * alert( <b>CKEDITOR.plugins.getFilePath( 'sample' )</b> );  // "&lt;editor path&gt;/plugins/sample/plugin.js"
     123         */
     124        getFilePath : function( name )
     125        {
     126                var external = this.externals[ name ]
     127                return CKEDITOR.getUrl(
     128                                this.getPath( name ) +
     129                                ( ( external && external.file ) || ( this.fileName + '.js' ) ) );
    114130        },
    115131
    116132        /**
    117          * Registers a resource to be loaded from an external path instead of the core base path.
     133         * Registers one or more resources to be loaded from an external path
     134         * instead of the core base path.
    118135         * @param {String} names The resource names, separated by commas.
    119          * @param {String} path The resource external path.
     136         * @param {String} path The path of the folder containing the resource.
     137         * @param {String} [fileName] The resource file name. If not provided, the
     138         *              default name is used.
    120139         * @example
    121140         * // Loads a plugin from '/myplugin/samples/plugin.js'.
    122141         * CKEDITOR.plugins.addExternal( 'sample', '/myplugins/sample/' );
     142         * @example
     143         * // Loads a plugin from '/myplugin/samples/my_plugin.js'.
     144         * CKEDITOR.plugins.addExternal( 'sample', '/myplugins/sample/', 'my_plugin.js' );
    123145         */
    124         addExternal : function( names, path )
     146        addExternal : function( names, path, fileName )
    125147        {
    126148                names = names.split( ',' );
    127149                for ( var i = 0 ; i < names.length ; i++ )
     
    127149                for ( var i = 0 ; i < names.length ; i++ )
    128150                {
    129151                        var name = names[ i ];
    130                         if ( this.registered[ name ] || this.externals[ name ] )
    131                                 throw '[CKEDITOR.resourceManager.import] The resource name "' + name + '" is already registered or imported.';
    132152
    133                         this.externals[ name ] = path;
     153                        this.externals[ name ] =
     154                        {
     155                                dir : path,
     156                                file : fileName
     157                        };
    134158                }
    135159        },
    136160
     
    172196                        // If not available yet.
    173197                        if ( !loaded[ name ] && !registered[ name ] )
    174198                        {
    175                                 var url = CKEDITOR.getUrl( this.getPath( name ) + this.fileName + '.js' );
     199                                var url = this.getFilePath( name );
    176200                                urls.push( url );
    177201                                if ( !( url in urlsNames ) )
    178202                                        urlsNames[ url ] = [];
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy