| 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 | */ |
| 212 | FCKeditor.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 | |