Changeset 3378
- Timestamp:
- 04/13/09 06:43:27 (4 years ago)
- File:
-
- 1 edited
-
CKEditor/trunk/_source/plugins/styles/plugin.js (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
CKEditor/trunk/_source/plugins/styles/plugin.js
r3377 r3378 183 183 attribs; 184 184 185 // If no attributes are defined in the element. 186 if ( !fullMatch && !element.hasAttributes() ) 187 return true; 188 189 attribs = getAttributesForComparison( def ); 190 191 if ( attribs._length ) 192 { 193 for ( var attName in attribs ) 194 { 195 if ( attName == '_length' ) 196 continue; 197 198 if ( compareAttributeValues( attName, attribs[ attName ], element.getAttribute( attName ) ) ) 185 // If the element name is the same as the style name. 186 if ( element.getName() == this.element ) 187 { 188 // If no attributes are defined in the element. 189 if ( !fullMatch && !element.hasAttributes() ) 190 return true; 191 192 attribs = getAttributesForComparison( def ); 193 194 if ( attribs._length ) 195 { 196 for ( var attName in attribs ) 199 197 { 200 if ( !fullMatch ) 201 return true; 198 if ( attName == '_length' ) 199 continue; 200 201 if ( compareAttributeValues(attName, attribs[attName], element.getAttribute( attName ) ) ) 202 { 203 if ( !fullMatch ) 204 return true; 205 } 206 else if ( fullMatch ) 207 return false; 202 208 } 203 else if ( fullMatch )204 return false;205 }206 } 207 209 } 210 else 211 return true; 212 } 213 208 214 // Check if the element can be somehow overriden. 209 var override = this.getOverrides()[ element.getName() ] ;215 var override = getOverrides( this )[ element.getName() ] ; 210 216 if ( override ) 211 217 { … … 214 220 return true; 215 221 216 for ( var i = 0 ; i < attribs.length; i++ )222 for ( var i = 0 ; i < attribs.length ; i++ ) 217 223 { 218 224 var attName = attribs[i][0], actualAttrValue; … … 234 240 } 235 241 } 236 237 }, 238 239 /** 240 * Get the the collection used to compare the elements and attributes, 241 * defined in this style overrides, with other element. All information in 242 * it is lowercased. 243 */ 244 getOverrides: function() 245 { 246 var overrides = {}, 247 definition = this._.definition.overrides; 248 249 if ( definition ) 250 { 251 // The override description can be a string, object or array. 252 // Internally, well handle arrays only, so transform it if needed. 253 if ( !CKEDITOR.tools.isArray( definition ) ) 254 definition = [ definition ]; 255 256 // Loop through all override definitions. 257 for ( var i = 0; i < definition.length; i++ ) 258 { 259 var override = definition[i]; 260 var elementName; 261 var overrideEl; 262 var attrs; 263 264 // If can be a string with the element name. 265 if ( typeof override == 'string' ) 266 elementName = override.toLowerCase(); 267 // Or an object. 268 else 269 { 270 elementName = override.element ? override.element.toLowerCase() : this.element; 271 attrs = override.attributes; 272 } 273 274 // We can have more than one override definition for the same 275 // element name, so we attempt to simply append information to 276 // it if it already exists. 277 overrideEl = overrides[ elementName ] || ( overrides[ elementName ] = {} ); 278 279 if ( attrs ) 280 { 281 // The returning attributes list is an array, because we 282 // could have different override definitions for the same 283 // attribute name. 284 var overrideAttrs = ( overrideEl.attributes = overrideEl.attributes || new Array() ); 285 for ( var attName in attrs ) 286 { 287 // Each item in the attributes array is also an array, 288 // where [0] is the attribute name and [1] is the 289 // override value. 290 overrideAttrs.push( [ attName.toLowerCase(), attrs[ attName ] ] ); 291 } 292 } 293 } 294 } 295 296 // Cache the overrides resolution. 297 return ( this.getOverrides = function(){ 298 return overrides; 299 } )(); 300 } 301 242 return false; 243 } 302 244 }; 303 245 … … 576 518 */ 577 519 var startPath = new CKEDITOR.dom.elementPath( startNode.getParent() ); 578 for ( var i = 0, element ; i < startPath.elements.length && ( element = startPath.elements[i] ) ; i++ )520 for ( var i = 0, element ; i < startPath.elements.length && ( element = startPath.elements[i] ) ; i++ ) 579 521 { 580 522 if ( element == startPath.block || element == startPath.blockLimit ) … … 613 555 breakStart = null, 614 556 breakEnd = null; 615 for ( var i = 0 ; i < startPath.elements.length; i++ )557 for ( var i = 0 ; i < startPath.elements.length ; i++ ) 616 558 { 617 559 var element = startPath.elements[ i ]; … … 623 565 breakStart = element; 624 566 } 625 for ( i = 0 ; i < endPath.elements.length; i++ )567 for ( i = 0 ; i < endPath.elements.length ; i++ ) 626 568 { 627 569 element = endPath.elements[ i ]; … … 656 598 removeFromElement( this, currentNode ); 657 599 else 658 removeOverrides( currentNode, this.getOverrides()[ currentNode.getName() ] );600 removeOverrides( currentNode, getOverrides( this )[ currentNode.getName() ] ); 659 601 660 602 /* … … 717 659 // { 718 660 // if ( previousPreBlock ) 719 // this._CheckAndMergePre( previousPreBlock, newBlock ) ; // Merge successive <pre> blocks.661 // this._CheckAndMergePre( previousPreBlock, newBlock ) ; // Merge successive <pre> blocks. 720 662 // previousPreBlock = newBlock; 721 663 // } 722 664 // else if ( fromPre ) 723 // this._CheckAndSplitPre( newBlock ) ; // Split <br><br> in successive <pre>s.665 // this._CheckAndSplitPre( newBlock ) ; // Split <br><br> in successive <pre>s. 724 666 } 725 667 … … 733 675 attributes = def.attributes, 734 676 styles = def.styles, 735 overrides = style.getOverrides(); 736 737 for ( var attName in attributes ) 738 { 739 // The 'class' element value must match (#1318). 740 if ( attName == 'class' && element.getAttribute( attName ) != attributes[ attName ] ) 741 continue; 742 element.removeAttribute( attName ); 743 } 744 745 for ( var styleName in styles ) 746 element.removeStyle( styleName ); 747 748 // Now scan override styles on the element. 749 attributes = overrides[ element.getName() ]; 750 if( attributes ) 751 { 752 for( attName in attributes ) 677 overrides = getOverrides( style ); 678 679 function removeAttrs() 680 { 681 for ( var attName in attributes ) 753 682 { 754 683 // The 'class' element value must match (#1318). … … 758 687 } 759 688 } 689 690 // Remove definition attributes/style from the elemnt. 691 removeAttrs(); 692 for ( var styleName in styles ) 693 element.removeStyle( styleName ); 694 695 // Now remove override styles on the element. 696 attributes = overrides[ element.getName() ]; 697 if( attributes ) 698 removeAttrs(); 760 699 removeNoAttribsElement( element ); 761 700 } … … 767 706 attribs = def.attributes, 768 707 styles = def.styles, 769 overrides = style.getOverrides();708 overrides = getOverrides( style ); 770 709 771 710 var innerElements = element.getElementsByTag( style.element ); 772 711 773 for ( var i = innerElements.count(); --i >= 0 ; )712 for ( var i = innerElements.count(); --i >= 0 ; ) 774 713 removeFromElement( style, innerElements.getItem( i ) ); 775 714 … … 781 720 { 782 721 var innerElements = element.getElementsByTag( overrideElement ) ; 783 for ( var i = innerElements.count() - 1 ; i >= 0 ; i-- )722 for ( var i = innerElements.count() - 1 ; i >= 0 ; i-- ) 784 723 { 785 724 var innerElement = innerElements.getItem( i ); … … 985 924 return ( styleDefinition._AC = attribs ); 986 925 } 926 927 /** 928 * Get the the collection used to compare the elements and attributes, 929 * defined in this style overrides, with other element. All information in 930 * it is lowercased. 931 * @param {CKEDITOR.style} style 932 */ 933 function getOverrides( style ) 934 { 935 if( style._.overrides ) 936 return style._.overrides; 937 938 var overrides = ( style._.overrides = {} ), 939 definition = style._.definition.overrides; 940 941 if ( definition ) 942 { 943 // The override description can be a string, object or array. 944 // Internally, well handle arrays only, so transform it if needed. 945 if ( !CKEDITOR.tools.isArray( definition ) ) 946 definition = [ definition ]; 947 948 // Loop through all override definitions. 949 for ( var i = 0 ; i < definition.length ; i++ ) 950 { 951 var override = definition[i]; 952 var elementName; 953 var overrideEl; 954 var attrs; 955 956 // If can be a string with the element name. 957 if ( typeof override == 'string' ) 958 elementName = override.toLowerCase(); 959 // Or an object. 960 else 961 { 962 elementName = override.element ? override.element.toLowerCase() : style.element; 963 attrs = override.attributes; 964 } 965 966 // We can have more than one override definition for the same 967 // element name, so we attempt to simply append information to 968 // it if it already exists. 969 overrideEl = overrides[ elementName ] || ( overrides[ elementName ] = {} ); 970 971 if ( attrs ) 972 { 973 // The returning attributes list is an array, because we 974 // could have different override definitions for the same 975 // attribute name. 976 var overrideAttrs = ( overrideEl.attributes = overrideEl.attributes || new Array() ); 977 for ( var attName in attrs ) 978 { 979 // Each item in the attributes array is also an array, 980 // where [0] is the attribute name and [1] is the 981 // override value. 982 overrideAttrs.push( [ attName.toLowerCase(), attrs[ attName ] ] ); 983 } 984 } 985 } 986 } 987 988 return overrides; 989 } 987 990 988 991 function normalizeCssText( unparsedCssText ) … … 1025 1028 1026 1029 // Apply the style to the ranges. 1027 for ( var i = 0 ; i < ranges.length; i++ )1030 for ( var i = 0 ; i < ranges.length ; i++ ) 1028 1031 func.call( this, ranges[ i ] ); 1029 1032
Note: See TracChangeset
for help on using the changeset viewer.
