Changeset 1185

Show
Ignore:
Timestamp:
2007-12-07 10:14:19 (9 months ago)
Author:
fredck
Message:

#1617 : Implemented ReplaceAllTextareas for the JavaScript integration

Location:
FCKeditor/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/trunk/fckeditor.js

    r994 r1185  
    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 ; 
     
    4444        this.OnError            = null ;        // function( source, errorNumber, errorDescription ) 
    4545} 
     46 
     47/** 
     48 * This is the default BasePath used by all editor instances. 
     49 */ 
     50FCKeditor.BasePath = '/fckeditor/' ; 
     51 
     52/** 
     53 * The minimum height used when replacing textareas. 
     54 */ 
     55FCKeditor.MinHeight = 200 ; 
     56 
     57/** 
     58 * The minimum width used when replacing textareas. 
     59 */ 
     60FCKeditor.MinWidth = 750 ; 
    4661 
    4762FCKeditor.prototype.Version                     = '[Development]' ; 
     
    186201} 
    187202 
     203;(function() 
     204{ 
     205        var textareaToEditor = function( textarea ) 
     206        { 
     207                var editor = new FCKeditor( textarea.name ) ; 
     208                 
     209                editor.Width = Math.max( textarea.offsetWidth, FCKeditor.MinWidth ) ; 
     210                editor.Height = Math.max( textarea.offsetHeight, FCKeditor.MinHeight ) ; 
     211                 
     212                return editor ; 
     213        } 
     214         
     215        /** 
     216         * Replace all <textarea> elements available in the document with FCKeditor 
     217         * instances. 
     218         * 
     219         *      // Replace all <textarea> elements in the page. 
     220         *      FCKeditor.ReplaceAllTextareas() ; 
     221         * 
     222         *      // Replace all <textarea class="myClassName"> elements in the page. 
     223         *      FCKeditor.ReplaceAllTextareas( 'myClassName' ) ; 
     224         * 
     225         *      // Selectively replace <textarea> elements, based on custom assertions. 
     226         *      FCKeditor.ReplaceAllTextareas( function( textarea, editor ) 
     227         *              { 
     228         *                      // Custom code to evaluate the replace, returning false if it 
     229         *                      // must not be done. 
     230         *                      // It also passes the "editor" parameter, so the developer can 
     231         *                      // customize the instance. 
     232         *              } ) ; 
     233         */ 
     234        FCKeditor.ReplaceAllTextareas = function() 
     235        { 
     236                var textareas = document.getElementsByTagName( 'textarea' ) ; 
     237 
     238                for ( var i = 0 ; i < textareas.length ; i++ ) 
     239                { 
     240                        var editor = null ; 
     241                        var textarea = textareas[i] ; 
     242                        var name = textarea.name ; 
     243 
     244                        // The "name" attribute must exist. 
     245                        if ( !name || name.length == 0 ) 
     246                                continue ; 
     247                         
     248                        if ( typeof arguments[0] == 'string' ) 
     249                        { 
     250                                // The textarea class name could be passed as the function 
     251                                // parameter. 
     252 
     253                                var classRegex = new RegExp( '(?:^| )' + arguments[0] + '(?:$| )' ) ; 
     254 
     255                                if ( !classRegex.test( textarea.className ) ) 
     256                                        continue ; 
     257                        } 
     258                        else if ( typeof arguments[0] == 'function' ) 
     259                        { 
     260                                // An assertion function could be passed as the function parameter. 
     261                                // It must explicitly return "false" to ignore a specific <textarea>. 
     262                                editor = textareaToEditor( textarea ) ; 
     263                                if ( arguments[0]( textarea, editor ) === false ) 
     264                                        continue ; 
     265                        } 
     266 
     267                        if ( !editor ) 
     268                                editor = textareaToEditor( textarea ) ; 
     269 
     270                        editor.ReplaceTextarea() ; 
     271                } 
     272        } 
     273})() ; 
     274 
    188275function FCKeditor_IsCompatibleBrowser() 
    189276{ 
  • FCKeditor/trunk/_whatsnew.html

    r1148 r1185  
    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>