[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 /* 2 * FCKeditor - The text editor for internet 3 * Copyright (C) 2003-2006 Frederico Caldeira Knabben 4 * 5 * Licensed under the terms of the GNU Lesser General Public License: 6 * http://www.opensource.org/licenses/lgpl-license.php 7 * 8 * For further information visit: 9 * http://www.fckeditor.net/ 10 * 11 * "Support Open Source software. What about a donation today?" 12 * 13 * File Name: fckdocumentprocessor.js 14 * Advanced document processors. 15 * 16 * File Authors: 17 * Frederico Caldeira Knabben (fredck@fckeditor.net) 18 */ 19 20 var FCKDocumentProcessor = new Object() ; 21 FCKDocumentProcessor._Items = new Array() ; 22 23 FCKDocumentProcessor.AppendNew = function() 24 { 25 var oNewItem = new Object() ; 26 this._Items.AddItem( oNewItem ) ; 27 return oNewItem ; 28 } 29 30 FCKDocumentProcessor.Process = function( document ) 31 { 32 var oProcessor, i = 0 ; 33 while( ( oProcessor = this._Items[i++] ) ) 34 oProcessor.ProcessDocument( document ) ; 35 } 36 37 var FCKDocumentProcessor_CreateFakeImage = function( fakeClass, realElement ) 38 { 39 var oImg = FCK.EditorDocument.createElement( 'IMG' ) ; 40 oImg.className = fakeClass ; 41 oImg.src = FCKConfig.FullBasePath + 'images/spacer.gif' ; 42 oImg.setAttribute( '_fckfakelement', 'true', 0 ) ; 43 oImg.setAttribute( '_fckrealelement', FCKTempBin.AddElement( realElement ), 0 ) ; 44 return oImg ; 45 } 46 47 // Link Anchors 48 var FCKAnchorsProcessor = FCKDocumentProcessor.AppendNew() ; 49 FCKAnchorsProcessor.ProcessDocument = function( document ) 50 { 51 var aLinks = document.getElementsByTagName( 'A' ) ; 52 53 var oLink ; 54 var i = aLinks.length - 1 ; 55 while ( i >= 0 && ( oLink = aLinks[i--] ) ) 56 { 57 // If it is anchor. 58 if ( oLink.name.length > 0 && ( !oLink.getAttribute('href') || oLink.getAttribute('href').length == 0 ) ) 59 { 60 var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oLink.cloneNode(true) ) ; 61 oImg.setAttribute( '_fckanchor', 'true', 0 ) ; 62 63 oLink.parentNode.insertBefore( oImg, oLink ) ; 64 oLink.parentNode.removeChild( oLink ) ; 65 } 66 } 67 } 68 69 // Page Breaks 70 var FCKPageBreaksProcessor = FCKDocumentProcessor.AppendNew() ; 71 FCKPageBreaksProcessor.ProcessDocument = function( document ) 72 { 73 var aDIVs = document.getElementsByTagName( 'DIV' ) ; 74 75 var eDIV ; 76 var i = aDIVs.length - 1 ; 77 while ( i >= 0 && ( eDIV = aDIVs[i--] ) ) 78 { 79 if ( eDIV.style.pageBreakAfter == 'always' && eDIV.childNodes.length == 1 && eDIV.childNodes[0].style && eDIV.childNodes[0].style.display == 'none' ) 80 { 81 var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', eDIV.cloneNode(true) ) ; 82 83 eDIV.parentNode.insertBefore( oFakeImage, eDIV ) ; 84 eDIV.parentNode.removeChild( eDIV ) ; 85 } 86 } 87 /* 88 var aCenters = document.getElementsByTagName( 'CENTER' ) ; 89 90 var oCenter ; 91 var i = aCenters.length - 1 ; 92 while ( i >= 0 && ( oCenter = aCenters[i--] ) ) 93 { 94 if ( oCenter.style.pageBreakAfter == 'always' && oCenter.innerHTML.trim().length == 0 ) 95 { 96 var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', oCenter.cloneNode(true) ) ; 97 98 oCenter.parentNode.insertBefore( oFakeImage, oCenter ) ; 99 oCenter.parentNode.removeChild( oCenter ) ; 100 } 101 } 102 */ 103 } 104 105 // Flash Embeds. 106 var FCKFlashProcessor = FCKDocumentProcessor.AppendNew() ; 107 FCKFlashProcessor.ProcessDocument = function( document ) 108 { 109 /* 110 Sample code: 111 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>. 112 */ 113 114 var aEmbeds = document.getElementsByTagName( 'EMBED' ) ; 115 116 var oEmbed ; 117 var i = aEmbeds.length - 1 ; 118 while ( i >= 0 && ( oEmbed = aEmbeds[i--] ) ) 119 { 120 if ( oEmbed.src.endsWith( '.swf', true ) ) 121 { 122 var oCloned = oEmbed.cloneNode( true ) ; 123 124 // On IE, some properties are not getting clonned properly, so we 125 // must fix it. Thanks to Alfonso Martinez. 126 if ( FCKBrowserInfo.IsIE ) 127 { 128 var oAtt ; 129 if ( oAtt = oEmbed.getAttribute( 'scale' ) ) oCloned.setAttribute( 'scale', oAtt ) ; 130 if ( oAtt = oEmbed.getAttribute( 'play' ) ) oCloned.setAttribute( 'play', oAtt ) ; 131 if ( oAtt = oEmbed.getAttribute( 'loop' ) ) oCloned.setAttribute( 'loop', oAtt ) ; 132 if ( oAtt = oEmbed.getAttribute( 'menu' ) ) oCloned.setAttribute( 'menu', oAtt ) ; 133 if ( oAtt = oEmbed.getAttribute( 'wmode' ) ) oCloned.setAttribute( 'wmode', oAtt ) ; 134 if ( oAtt = oEmbed.getAttribute( 'quality' ) ) oCloned.setAttribute( 'quality', oAtt ) ; 135 } 136 137 var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Flash', oCloned ) ; 138 oImg.setAttribute( '_fckflash', 'true', 0 ) ; 139 140 FCKFlashProcessor.RefreshView( oImg, oEmbed ) ; 141 142 oEmbed.parentNode.insertBefore( oImg, oEmbed ) ; 143 oEmbed.parentNode.removeChild( oEmbed ) ; 144 145 // oEmbed.setAttribute( '_fcktemp', 'true', 0) ; 146 // oEmbed.style.display = 'none' ; 147 // oEmbed.hidden = true ; 148 } 149 } 150 } 151 152 FCKFlashProcessor.RefreshView = function( placholderImage, originalEmbed ) 153 { 154 if ( originalEmbed.width > 0 ) 155 placholderImage.style.width = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.width ) ; 156 157 if ( originalEmbed.height > 0 ) 158 placholderImage.style.height = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.height ) ; 159 } 160 161 FCK.GetRealElement = function( fakeElement ) 162 { 163 var e = FCKTempBin.Elements[ fakeElement.getAttribute('_fckrealelement') ] ; 164 165 if ( fakeElement.getAttribute('_fckflash') ) 166 { 167 if ( fakeElement.style.width.length > 0 ) 168 e.width = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.width ) ; 169 170 if ( fakeElement.style.height.length > 0 ) 171 e.height = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.height ) ; 172 } 173 174 return e ; 175 } 176 177 // START iCM MODIFICATIONS 178 /* 179 var FCKTablesProcessor = FCKDocumentProcessor.AppendNew() ; 180 FCKTablesProcessor.ProcessDocument = function( document ) 181 { 182 FCKTablesProcessor.CheckTablesNesting( document ) ; 183 } 184 185 // Ensure that tables are not incorrectly nested within P, H1, H2, etc tags 186 FCKTablesProcessor.CheckTablesNesting = function( document ) 187 { 188 var aTables = document.getElementsByTagName( "TABLE" ) ; 189 var oParentNode ; 190 191 for ( var i=0; i<aTables.length; i++ ) 192 { 193 FCKTablesProcessor.CheckTableNesting( aTables[i] ) ; 194 } 195 } 196 197 // Corrects nesting of the supplied table as necessary. 198 // Also called by fck_table.html to check that a newly inserted table is correctly nested. 199 FCKTablesProcessor.CheckTableNesting = function( oTableNode ) 200 { 201 var oParentBlockNode = FCKTools.GetParentBlockNode( oTableNode.parentNode ) ; 202 203 if ( oParentBlockNode && !FCKRegexLib.TableBlockElements.test( oParentBlockNode.nodeName ) ) 204 { 205 // Create a new tag which holds the content of the child nodes located before the table 206 var oNode1 = FCK.EditorDocument.createElement( oParentBlockNode.tagName ) ; 207 var oFragment1 = FCKTools.GetDocumentFragment( oParentBlockNode, oParentBlockNode.firstChild, oTableNode, true, false, true ) ; 208 oNode1.appendChild( oFragment1 ) ; 209 FCKTools.SetElementAttributes( oNode1, oParentBlockNode.attributes ) ; // Transfer across any class attributes, etc 210 211 // Create a new tag which holds the content of the child nodes located after the table 212 var oNode2 = FCK.EditorDocument.createElement( oParentBlockNode.tagName ); 213 var oFragment2 = FCKTools.GetDocumentFragment( oParentBlockNode, oTableNode, oParentBlockNode.lastChild, false, true, true ) ; 214 oNode2.appendChild( oFragment2 ) ; 215 FCKTools.SetElementAttributes( oNode2, oParentBlockNode.attributes ) ; // Transfer across any class attributes, etc 216 217 // Create a document fragment that contains the two new elements with the table element inbetween 218 var oNewNode = FCK.EditorDocument.createDocumentFragment() ; 219 if ( !FCKTools.NodeIsEmpty( oNode1 ) ) 220 oNewNode.appendChild( oNode1 ) ; 221 oNewNode.appendChild( oTableNode ) ; 222 if ( !FCKTools.NodeIsEmpty( oNode2 ) ) 223 oNewNode.appendChild( oNode2 ) ; 224 225 // Replace the existing parent node with the nodes in the fragment 226 oParentBlockNode.parentNode.replaceChild( oNewNode, oParentBlockNode ) ; 227 } 228 } 229 */ 230 // END iCM MODIFICATIONS
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |