Ticket #2203: fckstyles.patch
File fckstyles.patch, 3.4 KB (added by , 15 years ago) |
---|
-
fckstyle.js
1 /*1 /* 2 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 3 * Copyright (C) 2003-2008 Frederico Caldeira Knabben 4 4 * … … 695 695 696 696 _CompareAttributeValues : function( attName, valueA, valueB ) 697 697 { 698 var matchedStyle = false; 699 698 700 if ( attName == 'style' && valueA && valueB ) 699 701 { 700 702 valueA = valueA.replace( /;$/, '' ).toLowerCase() ; 701 703 valueB = valueB.replace( /;$/, '' ).toLowerCase() ; 704 matchedStyle = valueA.indexOf( valueB ) >= 0 ? true : false ; 702 705 } 703 706 704 707 // Return true if they match or if valueA is null and valueB is an empty string 705 return ( valueA == valueB || ( ( valueA === null || valueA === '' ) && ( valueB === null || valueB === '' ) ) )708 return ( matchedStyle || valueA == valueB || ( ( valueA === null || valueA === '' ) && ( valueB === null || valueB === '' ) ) ) 706 709 }, 707 710 708 711 GetFinalAttributeValue : function( attName ) … … 1162 1165 1163 1166 // Let's merge our new style with its neighbors, if possible. 1164 1167 this._MergeSiblings( styleNode, this._GetAttribsForComparison() ) ; 1168 1169 // In the case of span tags merge with child nodes to prevent duplication 1170 this._MergeChildren( styleNode ) ; 1171 1165 1172 1166 1173 // As the style system breaks text nodes constantly, let's normalize 1167 1174 // things for performance. … … 1218 1225 break ; 1219 1226 } 1220 1227 }, 1228 1229 /** 1230 * Merge an element with its similar children. 1231 */ 1232 _MergeChildren : function( element ) 1233 { 1234 if ( !element || element.nodeType != 1 || !FCKListsLib.InlineNonEmptyElements[ element.nodeName.toLowerCase() ] ) 1235 return ; 1221 1236 1237 this._MergeFirstChild( element ) ; 1238 this._MergeLastChild( element ) ; 1239 }, 1240 1241 _MergeFirstChild : function ( element ) 1242 { 1243 var child = element.firstChild ; 1244 1245 if ( child && child.nodeType == 1 && child.nodeName == element.nodeName && child.nextSibling == null) 1246 { 1247 // Get the style of the element to merge to 1248 var mergeStyle = child.style.cssText; 1249 1250 // IE doesn't return a ";" when asking for a style so we add it here. 1251 if ( mergeStyle.charAt(mergeStyle.length - 1) != ";" ) { mergeStyle += ";"; } 1252 1253 // add the selected texts style to the new node 1254 element.style.cssText = mergeStyle + element.style.cssText; 1255 1256 // Move contents from the 1257 FCKDomTools.MoveChildren( child, element ) ; 1258 FCKDomTools.RemoveNode( child ) ; 1259 } 1260 }, 1261 1262 _MergeLastChild : function ( element ) 1263 { 1264 var child = element.lastChild ; 1265 1266 if ( child && child.nodeType == 1 && child.nodeName == element.nodeName && child.previousSibling == null) 1267 { 1268 // Get the style of the element to merge to 1269 var mergeStyle = child.style.cssText; 1270 1271 // IE doesn't return a ";" when asking for a style so we add it here. 1272 if ( mergeStyle.charAt(mergeStyle.length - 1) != ";" ) { mergeStyle += ";"; } 1273 1274 // add the selected texts style to the new node 1275 element.style.cssText = mergeStyle + element.style.cssText; 1276 1277 // Move contents from the child 1278 FCKDomTools.MoveChildren( child, element ) ; 1279 FCKDomTools.RemoveNode( child ) ; 1280 } 1281 }, 1282 1222 1283 /** 1223 1284 * Merge an element with its similar siblings. 1224 1285 * "attribs" is and object computed with _CreateAttribsForComparison.