X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fpastefromword%2Ffilter%2Fdefault.js;h=e29d1c5e22dc38d3ef8b8fa4e268a83f41ff8759;hb=039a051ccf3901311661022a30afd60fc38130c9;hp=745bda36cd1d3190cf186022f09072c1e4426a58;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6;p=ckeditor.git diff --git a/_source/plugins/pastefromword/filter/default.js b/_source/plugins/pastefromword/filter/default.js index 745bda3..e29d1c5 100644 --- a/_source/plugins/pastefromword/filter/default.js +++ b/_source/plugins/pastefromword/filter/default.js @@ -25,7 +25,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license for ( var i = 0; i < children.length; i++ ) { child = children[ i ]; - if( !child.name ) + if ( !child.name ) continue; if ( child.name == tagName ) @@ -60,15 +60,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license child = child.firstChild( evaluator ); if ( child ) return child; - else - continue; } } return null; }; - // Adding a (set) of styles to the element's attributes. + // Adding a (set) of styles to the element's 'style' attributes. elementPrototype.addStyle = function( name, value, isPrepend ) { var styleText, addingStyleText = ''; @@ -80,9 +78,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // style literal. if ( typeof name == 'object' ) { - for( var style in name ) + for ( var style in name ) { - if( name.hasOwnProperty( style ) ) + if ( name.hasOwnProperty( style ) ) addingStyleText += style + ':' + name[ style ] + ';'; } } @@ -93,7 +91,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license isPrepend = value; } - if( !this.attributes ) + if ( !this.attributes ) this.attributes = {}; styleText = this.attributes.style || ''; @@ -120,8 +118,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return result; }; - var cssLengthRelativeUnit = /^(\d[.\d]*)+(em|ex|px|gd|rem|vw|vh|vm|ch|mm|cm|in|pt|pc|deg|rad|ms|s|hz|khz){1}?/i; - var emptyMarginRegex = /^(?:\b0[^\s]*\s*){1,4}$/; + var cssLengthRelativeUnit = /^([.\d]*)+(em|ex|px|gd|rem|vw|vh|vm|ch|mm|cm|in|pt|pc|deg|rad|ms|s|hz|khz){1}?/i; + var emptyMarginRegex = /^(?:\b0[^\s]*\s*){1,4}$/; // e.g. 0px 0pt 0px var listBaseIndent = 0, previousListItemMargin; @@ -161,11 +159,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } else { - if ( /[l\u00B7\u2002]/.test( bulletStyle[ 1 ] ) ) //l·• + if ( /[l\u00B7\u2002]/.test( bulletStyle[ 1 ] ) ) bulletStyle = 'disc'; - else if ( /[\u006F\u00D8]/.test( bulletStyle[ 1 ] ) ) //oØ + else if ( /[\u006F\u00D8]/.test( bulletStyle[ 1 ] ) ) bulletStyle = 'circle'; - else if ( /[\u006E\u25C6]/.test( bulletStyle[ 1 ] ) ) //n◆ + else if ( /[\u006E\u25C6]/.test( bulletStyle[ 1 ] ) ) bulletStyle = 'square'; else bulletStyle = 'disc'; @@ -186,7 +184,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license isListBulletIndicator : function( element ) { var styleText = element.attributes && element.attributes.style; - if( /mso-list\s*:\s*Ignore/i.test( styleText ) ) + if ( /mso-list\s*:\s*Ignore/i.test( styleText ) ) return true; }, @@ -200,8 +198,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license resolveList : function( element ) { // indicate a list item. - var children = element.children, - attrs = element.attributes, + var attrs = element.attributes, listMarker; if ( ( listMarker = element.removeAnyChildWithName( 'cke:listbullet' ) ) @@ -222,7 +219,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { // Be able to deal with component/short-hand form style. var values = margin.split( ' ' ); - margin = values[ 3 ] || values[ 1 ] || values [ 0 ]; + margin = CKEDITOR.plugins.pastefromword.utils.convertToPx( values[ 3 ] || values[ 1 ] || values [ 0 ] ); margin = parseInt( margin, 10 ); // Figure out the indent unit by looking at the first increament. @@ -257,7 +254,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return function( cssLength ) { - if( cssLengthRelativeUnit.test( cssLength ) ) + if ( cssLengthRelativeUnit.test( cssLength ) ) { calculator.setStyle( 'width', cssLength ); return calculator.$.clientWidth + 'px'; @@ -328,14 +325,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license child = children[ i ]; var attributes = child.attributes; - if( child.name in CKEDITOR.dtd.$listItem ) + if ( child.name in CKEDITOR.dtd.$listItem ) { var listItemChildren = child.children, count = listItemChildren.length, last = listItemChildren[ count - 1 ]; // Move out nested list. - if( last.name in CKEDITOR.dtd.$list ) + if ( last.name in CKEDITOR.dtd.$list ) { children.splice( i + 1, 0, last ); last.parent = element; @@ -420,8 +417,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { // There might be a negative gap between two list levels. (#4944) var diff = indent - listItemIndent, - parent = list.parent; - while( diff-- && parent ) + parent; + while ( diff-- && ( parent = list.parent ) ) list = parent.parent; list.add( listItem ); @@ -477,9 +474,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license valuePattern, newValue, newName; - for( var i = 0 ; i < styles.length; i++ ) + for ( var i = 0 ; i < styles.length; i++ ) { - if( styles[ i ] ) + if ( styles[ i ] ) { namePattern = styles[ i ][ 0 ]; valuePattern = styles[ i ][ 1 ]; @@ -492,15 +489,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license name = newName || name; whitelist && ( newValue = newValue || value ); - if( typeof newValue == 'function' ) + if ( typeof newValue == 'function' ) newValue = newValue( value, element, name ); // Return an couple indicate both name and value // changed. - if( newValue && newValue.push ) + if ( newValue && newValue.push ) name = newValue[ 0 ], newValue = newValue[ 1 ]; - if( typeof newValue == 'string' ) + if ( typeof newValue == 'string' ) rules.push( [ name, newValue ] ); return; } @@ -567,7 +564,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license */ bogusAttrFilter : function( value, element ) { - if( element.name.indexOf( 'cke:' ) == -1 ) + if ( element.name.indexOf( 'cke:' ) == -1 ) return false; }, @@ -589,7 +586,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license stylesFilter = filters.stylesFilter, elementMigrateFilter = filters.elementMigrateFilter, styleMigrateFilter = CKEDITOR.tools.bind( this.filters.styleMigrateFilter, this.filters ), - bogusAttrFilter = filters.bogusAttrFilter, createListBulletMarker = this.utils.createListBulletMarker, flattenList = filters.flattenList, assembleList = filters.assembleList, @@ -645,7 +641,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { element.filterChildren(); // Is the heading actually a list item? - if( resolveListItem( element ) ) + if ( resolveListItem( element ) ) return; // Adapt heading styles to editor's convention. @@ -720,12 +716,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license className = className.substring( 1, className.length ); // Reject MS-Word Normal styles. - if( className.match( /MsoNormal/ ) ) + if ( className.match( /MsoNormal/ ) ) return; - if( !rules[ tagName ] ) + if ( !rules[ tagName ] ) rules[ tagName ] = {}; - if( className ) + if ( className ) rules[ tagName ][ className ] = styleBlock; else rules[ tagName ] = styleBlock; @@ -738,10 +734,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var name = rules[ '*' ] ? '*' : element.name, className = element.attributes && element.attributes[ 'class' ], style; - if( name in rules ) + if ( name in rules ) { style = rules[ name ]; - if( typeof style == 'object' ) + if ( typeof style == 'object' ) style = style[ className ]; // Maintain style rules priorities. style && element.addStyle( style, true ); @@ -756,10 +752,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { element.filterChildren(); - var attrs = element.attributes, - parent = element.parent, - children = element.children; - // Is the paragraph actually a list item? if ( resolveListItem( element ) ) return; @@ -782,7 +774,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // table cells inherit as text-align styles, which is wrong. // Instead we use a clear-float div after the table to properly achieve the same layout. var singleChild = element.onlyChild(); - if( singleChild && singleChild.name == 'table' ) + if ( singleChild && singleChild.name == 'table' ) { var attrs = element.attributes; singleChild.attributes = CKEDITOR.tools.extend( singleChild.attributes, attrs ); @@ -829,7 +821,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license element.attributes ); styleText && parent.addStyle( styleText ); delete element.name; - return; } // Convert the merged into a span with all attributes preserved. else @@ -924,7 +915,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license 'a' : function( element ) { var attrs = element.attributes; - if( attrs && !attrs.href && attrs.name ) + if ( attrs && !attrs.href && attrs.name ) delete element.name; }, 'cke:listbullet' : function( element ) @@ -983,14 +974,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license [ ( /^border.*|margin.*|vertical-align|float$/ ), null, function( value, element ) { - if( element.name == 'img' ) + if ( element.name == 'img' ) return value; } ], [ (/^width|height$/ ), null, function( value, element ) { - if( element.name in { table : 1, td : 1, th : 1, img : 1 } ) + if ( element.name in { table : 1, td : 1, th : 1, img : 1 } ) return value; } ] ] : @@ -1000,9 +991,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Fixing color values. [ ( /-color$/ ), null, function( value ) { - if( value == 'transparent' ) + if ( value == 'transparent' ) return false; - if( CKEDITOR.env.gecko ) + if ( CKEDITOR.env.gecko ) return value.replace( /-moz-use-text-color/g, 'transparent' ); } ], // Remove empty margin values, e.g. 0.00001pt 0em 0pt @@ -1017,13 +1008,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Prefer width styles over 'width' attributes. 'width' : function( value, element ) { - if( element.name in dtd.$tableContent ) + if ( element.name in dtd.$tableContent ) return false; }, // Prefer border styles over table 'border' attributes. 'border' : function( value, element ) { - if( element.name in dtd.$tableContent ) + if ( element.name in dtd.$tableContent ) return false; }, @@ -1064,7 +1055,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } // Reveal the element in conditional comments for Firefox. - if( CKEDITOR.env.gecko && imageInfo ) + if ( CKEDITOR.env.gecko && imageInfo ) { var img = CKEDITOR.htmlParser.fragment.fromHtml( imageInfo[ 0 ] ).children[ 0 ], previousComment = node.previous, @@ -1107,7 +1098,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Firefox will be confused by those downlevel-revealed IE conditional // comments, fixing them first( convert it to upperlevel-revealed one ). // e.g. ... - if( CKEDITOR.env.gecko ) + if ( CKEDITOR.env.gecko ) data = data.replace( /(([\S\s]*?))/gi, '$1$2$3' ); var dataProcessor = new pasteProcessor(), @@ -1144,11 +1135,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license })(); /** - * Whether the ignore all font-related format styles, including: - * - font size; - * - font family; - * - font fore/background color; + * Whether to ignore all font related formatting styles, including: + * * @name CKEDITOR.config.pasteFromWordRemoveFontStyles + * @since 3.1 * @type Boolean * @default true * @example @@ -1156,8 +1148,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license */ /** - * Whether transform MS-Word Outline Numbered Heading into html list. + * Whether to transform MS Word outline numbered headings into lists. * @name CKEDITOR.config.pasteFromWordNumberedHeadingToList + * @since 3.1 * @type Boolean * @default false * @example @@ -1165,10 +1158,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license */ /** - * Whether remove element styles that can't be managed with editor, note that this - * this doesn't handle the font-specific styles, which depends on - * how {@link CKEDITOR.config.pasteFromWordRemoveFontStyles} is configured. + * Whether to remove element styles that can't be managed with the editor. Note + * that this doesn't handle the font specific styles, which depends on the + * {@link CKEDITOR.config.pasteFromWordRemoveFontStyles} setting instead. * @name CKEDITOR.config.pasteFromWordRemoveStyles + * @since 3.1 * @type Boolean * @default true * @example