Ticket #1617: 1617.patch

File 1617.patch, 3.5 KB (added by Frederico Caldeira Knabben, 16 years ago)

Patch

  • _whatsnew.html

     
    3737        <p>
    3838                New Features and Improvements:</p>
    3939        <ul>
    40                 <li></li>
     40                <li>JavaScript integration file:
     41                        <ul>
     42                                <li>The new "<strong>FCKeditor.ReplaceAllTextareas</strong>" function is being introduced,
     43                                        making it possible to replace many (or unknown) &lt;textarea&gt; elements in a single
     44                                        call. The replacement can be also filtered by CSS class name, or by a custom function
     45                                        evaluator.</li>
     46                                <li>It is now possible to set the default BasePath for all editor instances by setting
     47                                        <strong>FCKeditor.BasePath</strong>. This is extremely useful when working with
     48                                        the ReplaceAllTextareas function.</li>
     49                        </ul>
     50                </li>
    4151        </ul>
    4252        <p>
    4353                Fixed Bugs:</p>
  • fckeditor.js

     
    3434        this.Height                     = height                || '200' ;
    3535        this.ToolbarSet         = toolbarSet    || 'Default' ;
    3636        this.Value                      = value                 || '' ;
    37         this.BasePath           = '/fckeditor/' ;
     37        this.BasePath           = FCKeditor.BasePath ;
    3838        this.CheckBrowser       = true ;
    3939        this.DisplayErrors      = true ;
    4040
     
    4444        this.OnError            = null ;        // function( source, errorNumber, errorDescription )
    4545}
    4646
     47/**
     48 * This is the default BasePath used by all editor instances.
     49 */
     50FCKeditor.BasePath = '/fckeditor/' ;
     51
    4752FCKeditor.prototype.Version                     = '[Development]' ;
    4853FCKeditor.prototype.VersionBuild        = '[DEV]' ;
    4954
     
    185190        return text ;
    186191}
    187192
     193/**
     194 * Replace all <textarea> elements available in the document with FCKeditor
     195 * instances.
     196 *
     197 *      // Replace all <textarea> elements in the page.
     198 *      FCKeditor.ReplaceAllTextareas() ;
     199 *
     200 *      // Replace all <textarea class="myClassName"> elements in the page.
     201 *      FCKeditor.ReplaceAllTextareas( 'myClassName' ) ;
     202 *
     203 *      // Selectively replace <textarea> elements, based on custom assertions.
     204 *      FCKeditor.ReplaceAllTextareas( function( textarea, editor )
     205 *              {
     206 *                      // Custom code to evaluate the replace, returning false if it
     207 *                      // must not be done.
     208 *                      // It also passes the "editor" parameter, so the developer can
     209 *                      // customize the instance.
     210 *              } ) ;
     211 */
     212FCKeditor.ReplaceAllTextareas = function()
     213{
     214        var textareas = document.getElementsByTagName( 'textarea' ) ;
     215
     216        for ( var i = 0 ; i < textareas.length ; i++ )
     217        {
     218                var editor = null ;
     219                var textarea = textareas[i] ;
     220                var name = textarea.name ;
     221
     222                // The "name" attribute must exist.
     223                if ( !name || name.length == 0 )
     224                        continue ;
     225
     226                if ( typeof arguments[0] == 'string' )
     227                {
     228                        // The textarea class name could be passed as the function
     229                        // parameter.
     230
     231                        var classRegex = new RegExp( '(?:^| )' + arguments[0] + '(?:$| )' ) ;
     232
     233                        if ( !classRegex.test( textarea.className ) )
     234                                continue ;
     235                }
     236                else if ( typeof arguments[0] == 'function' )
     237                {
     238                        // An assertion function could be passed as the function parameter.
     239                        // It must explicitly return "false" to ignore a specific <textarea>.
     240                        editor = new FCKeditor( name ) ;
     241                        if ( arguments[0]( textarea, editor ) === false )
     242                                continue ;
     243                }
     244
     245                if ( !editor )
     246                        editor = new FCKeditor( name ) ;
     247
     248                editor.ReplaceTextarea() ;
     249        }
     250}
     251
    188252function FCKeditor_IsCompatibleBrowser()
    189253{
    190254        var sAgent = navigator.userAgent.toLowerCase() ;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy