| 1 |
/* |
| 2 |
|
| 3 |
* FCKeditor - The text editor for Internet - http://www.fckeditor.net |
| 4 |
|
| 5 |
* Copyright (C) 2003-2009 Frederico Caldeira Knabben |
| 6 |
|
| 7 |
* |
| 8 |
|
| 9 |
* == BEGIN LICENSE == |
| 10 |
|
| 11 |
* |
| 12 |
|
| 13 |
* Licensed under the terms of any of the following licenses at your |
| 14 |
|
| 15 |
* choice: |
| 16 |
|
| 17 |
* |
| 18 |
|
| 19 |
* - GNU General Public License Version 2 or later (the "GPL") |
| 20 |
|
| 21 |
* http://www.gnu.org/licenses/gpl.html |
| 22 |
|
| 23 |
* |
| 24 |
|
| 25 |
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL") |
| 26 |
|
| 27 |
* http://www.gnu.org/licenses/lgpl.html |
| 28 |
|
| 29 |
* |
| 30 |
|
| 31 |
* - Mozilla Public License Version 1.1 or later (the "MPL") |
| 32 |
|
| 33 |
* http://www.mozilla.org/MPL/MPL-1.1.html |
| 34 |
|
| 35 |
* |
| 36 |
|
| 37 |
* == END LICENSE == |
| 38 |
|
| 39 |
* |
| 40 |
|
| 41 |
* Advanced document processors. |
| 42 |
|
| 43 |
*/ |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
var FCKDocumentProcessor = new Object() ; |
| 48 |
|
| 49 |
FCKDocumentProcessor._Items = new Array() ; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
FCKDocumentProcessor.AppendNew = function() |
| 54 |
|
| 55 |
{ |
| 56 |
|
| 57 |
var oNewItem = new Object() ; |
| 58 |
|
| 59 |
this._Items.push( oNewItem ) ; |
| 60 |
|
| 61 |
return oNewItem ; |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
FCKDocumentProcessor.Process = function( document ) |
| 68 |
|
| 69 |
{ |
| 70 |
|
| 71 |
var bIsDirty = FCK.IsDirty() ; |
| 72 |
|
| 73 |
var oProcessor, i = 0 ; |
| 74 |
|
| 75 |
while( ( oProcessor = this._Items[i++] ) ) |
| 76 |
|
| 77 |
oProcessor.ProcessDocument( document ) ; |
| 78 |
|
| 79 |
if ( !bIsDirty ) |
| 80 |
|
| 81 |
FCK.ResetIsDirty() ; |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
var FCKDocumentProcessor_CreateFakeImage = function( fakeClass, realElement ) |
| 88 |
|
| 89 |
{ |
| 90 |
|
| 91 |
var oImg = FCKTools.GetElementDocument( realElement ).createElement( 'IMG' ) ; |
| 92 |
|
| 93 |
oImg.className = fakeClass ; |
| 94 |
|
| 95 |
oImg.src = FCKConfig.BasePath + 'images/spacer.gif' ; |
| 96 |
|
| 97 |
oImg.setAttribute( '_fckfakelement', 'true', 0 ) ; |
| 98 |
|
| 99 |
oImg.setAttribute( '_fckrealelement', FCKTempBin.AddElement( realElement ), 0 ) ; |
| 100 |
|
| 101 |
return oImg ; |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
// Link Anchors |
| 108 |
|
| 109 |
if ( FCKBrowserInfo.IsIE || FCKBrowserInfo.IsOpera ) |
| 110 |
|
| 111 |
{ |
| 112 |
|
| 113 |
var FCKAnchorsProcessor = FCKDocumentProcessor.AppendNew() ; |
| 114 |
|
| 115 |
FCKAnchorsProcessor.ProcessDocument = function( document ) |
| 116 |
|
| 117 |
{ |
| 118 |
|
| 119 |
var aLinks = document.getElementsByTagName( 'A' ) ; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
var oLink ; |
| 124 |
|
| 125 |
var i = aLinks.length - 1 ; |
| 126 |
|
| 127 |
while ( i >= 0 && ( oLink = aLinks[i--] ) ) |
| 128 |
|
| 129 |
{ |
| 130 |
|
| 131 |
// If it is anchor. Doesn't matter if it's also a link (even better: we show that it's both a link and an anchor) |
| 132 |
|
| 133 |
if ( oLink.name.length > 0 ) |
| 134 |
|
| 135 |
{ |
| 136 |
|
| 137 |
//if the anchor has some content then we just add a temporary class |
| 138 |
|
| 139 |
if ( oLink.innerHTML !== '' ) |
| 140 |
|
| 141 |
{ |
| 142 |
|
| 143 |
if ( FCKBrowserInfo.IsIE ) |
| 144 |
|
| 145 |
oLink.className += ' FCK__AnchorC' ; |
| 146 |
|
| 147 |
} |
| 148 |
|
| 149 |
else |
| 150 |
|
| 151 |
{ |
| 152 |
|
| 153 |
var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oLink.cloneNode(true) ) ; |
| 154 |
|
| 155 |
oImg.setAttribute( '_fckanchor', 'true', 0 ) ; |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
oLink.parentNode.insertBefore( oImg, oLink ) ; |
| 160 |
|
| 161 |
oLink.parentNode.removeChild( oLink ) ; |
| 162 |
|
| 163 |
} |
| 164 |
|
| 165 |
} |
| 166 |
|
| 167 |
} |
| 168 |
|
| 169 |
} |
| 170 |
|
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
// Page Breaks |
| 176 |
|
| 177 |
var FCKPageBreaksProcessor = FCKDocumentProcessor.AppendNew() ; |
| 178 |
|
| 179 |
FCKPageBreaksProcessor.ProcessDocument = function( document ) |
| 180 |
|
| 181 |
{ |
| 182 |
|
| 183 |
var aDIVs = document.getElementsByTagName( 'DIV' ) ; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
var eDIV ; |
| 188 |
|
| 189 |
var i = aDIVs.length - 1 ; |
| 190 |
|
| 191 |
while ( i >= 0 && ( eDIV = aDIVs[i--] ) ) |
| 192 |
|
| 193 |
{ |
| 194 |
|
| 195 |
if ( eDIV.style.pageBreakAfter == 'always' && eDIV.childNodes.length == 1 && eDIV.childNodes[0].style && eDIV.childNodes[0].style.display == 'none' ) |
| 196 |
|
| 197 |
{ |
| 198 |
|
| 199 |
var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', eDIV.cloneNode(true) ) ; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
eDIV.parentNode.insertBefore( oFakeImage, eDIV ) ; |
| 204 |
|
| 205 |
eDIV.parentNode.removeChild( eDIV ) ; |
| 206 |
|
| 207 |
} |
| 208 |
|
| 209 |
} |
| 210 |
|
| 211 |
/* |
| 212 |
|
| 213 |
var aCenters = document.getElementsByTagName( 'CENTER' ) ; |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
var oCenter ; |
| 218 |
|
| 219 |
var i = aCenters.length - 1 ; |
| 220 |
|
| 221 |
while ( i >= 0 && ( oCenter = aCenters[i--] ) ) |
| 222 |
|
| 223 |
{ |
| 224 |
|
| 225 |
if ( oCenter.style.pageBreakAfter == 'always' && oCenter.innerHTML.Trim().length == 0 ) |
| 226 |
|
| 227 |
{ |
| 228 |
|
| 229 |
var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', oCenter.cloneNode(true) ) ; |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
oCenter.parentNode.insertBefore( oFakeImage, oCenter ) ; |
| 234 |
|
| 235 |
oCenter.parentNode.removeChild( oCenter ) ; |
| 236 |
|
| 237 |
} |
| 238 |
|
| 239 |
} |
| 240 |
|
| 241 |
*/ |
| 242 |
|
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
// EMBED and OBJECT tags. |
| 248 |
|
| 249 |
var FCKEmbedAndObjectProcessor = (function() |
| 250 |
|
| 251 |
{ |
| 252 |
|
| 253 |
var customProcessors = [] ; |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
var processElement = function( el ) |
| 258 |
|
| 259 |
{ |
| 260 |
|
| 261 |
var clone = el.cloneNode( true ) ; |
| 262 |
|
| 263 |
var replaceElement ; |
| 264 |
|
| 265 |
var fakeImg = replaceElement = FCKDocumentProcessor_CreateFakeImage( 'FCK__UnknownObject', clone ) ; |
| 266 |
|
| 267 |
FCKEmbedAndObjectProcessor.RefreshView( fakeImg, el ) ; |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
for ( var i = 0 ; i < customProcessors.length ; i++ ) |
| 272 |
|
| 273 |
replaceElement = customProcessors[i]( el, replaceElement ) || replaceElement ; |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
if ( replaceElement != fakeImg ) |
| 278 |
|
| 279 |
FCKTempBin.RemoveElement( fakeImg.getAttribute( '_fckrealelement' ) ) ; |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
el.parentNode.replaceChild( replaceElement, el ) ; |
| 284 |
|
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
var processElementsByName = function( elementName, doc ) |
| 290 |
|
| 291 |
{ |
| 292 |
|
| 293 |
var aObjects = doc.getElementsByTagName( elementName ); |
| 294 |
|
| 295 |
for ( var i = aObjects.length - 1 ; i >= 0 ; i-- ) |
| 296 |
|
| 297 |
processElement( aObjects[i] ) ; |
| 298 |
|
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
var processObjectAndEmbed = function( doc ) |
| 304 |
|
| 305 |
{ |
| 306 |
|
| 307 |
processElementsByName( 'object', doc ); |
| 308 |
|
| 309 |
processElementsByName( 'embed', doc ); |
| 310 |
|
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
return FCKTools.Merge( FCKDocumentProcessor.AppendNew(), |
| 316 |
|
| 317 |
{ |
| 318 |
|
| 319 |
ProcessDocument : function( doc ) |
| 320 |
|
| 321 |
{ |
| 322 |
|
| 323 |
// Firefox 3 would sometimes throw an unknown exception while accessing EMBEDs and OBJECTs |
| 324 |
|
| 325 |
// without the setTimeout(). |
| 326 |
|
| 327 |
if ( FCKBrowserInfo.IsGecko ) |
| 328 |
|
| 329 |
FCKTools.RunFunction( processObjectAndEmbed, this, [ doc ] ) ; |
| 330 |
|
| 331 |
else |
| 332 |
|
| 333 |
processObjectAndEmbed( doc ) ; |
| 334 |
|
| 335 |
}, |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
RefreshView : function( placeHolder, original ) |
| 340 |
|
| 341 |
{ |
| 342 |
|
| 343 |
if ( original.getAttribute( 'width' ) > 0 ) |
| 344 |
|
| 345 |
placeHolder.style.width = FCKTools.ConvertHtmlSizeToStyle( original.getAttribute( 'width' ) ) ; |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
if ( original.getAttribute( 'height' ) > 0 ) |
| 350 |
|
| 351 |
placeHolder.style.height = FCKTools.ConvertHtmlSizeToStyle( original.getAttribute( 'height' ) ) ; |
| 352 |
|
| 353 |
}, |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
AddCustomHandler : function( func ) |
| 358 |
|
| 359 |
{ |
| 360 |
|
| 361 |
customProcessors.push( func ) ; |
| 362 |
|
| 363 |
} |
| 364 |
|
| 365 |
} ) ; |
| 366 |
|
| 367 |
} )() ; |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
FCK.GetRealElement = function( fakeElement ) |
| 372 |
|
| 373 |
{ |
| 374 |
|
| 375 |
var e = FCKTempBin.Elements[ fakeElement.getAttribute('_fckrealelement') ] ; |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
if ( fakeElement.getAttribute('_fckflash') ) |
| 380 |
|
| 381 |
{ |
| 382 |
|
| 383 |
if ( fakeElement.style.width.length > 0 ) |
| 384 |
|
| 385 |
e.width = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.width ) ; |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
if ( fakeElement.style.height.length > 0 ) |
| 390 |
|
| 391 |
e.height = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.height ) ; |
| 392 |
|
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
return e ; |
| 398 |
|
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
// HR Processor. |
| 404 |
|
| 405 |
// This is a IE only (tricky) thing. We protect all HR tags before loading them |
| 406 |
|
| 407 |
// (see FCK.ProtectTags). Here we put the HRs back. |
| 408 |
|
| 409 |
if ( FCKBrowserInfo.IsIE ) |
| 410 |
|
| 411 |
{ |
| 412 |
|
| 413 |
FCKDocumentProcessor.AppendNew().ProcessDocument = function( document ) |
| 414 |
|
| 415 |
{ |
| 416 |
|
| 417 |
var aHRs = document.getElementsByTagName( 'HR' ) ; |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
var eHR ; |
| 422 |
|
| 423 |
var i = aHRs.length - 1 ; |
| 424 |
|
| 425 |
while ( i >= 0 && ( eHR = aHRs[i--] ) ) |
| 426 |
|
| 427 |
{ |
| 428 |
|
| 429 |
// Create the replacement HR. |
| 430 |
|
| 431 |
var newHR = document.createElement( 'hr' ) ; |
| 432 |
|
| 433 |
newHR.mergeAttributes( eHR, true ) ; |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
// We must insert the new one after it. insertBefore will not work in all cases. |
| 438 |
|
| 439 |
FCKDomTools.InsertAfterNode( eHR, newHR ) ; |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
eHR.parentNode.removeChild( eHR ) ; |
| 444 |
|
| 445 |
} |
| 446 |
|
| 447 |
} |
| 448 |
|
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
// INPUT:hidden Processor. |
| 454 |
|
| 455 |
FCKDocumentProcessor.AppendNew().ProcessDocument = function( document ) |
| 456 |
|
| 457 |
{ |
| 458 |
|
| 459 |
var aInputs = document.getElementsByTagName( 'INPUT' ) ; |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
var oInput ; |
| 464 |
|
| 465 |
var i = aInputs.length - 1 ; |
| 466 |
|
| 467 |
while ( i >= 0 && ( oInput = aInputs[i--] ) ) |
| 468 |
|
| 469 |
{ |
| 470 |
|
| 471 |
if ( oInput.type == 'hidden' ) |
| 472 |
|
| 473 |
{ |
| 474 |
|
| 475 |
var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__InputHidden', oInput.cloneNode(true) ) ; |
| 476 |
|
| 477 |
oImg.setAttribute( '_fckinputhidden', 'true', 0 ) ; |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
oInput.parentNode.insertBefore( oImg, oInput ) ; |
| 482 |
|
| 483 |
oInput.parentNode.removeChild( oInput ) ; |
| 484 |
|
| 485 |
} |
| 486 |
|
| 487 |
} |
| 488 |
|
| 489 |
} |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
// Flash handler. |
| 494 |
|
| 495 |
FCKEmbedAndObjectProcessor.AddCustomHandler( function( el, fakeImg ) |
| 496 |
|
| 497 |
{ |
| 498 |
|
| 499 |
if ( ! ( el.nodeName.IEquals( 'embed' ) && ( el.type == 'application/x-shockwave-flash' || /\.swf($|#|\?)/i.test( el.src ) ) ) ) |
| 500 |
|
| 501 |
return ; |
| 502 |
|
| 503 |
fakeImg.className = 'FCK__Flash' ; |
| 504 |
|
| 505 |
fakeImg.setAttribute( '_fckflash', 'true', 0 ); |
| 506 |
|
| 507 |
} ) ; |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
// Buggy <span class="Apple-style-span"> tags added by Safari. |
| 512 |
|
| 513 |
if ( FCKBrowserInfo.IsSafari ) |
| 514 |
|
| 515 |
{ |
| 516 |
|
| 517 |
FCKDocumentProcessor.AppendNew().ProcessDocument = function( doc ) |
| 518 |
|
| 519 |
{ |
| 520 |
|
| 521 |
var spans = doc.getElementsByClassName ? |
| 522 |
|
| 523 |
doc.getElementsByClassName( 'Apple-style-span' ) : |
| 524 |
|
| 525 |
Array.prototype.filter.call( |
| 526 |
|
| 527 |
doc.getElementsByTagName( 'span' ), |
| 528 |
|
| 529 |
function( item ){ return item.className == 'Apple-style-span' ; } |
| 530 |
|
| 531 |
) ; |
| 532 |
|
| 533 |
for ( var i = spans.length - 1 ; i >= 0 ; i-- ) |
| 534 |
|
| 535 |
FCKDomTools.RemoveNode( spans[i], true ) ; |
| 536 |
|
| 537 |
} |
| 538 |
|
| 539 |
} |
| 540 |
|
| 541 |
|