X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2Fpackagist%2Fpiedsjaloux-ckeditor-component.git;a=blobdiff_plain;f=sources%2Fcore%2Ffilter.js;fp=sources%2Fcore%2Ffilter.js;h=3e64fc5b0dbb4f6d164c089708d44c49f34eff11;hp=e9d5a374e3287f7b6b95861b2f9290621e809210;hb=317f8f8f0651488f226b5280a8f036c7c135c639;hpb=1096cdefb1c9a3f3c4ca6807e272da6c92e5ed9c diff --git a/sources/core/filter.js b/sources/core/filter.js index e9d5a37..3e64fc5 100644 --- a/sources/core/filter.js +++ b/sources/core/filter.js @@ -1,5 +1,5 @@ /** - * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. + * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license */ @@ -158,7 +158,8 @@ }, // Object: element name => array of transformations groups. transformations: {}, - cachedTests: {} + cachedTests: {}, + cachedChecks: {} }; // Register filter instance. @@ -299,7 +300,7 @@ if ( el.attributes[ 'data-cke-filter' ] == 'off' ) return false; - // (#10260) Don't touch elements like spans with data-cke-* attribute since they're + // (http://dev.ckeditor.com/ticket/10260) Don't touch elements like spans with data-cke-* attribute since they're // responsible e.g. for placing markers, bookmarks, odds and stuff. // We love 'em and we don't wanna lose anything during the filtering. // '|' is to avoid tricky joints like data-="foo" + cke-="bar". Yes, they're possible. @@ -346,7 +347,7 @@ if ( !element.parent ) continue; - // Handle custom elements as inline elements (#12683). + // Handle custom elements as inline elements (http://dev.ckeditor.com/ticket/12683). parentDtd = DTD[ element.parent.name ] || DTD.span; switch ( check.check ) { @@ -805,6 +806,32 @@ }; } )(), + /** + * Returns a clone of this filter instance. + * + * @since 4.7.3 + * @returns {CKEDITOR.filter} + */ + clone: function() { + var ret = new CKEDITOR.filter(), + clone = CKEDITOR.tools.clone; + + // Cloning allowed content related things. + ret.allowedContent = clone( this.allowedContent ); + ret._.allowedRules = clone( this._.allowedRules ); + + // Disallowed content rules. + ret.disallowedContent = clone( this.disallowedContent ); + ret._.disallowedRules = clone( this._.disallowedRules ); + + ret._.transformations = clone( this._.transformations ); + + ret.disabled = this.disabled; + ret.editor = this.editor; + + return ret; + }, + /** * Destroys the filter instance and removes it from the global {@link CKEDITOR.filter#instances} object. * @@ -1248,22 +1275,20 @@ styles = styleDef.styles, attrs = styleDef.attributes || {}; - if ( styles ) { + if ( styles && !CKEDITOR.tools.isEmpty( styles ) ) { styles = copy( styles ); attrs.style = CKEDITOR.tools.writeCssText( styles, true ); } else { styles = {}; } - var el = { + return { name: styleDef.element, attributes: attrs, classes: attrs[ 'class' ] ? attrs[ 'class' ].split( /\s+/ ) : [], styles: styles, children: [] }; - - return el; } // Mock hash based on string. @@ -1873,6 +1898,7 @@ // // TRANSFORMATIONS -------------------------------------------------------- // + var transformationsTools; // Apply given transformations group to the element. function applyTransformationsGroup( filter, element, group ) { @@ -2021,7 +2047,7 @@ * @class CKEDITOR.filter.transformationsTools * @singleton */ - var transformationsTools = CKEDITOR.filter.transformationsTools = { + transformationsTools = CKEDITOR.filter.transformationsTools = { /** * Converts `width` and `height` attributes to styles. * @@ -2070,8 +2096,8 @@ * Converts length in the `styleName` style to a valid length attribute (like `width` or `height`). * * @param {CKEDITOR.htmlParser.element} element - * @param {String} styleName Name of the style that will be converted. - * @param {String} [attrName=styleName] Name of the attribute into which the style will be converted. + * @param {String} styleName The name of the style that will be converted. + * @param {String} [attrName=styleName] The name of the attribute into which the style will be converted. */ lengthToAttribute: function( element, styleName, attrName ) { attrName = attrName || styleName; @@ -2091,7 +2117,7 @@ }, /** - * Converts the `align` attribute to the `float` style if not set. Attribute + * Converts the `align` attribute to the `float` style if not set. The attribute * is always removed. * * @param {CKEDITOR.htmlParser.element} element @@ -2109,7 +2135,7 @@ /** * Converts the `float` style to the `align` attribute if not set. - * Style is always removed. + * The style is always removed. * * @param {CKEDITOR.htmlParser.element} element */ @@ -2124,6 +2150,107 @@ delete element.styles[ 'float' ]; // Uh... GCC doesn't like the 'float' prop name. }, + /** + * Converts the shorthand form of the `border` style to seperate styles. + * + * @param {CKEDITOR.htmlParser.element} element + */ + splitBorderShorthand: function( element ) { + if ( !element.styles.border ) { + return; + } + + var widths = element.styles.border.match( /([\.\d]+\w+)/g ) || [ '0px' ]; + switch ( widths.length ) { + case 1: + element.styles[ 'border-width' ] = widths[0]; + break; + case 2: + mapStyles( [ 0, 1, 0, 1 ] ); + break; + case 3: + mapStyles( [ 0, 1, 2, 1 ] ); + break; + case 4: + mapStyles( [ 0, 1, 2, 3 ] ); + break; + } + + element.styles[ 'border-style' ] = element.styles[ 'border-style' ] || + ( element.styles.border.match( /(none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset|initial|inherit)/ ) || [] )[ 0 ]; + if ( !element.styles[ 'border-style' ] ) + delete element.styles[ 'border-style' ]; + + delete element.styles.border; + + function mapStyles( map ) { + element.styles['border-top-width'] = widths[ map[0] ]; + element.styles['border-right-width'] = widths[ map[1] ]; + element.styles['border-bottom-width'] = widths[ map[2] ]; + element.styles['border-left-width'] = widths[ map[3] ]; + } + }, + + listTypeToStyle: function( element ) { + if ( element.attributes.type ) { + switch ( element.attributes.type ) { + case 'a': + element.styles[ 'list-style-type' ] = 'lower-alpha'; + break; + case 'A': + element.styles[ 'list-style-type' ] = 'upper-alpha'; + break; + case 'i': + element.styles[ 'list-style-type' ] = 'lower-roman'; + break; + case 'I': + element.styles[ 'list-style-type' ] = 'upper-roman'; + break; + case '1': + element.styles[ 'list-style-type' ] = 'decimal'; + break; + default: + element.styles[ 'list-style-type' ] = element.attributes.type; + } + } + }, + + /** + * Converts the shorthand form of the `margin` style to seperate styles. + * + * @param {CKEDITOR.htmlParser.element} element + */ + splitMarginShorthand: function( element ) { + if ( !element.styles.margin ) { + return; + } + + var widths = element.styles.margin.match( /(\-?[\.\d]+\w+)/g ) || [ '0px' ]; + switch ( widths.length ) { + case 1: + mapStyles( [ 0, 0, 0, 0 ] ); + break; + case 2: + mapStyles( [ 0, 1, 0, 1 ] ); + break; + case 3: + mapStyles( [ 0, 1, 2, 1 ] ); + break; + case 4: + mapStyles( [ 0, 1, 2, 3 ] ); + break; + } + + delete element.styles.margin; + + function mapStyles( map ) { + element.styles['margin-top'] = widths[ map[0] ]; + element.styles['margin-right'] = widths[ map[1] ]; + element.styles['margin-bottom'] = widths[ map[2] ]; + element.styles['margin-left'] = widths[ map[3] ]; + } + }, + /** * Checks whether an element matches a given {@link CKEDITOR.style}. * The element can be a "superset" of a style, e.g. it may have @@ -2135,12 +2262,12 @@ matchesStyle: elementMatchesStyle, /** - * Transforms element to given form. + * Transforms an element to a given form. * * Form may be a: * * * {@link CKEDITOR.style}, - * * string – the new name of an element. + * * string – the new name of the element. * * @param {CKEDITOR.htmlParser.element} el * @param {CKEDITOR.style/String} form @@ -2191,7 +2318,7 @@ * * {@link CKEDITOR.filter.allowedContentRules} – defined rules will be added * to the {@link CKEDITOR.editor#filter}. * * `true` – will disable the filter (data will not be filtered, - * all features will be activated). + * all features will be activated). Reading [security best practices](#!/guide/dev_best_practices) before setting `true` is recommended. * * default – the filter will be configured by loaded features * (toolbar items, commands, etc.). *