[ Index ] |
|
Code source de FCKeditor 2.4 |
1 /* 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 * 21 * File Name: fckdocumentprocessor.js 22 * Advanced document processors. 23 * 24 * File Authors: 25 * Frederico Caldeira Knabben (www.fckeditor.net) 26 * Alfonso Martinez de Lizarrondo - Uritec (alfonso at uritec dot net) 27 */ 28 29 var FCKDocumentProcessor = new Object() ; 30 FCKDocumentProcessor._Items = new Array() ; 31 32 FCKDocumentProcessor.AppendNew = function() 33 { 34 var oNewItem = new Object() ; 35 this._Items.AddItem( oNewItem ) ; 36 return oNewItem ; 37 } 38 39 FCKDocumentProcessor.Process = function( document ) 40 { 41 var oProcessor, i = 0 ; 42 while( ( oProcessor = this._Items[i++] ) ) 43 oProcessor.ProcessDocument( document ) ; 44 } 45 46 var FCKDocumentProcessor_CreateFakeImage = function( fakeClass, realElement ) 47 { 48 var oImg = FCK.EditorDocument.createElement( 'IMG' ) ; 49 oImg.className = fakeClass ; 50 oImg.src = FCKConfig.FullBasePath + 'images/spacer.gif' ; 51 oImg.setAttribute( '_fckfakelement', 'true', 0 ) ; 52 oImg.setAttribute( '_fckrealelement', FCKTempBin.AddElement( realElement ), 0 ) ; 53 return oImg ; 54 } 55 56 // Link Anchors 57 if ( FCKBrowserInfo.IsIE || FCKBrowserInfo.IsOpera ) 58 { 59 var FCKAnchorsProcessor = FCKDocumentProcessor.AppendNew() ; 60 FCKAnchorsProcessor.ProcessDocument = function( document ) 61 { 62 var aLinks = document.getElementsByTagName( 'A' ) ; 63 64 var oLink ; 65 var i = aLinks.length - 1 ; 66 while ( i >= 0 && ( oLink = aLinks[i--] ) ) 67 { 68 // 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) 69 if ( oLink.name.length > 0 ) 70 { 71 //if the anchor has some content then we just add a temporary class 72 if ( oLink.innerHTML != '' ) 73 { 74 if ( FCKBrowserInfo.IsIE ) 75 oLink.className += ' FCK__AnchorC' ; 76 } 77 else 78 { 79 var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oLink.cloneNode(true) ) ; 80 oImg.setAttribute( '_fckanchor', 'true', 0 ) ; 81 82 oLink.parentNode.insertBefore( oImg, oLink ) ; 83 oLink.parentNode.removeChild( oLink ) ; 84 } 85 } 86 } 87 } 88 } 89 90 // Page Breaks 91 var FCKPageBreaksProcessor = FCKDocumentProcessor.AppendNew() ; 92 FCKPageBreaksProcessor.ProcessDocument = function( document ) 93 { 94 var aDIVs = document.getElementsByTagName( 'DIV' ) ; 95 96 var eDIV ; 97 var i = aDIVs.length - 1 ; 98 while ( i >= 0 && ( eDIV = aDIVs[i--] ) ) 99 { 100 if ( eDIV.style.pageBreakAfter == 'always' && eDIV.childNodes.length == 1 && eDIV.childNodes[0].style && eDIV.childNodes[0].style.display == 'none' ) 101 { 102 var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', eDIV.cloneNode(true) ) ; 103 104 eDIV.parentNode.insertBefore( oFakeImage, eDIV ) ; 105 eDIV.parentNode.removeChild( eDIV ) ; 106 } 107 } 108 /* 109 var aCenters = document.getElementsByTagName( 'CENTER' ) ; 110 111 var oCenter ; 112 var i = aCenters.length - 1 ; 113 while ( i >= 0 && ( oCenter = aCenters[i--] ) ) 114 { 115 if ( oCenter.style.pageBreakAfter == 'always' && oCenter.innerHTML.Trim().length == 0 ) 116 { 117 var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', oCenter.cloneNode(true) ) ; 118 119 oCenter.parentNode.insertBefore( oFakeImage, oCenter ) ; 120 oCenter.parentNode.removeChild( oCenter ) ; 121 } 122 } 123 */ 124 } 125 126 // Flash Embeds. 127 var FCKFlashProcessor = FCKDocumentProcessor.AppendNew() ; 128 FCKFlashProcessor.ProcessDocument = function( document ) 129 { 130 /* 131 Sample code: 132 This is some <embed src="/UserFiles/Flash/Yellow_Runners.swf"></embed><strong>sample text</strong>. You are <a name="fred"></a> using <a href="http://www.fckeditor.net/">FCKeditor</a>. 133 */ 134 135 var aEmbeds = document.getElementsByTagName( 'EMBED' ) ; 136 137 var oEmbed ; 138 var i = aEmbeds.length - 1 ; 139 while ( i >= 0 && ( oEmbed = aEmbeds[i--] ) ) 140 { 141 if ( oEmbed.src.EndsWith( '.swf', true ) ) 142 { 143 var oCloned = oEmbed.cloneNode( true ) ; 144 145 // On IE, some properties are not getting clonned properly, so we 146 // must fix it. Thanks to Alfonso Martinez. 147 if ( FCKBrowserInfo.IsIE ) 148 { 149 var aAttributes = [ 'scale', 'play', 'loop', 'menu', 'wmode', 'quality' ] ; 150 for ( var iAtt = 0 ; i < aAttributes.length ; i++ ) 151 { 152 var oAtt = oEmbed.getAttribute( aAttributes[iAtt] ) ; 153 if ( oAtt ) oCloned.setAttribute( aAttributes[iAtt], oAtt ) ; 154 } 155 } 156 157 var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Flash', oCloned ) ; 158 oImg.setAttribute( '_fckflash', 'true', 0 ) ; 159 160 FCKFlashProcessor.RefreshView( oImg, oEmbed ) ; 161 162 oEmbed.parentNode.insertBefore( oImg, oEmbed ) ; 163 oEmbed.parentNode.removeChild( oEmbed ) ; 164 165 // oEmbed.setAttribute( '_fcktemp', 'true', 0) ; 166 // oEmbed.style.display = 'none' ; 167 // oEmbed.hidden = true ; 168 } 169 } 170 } 171 172 FCKFlashProcessor.RefreshView = function( placholderImage, originalEmbed ) 173 { 174 if ( originalEmbed.width > 0 ) 175 placholderImage.style.width = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.width ) ; 176 177 if ( originalEmbed.height > 0 ) 178 placholderImage.style.height = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.height ) ; 179 } 180 181 FCK.GetRealElement = function( fakeElement ) 182 { 183 var e = FCKTempBin.Elements[ fakeElement.getAttribute('_fckrealelement') ] ; 184 185 if ( fakeElement.getAttribute('_fckflash') ) 186 { 187 if ( fakeElement.style.width.length > 0 ) 188 e.width = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.width ) ; 189 190 if ( fakeElement.style.height.length > 0 ) 191 e.height = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.height ) ; 192 } 193 194 return e ; 195 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 15:28:05 2007 | par Balluche grâce à PHPXref 0.7 |