Ticket #6976: override.patch
File override.patch, 8.4 KB (added by , 14 years ago) |
---|
-
_source/plugins/colorbutton/plugin.js
287 287 CKEDITOR.config.colorButton_backStyle = 288 288 { 289 289 element : 'span', 290 styles : { 'background-color' : '#(color)' } 290 styles : { 'background-color' : '#(color)' }, 291 overrides : [ { element : '*', styles : { 'background-color' : null }} ] 291 292 }; -
_source/plugins/styles/plugin.js
100 100 { 101 101 styleDefinition = CKEDITOR.tools.clone( styleDefinition ); 102 102 103 replaceVariables( styleDefinition.attributes, variablesValues ); 104 replaceVariables( styleDefinition.styles, variablesValues ); 103 replaceVariables( styleDefinition, variablesValues ); 105 104 } 106 105 107 106 var element = this.element = ( styleDefinition.element || '*' ).toLowerCase(); … … 221 220 return false; 222 221 223 222 var def = this._.definition, 224 attribs; 223 attribs, 224 styles; 225 225 226 226 // If the element name is the same as the style name. 227 227 if ( element.getName() == this.element ) … … 260 260 } 261 261 262 262 // Check if the element can be somehow overriden. 263 var override = getOverrides( this )[ element.getName() ] ; 263 var overrides = getOverrides( this ), 264 override = overrides[ element.getName() ]|| overrides["*"]; 264 265 if ( override ) 265 266 { 266 267 // If no attributes have been defined, remove the element. 267 if ( !( attribs = override.attributes ) )268 if ( !( attribs = override.attributes ) && !(styles = override.styles)) 268 269 return true; 270 if(attribs) 271 { 272 for ( i = 0 ; i < attribs.length ; i++ ) 273 { 274 attName = attribs[i][0]; 275 var actualAttrValue = element.getAttribute( attName ); 276 if ( actualAttrValue ) 277 { 278 var attValue = attribs[i][1]; 269 279 270 for ( var i = 0 ; i < attribs.length ; i++ ) 271 { 272 attName = attribs[i][0]; 273 var actualAttrValue = element.getAttribute( attName ); 274 if ( actualAttrValue ) 275 { 276 var attValue = attribs[i][1]; 280 // Remove the attribute if: 281 // - The override definition value is null; 282 // - The override definition value is a string that 283 // matches the attribute value exactly. 284 // - The override definition value is a regex that 285 // has matches in the attribute value. 286 if ( attValue === null || 287 ( typeof attValue == 'string' && actualAttrValue == attValue ) || 288 attValue.test( actualAttrValue ) ) 289 return true; 290 } 291 } 292 } 293 if(styles) 294 { 295 for ( var i = 0 ; i < styles.length ; i++ ) 296 { 297 var styleName = styles[i][0]; 298 var actualStyleValue = element.getStyle( styleName ); 299 if ( actualStyleValue ) 300 { 301 var styleValue = styles[i][1]; 277 302 278 // Remove the attribute if: 279 // - The override definition value is null; 280 // - The override definition value is a string that 281 // matches the attribute value exactly. 282 // - The override definition value is a regex that 283 // has matches in the attribute value. 284 if ( attValue === null || 285 ( typeof attValue == 'string' && actualAttrValue == attValue ) || 286 attValue.test( actualAttrValue ) ) 287 return true; 288 } 289 } 303 304 if ( styleValue === null || 305 ( typeof styleValue == 'string' && actualStyleValue == attValue ) || 306 styleValue.test && styleValue.test( actualStyleValue ) ) 307 return true; 308 } 309 } 310 } 290 311 } 291 312 return false; 292 313 }, … … 1063 1084 function removeFromElement( style, element ) 1064 1085 { 1065 1086 var def = style._.definition, 1066 attributes = CKEDITOR.tools.extend( {}, def.attributes, getOverrides( style )[ element.getName() ] ), 1067 styles = def.styles, 1087 overrides = getOverrides( style ), 1088 override = overrides[ element.getName() ] || overrides[ "*" ] || {}, 1089 attributes = CKEDITOR.tools.extend( {}, def.attributes, override.attributes ), 1090 styles = CKEDITOR.tools.extend( {}, def.styles, override.styles ), 1068 1091 // If the style is only about the element itself, we have to remove the element. 1069 1092 removeEmpty = CKEDITOR.tools.isEmpty( attributes ) && CKEDITOR.tools.isEmpty( styles ); 1070 1093 1071 1094 // Remove definition attributes/style from the elemnt. 1072 1095 for ( var attName in attributes ) 1073 1096 { 1097 if( !attributes.hasOwnProperty( attName ) ) continue; 1074 1098 // The 'class' element value must match (#1318). 1075 1099 if ( ( attName == 'class' || style._.definition.fullMatch ) 1076 1100 && element.getAttribute( attName ) != normalizeProperty( attName, attributes[ attName ] ) ) … … 1081 1105 1082 1106 for ( var styleName in styles ) 1083 1107 { 1108 if( !styles.hasOwnProperty( styleName ) ) continue; 1084 1109 // Full match style insist on having fully equivalence. (#5018) 1085 1110 if ( style._.definition.fullMatch 1086 1111 && element.getStyle( styleName ) != normalizeProperty( styleName, styles[ styleName ], true ) ) … … 1097 1122 function removeFromInsideElement( style, element ) 1098 1123 { 1099 1124 var def = style._.definition, 1100 attribs = def.attributes, 1101 styles = def.styles, 1125 1102 1126 overrides = getOverrides( style ); 1103 1127 1104 1128 var innerElements = element.getElementsByTag( style.element ); … … 1157 1181 } 1158 1182 } 1159 1183 1184 var styles = overrides && overrides.styles ; 1185 1186 if ( styles ) 1187 { 1188 for ( var i = 0 ; i < styles.length ; i++ ) 1189 { 1190 var styleName = styles[i][0], actualStyleValue ; 1191 1192 if ( ( actualStyleValue = element.getStyle( styleName ) ) ) 1193 { 1194 var styleValue = styles[i][1] ; 1195 1196 1197 if ( styleValue === null || 1198 ( styleValue.test && styleValue.test( actualStyleValue ) ) || 1199 ( typeof styleValue == 'string' && actualStyleValue == styleValue ) ) 1200 element.removeStyle( styleName ) ; 1201 } 1202 } 1203 } 1204 1160 1205 removeNoAttribsElement( element ); 1161 1206 } 1162 1207 … … 1243 1288 { 1244 1289 for ( var item in list ) 1245 1290 { 1246 list[ item ] = list[ item ].replace( varRegex, function( match, varName ) 1291 if (!list.hasOwnProperty(item)) continue; 1292 if(typeof list[ item ]==='string') 1293 { 1294 list[ item ] = list[ item ].replace( varRegex, function( match, varName ) 1247 1295 { 1248 1296 return variablesValues[ varName ]; 1249 1297 }); 1298 } 1299 else 1300 { 1301 replaceVariables(list[ item ],variablesValues); 1302 } 1303 1250 1304 } 1251 1305 } 1252 1306 … … 1320 1374 var elementName; 1321 1375 var overrideEl; 1322 1376 var attrs; 1377 //consider overrides's style 1378 var styles; 1323 1379 1324 1380 // If can be a string with the element name. 1325 1381 if ( typeof override == 'string' ) … … 1329 1385 { 1330 1386 elementName = override.element ? override.element.toLowerCase() : style.element; 1331 1387 attrs = override.attributes; 1388 styles = override.styles; 1332 1389 } 1333 1390 1334 1391 // We can have more than one override definition for the same … … 1350 1407 overrideAttrs.push( [ attName.toLowerCase(), attrs[ attName ] ] ); 1351 1408 } 1352 1409 } 1410 1411 // note : consider override's style 1412 if ( styles ) 1413 { 1414 var overrideStyles = ( overrideEl.styles = overrideEl.styles || [] ); 1415 for ( var styleName in styles ) 1416 { 1417 overrideStyles.push( [ styleName.toLowerCase(), styles[ styleName ] ] ); 1418 } 1419 } 1353 1420 } 1354 1421 } 1355 1422