185 | | // If no attributes are defined in the element. |
186 | | if ( !fullMatch && !element.hasAttributes() ) |
187 | | return true; |
188 | | |
189 | | attribs = getAttributesForComparison( def ); |
| 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 ) |
| 197 | { |
| 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; |
| 208 | } |
| 209 | } |
| 210 | else |
| 211 | return true; |
| 212 | } |
200 | | if ( !fullMatch ) |
| 227 | var attValue = attribs[i][1]; |
| 228 | |
| 229 | // Remove the attribute if: |
| 230 | // - The override definition value is null; |
| 231 | // - The override definition valie is a string that |
| 232 | // matches the attribute value exactly. |
| 233 | // - The override definition value is a regex that |
| 234 | // has matches in the attribute value. |
| 235 | if ( attValue == null || |
| 236 | ( typeof attValue == 'string' && actualAttrValue == attValue ) || |
| 237 | attValue.test( actualAttrValue ) ) |
640 | | for ( var attName in attributes ) |
641 | | { |
642 | | // The 'class' element value must match (#1318). |
643 | | if ( attName == 'class' && element.getAttribute( attName ) != attributes[ attName ] ) |
644 | | continue; |
645 | | element.removeAttribute( attName ); |
| 679 | function removeAttrs(){ |
| 680 | |
| 681 | for ( var attName in attributes ) |
| 682 | { |
| 683 | // The 'class' element value must match (#1318). |
| 684 | if ( attName == 'class' && element.getAttribute( attName ) != attributes[ attName ] ) |
| 685 | continue; |
| 686 | element.removeAttribute( attName ); |
| 687 | } |
663 | | for ( var i = innerElements.count() ; --i >= 0 ; ) |
664 | | removeFromElement( style, innerElements.getItem( i ) ); |
| 712 | for ( var i = innerElements.count(); --i >= 0 ; ) |
| 713 | removeFromElement( style, innerElements.getItem( i ) ); |
| 714 | |
| 715 | // Now remove any other element with different name that is |
| 716 | // defined to be overriden. |
| 717 | for ( var overrideElement in overrides ) |
| 718 | { |
| 719 | if ( overrideElement != style.element ) |
| 720 | { |
| 721 | var innerElements = element.getElementsByTag( overrideElement ) ; |
| 722 | for ( var i = innerElements.count() - 1 ; i >= 0 ; i-- ) |
| 723 | { |
| 724 | var innerElement = innerElements.getItem( i ); |
| 725 | removeOverrides( innerElement, overrides[ overrideElement ] ) ; |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
| 731 | |
| 732 | /** |
| 733 | * Remove overriding styles/attributes from the specific element. |
| 734 | * Note: Remove the element if no attributes remain. |
| 735 | * @param {Object} element |
| 736 | * @param {Object} overrides |
| 737 | */ |
| 738 | function removeOverrides( element, overrides ) |
| 739 | { |
| 740 | var attributes = overrides && overrides.attributes ; |
| 741 | |
| 742 | if ( attributes ) |
| 743 | { |
| 744 | for ( var i = 0 ; i < attributes.length ; i++ ) |
| 745 | { |
| 746 | var attName = attributes[i][0], actualAttrValue ; |
| 747 | |
| 748 | if ( actualAttrValue = element.getAttribute( attName ) ) |
| 749 | { |
| 750 | var attValue = attributes[i][1] ; |
| 752 | // Remove the attribute if: |
| 753 | // - The override definition value is null ; |
| 754 | // - The override definition valie is a string that |
| 755 | // matches the attribute value exactly. |
| 756 | // - The override definition value is a regex that |
| 757 | // has matches in the attribute value. |
| 758 | if ( attValue == null || |
| 759 | ( attValue.test && attValue.test( actualAttrValue ) ) || |
| 760 | ( typeof attValue == 'string' && actualAttrValue == attValue ) ) |
| 761 | element.removeAttribute( attName ) ; |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | removeNoAttribsElement( element ); |
| 767 | } |
| 768 | |
| 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 | var overrides = {}, |
| 936 | definition = style._.definition.overrides; |
| 937 | |
| 938 | if ( definition ) |
| 939 | { |
| 940 | // The override description can be a string, object or array. |
| 941 | // Internally, well handle arrays only, so transform it if needed. |
| 942 | if ( !CKEDITOR.tools.isArray( definition ) ) |
| 943 | definition = [ definition ]; |
| 944 | |
| 945 | // Loop through all override definitions. |
| 946 | for ( var i = 0 ; i < definition.length ; i++ ) |
| 947 | { |
| 948 | var override = definition[i]; |
| 949 | var elementName; |
| 950 | var overrideEl; |
| 951 | var attrs; |
| 952 | |
| 953 | // If can be a string with the element name. |
| 954 | if ( typeof override == 'string' ) |
| 955 | elementName = override.toLowerCase(); |
| 956 | // Or an object. |
| 957 | else |
| 958 | { |
| 959 | elementName = override.element ? override.element.toLowerCase() : style.element; |
| 960 | attrs = override.attributes; |
| 961 | } |
| 962 | |
| 963 | // We can have more than one override definition for the same |
| 964 | // element name, so we attempt to simply append information to |
| 965 | // it if it already exists. |
| 966 | overrideEl = overrides[ elementName ] || ( overrides[ elementName ] = {} ); |
| 967 | |
| 968 | if ( attrs ) |
| 969 | { |
| 970 | // The returning attributes list is an array, because we |
| 971 | // could have different override definitions for the same |
| 972 | // attribute name. |
| 973 | var overrideAttrs = ( overrideEl.attributes = overrideEl.attributes || new Array() ); |
| 974 | for ( var attName in attrs ) |
| 975 | { |
| 976 | // Each item in the attributes array is also an array, |
| 977 | // where [0] is the attribute name and [1] is the |
| 978 | // override value. |
| 979 | overrideAttrs.push( [ attName.toLowerCase(), attrs[ attName ] ] ); |
| 980 | } |
| 981 | } |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | // Cache the overrides resolution. |
| 986 | return ( arguments.callee = function(){ |
| 987 | return overrides; |
| 988 | } )(); |
| 989 | } |
| 990 | |