[ 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: fckstyledef_ie.js 22 * FCKStyleDef Class: represents a single stylke definition. (IE specific) 23 * 24 * File Authors: 25 * Frederico Caldeira Knabben (www.fckeditor.net) 26 */ 27 28 FCKStyleDef.prototype.ApplyToSelection = function() 29 { 30 var oSelection = FCK.ToolbarSet.CurrentInstance.EditorDocument.selection ; 31 32 if ( oSelection.type == 'Text' ) 33 { 34 var oRange = oSelection.createRange() ; 35 36 // Create the main element. 37 var e = document.createElement( this.Element ) ; 38 e.innerHTML = oRange.htmlText ; 39 40 // Set the attributes. 41 this._AddAttributes( e ) ; 42 43 // Remove the duplicated elements. 44 this._RemoveDuplicates( e ) ; 45 46 // Replace the selection with the resulting HTML. 47 oRange.pasteHTML( e.outerHTML ) ; 48 } 49 else if ( oSelection.type == 'Control' ) 50 { 51 var oControl = FCK.ToolbarSet.CurrentInstance.Selection.GetSelectedElement() ; 52 if ( oControl.tagName == this.Element ) 53 this._AddAttributes( oControl ) ; 54 } 55 } 56 57 FCKStyleDef.prototype._AddAttributes = function( targetElement ) 58 { 59 for ( var a in this.Attributes ) 60 { 61 switch ( a.toLowerCase() ) 62 { 63 case 'style' : 64 targetElement.style.cssText = this.Attributes[a] ; 65 break ; 66 67 case 'class' : 68 targetElement.setAttribute( 'className', this.Attributes[a], 0 ) ; 69 break ; 70 71 case 'src' : 72 targetElement.setAttribute( '_fcksavedurl', this.Attributes[a], 0 ) ; 73 default : 74 targetElement.setAttribute( a, this.Attributes[a], 0 ) ; 75 } 76 } 77 } 78 79 FCKStyleDef.prototype._RemoveDuplicates = function( parent ) 80 { 81 for ( var i = 0 ; i < parent.children.length ; i++ ) 82 { 83 var oChild = parent.children[i] ; 84 this._RemoveDuplicates( oChild ) ; 85 86 if ( this.IsEqual( oChild ) ) 87 FCKTools.RemoveOuterTags( oChild ) ; 88 } 89 } 90 91 FCKStyleDef.prototype.IsEqual = function( e ) 92 { 93 if ( e.tagName != this.Element ) 94 return false ; 95 96 for ( var a in this.Attributes ) 97 { 98 switch ( a.toLowerCase() ) 99 { 100 case 'style' : 101 if ( e.style.cssText.toLowerCase() != this.Attributes[a].toLowerCase() ) 102 return false ; 103 break ; 104 case 'class' : 105 if ( e.getAttribute( 'className', 0 ) != this.Attributes[a] ) 106 return false ; 107 break ; 108 default : 109 if ( e.getAttribute( a, 0 ) != this.Attributes[a] ) 110 return false ; 111 } 112 } 113 114 return true ; 115 } 116 117 FCKStyleDef.prototype._RemoveMe = function( elementToCheck ) 118 { 119 if ( ! elementToCheck ) 120 return ; 121 122 var oParent = elementToCheck.parentElement ; 123 124 if ( this.IsEqual( elementToCheck ) ) 125 { 126 if ( this.IsObjectElement ) 127 { 128 for ( var a in this.Attributes ) 129 { 130 switch ( a.toLowerCase() ) 131 { 132 case 'class' : 133 elementToCheck.removeAttribute( 'className', 0 ) ; 134 break ; 135 default : 136 elementToCheck.removeAttribute( a, 0 ) ; 137 } 138 } 139 return ; 140 } 141 else 142 FCKTools.RemoveOuterTags( elementToCheck ) ; 143 } 144 145 this._RemoveMe( oParent ) ; 146 }
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 |