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