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