JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / plugins / pastefromword / filter / default.js
index dce3649..2eb948d 100644 (file)
@@ -261,8 +261,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        {\r
                                                                                // Deal with component/short-hand form.\r
                                                                                var values = margin.split( ' ' );\r
-                                                                               margin = plugin.utils.convertToPx( values[ 3 ] || values[ 1 ] || values [ 0 ] );\r
-                                                                               margin = parseInt( margin, 10 );\r
+                                                                               margin = CKEDITOR.tools.convertToPx( values[ 3 ] || values[ 1 ] || values [ 0 ] );\r
 \r
                                                                                // Figure out the indent unit by checking the first time of incrementation.\r
                                                                                if ( !listBaseIndent && previousListItemMargin !== null && margin > previousListItemMargin )\r
@@ -279,8 +278,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                var listId = Number( val[ 0 ].match( /\d+/ ) ),\r
                                                                                        indent = Number( val[ 1 ].match( /\d+/ ) );\r
 \r
-                                                                               listId !== previousListId && ( attrs[ 'cke:reset' ] = 1 );\r
-                                                                               previousListId = listId;\r
+                                                                               if ( indent == 1 )\r
+                                                                               {\r
+                                                                                       listId !== previousListId && ( attrs[ 'cke:reset' ] = 1 );\r
+                                                                                       previousListId = listId;\r
+                                                                               }\r
                                                                                attrs[ 'cke:indent' ] = indent;\r
                                                                        } ]\r
                                                                ] )( attrs.style, element ) || '';\r
@@ -307,27 +309,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                return false;\r
                        },\r
 \r
-                       // Convert various length units to 'px' in ignorance of DPI.\r
-                       convertToPx : ( function ()\r
-                       {\r
-                               var calculator = CKEDITOR.dom.element.createFromHtml(\r
-                                                               '<div style="position:absolute;left:-9999px;' +\r
-                                                               'top:-9999px;margin:0px;padding:0px;border:0px;"' +\r
-                                                               '></div>', CKEDITOR.document );\r
-                               CKEDITOR.document.getBody().append( calculator );\r
-\r
-                               return function( cssLength )\r
-                               {\r
-                                       if ( cssLengthRelativeUnit.test( cssLength ) )\r
-                                       {\r
-                                               calculator.setStyle( 'width', cssLength );\r
-                                               return calculator.$.clientWidth + 'px';\r
-                                       }\r
-\r
-                                       return cssLength;\r
-                               };\r
-                       } )(),\r
-\r
                        // Providing a shorthand style then retrieve one or more style component values.\r
                        getStyleComponents : ( function()\r
                        {\r
@@ -357,20 +338,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                // E.g. <ul><li>level1<ol><li>level2</li></ol></li> =>\r
                                // <cke:li cke:listtype="ul" cke:indent="1">level1</cke:li>\r
                                // <cke:li cke:listtype="ol" cke:indent="2">level2</cke:li>\r
-                               flattenList : function( element )\r
+                               flattenList : function( element, level )\r
                                {\r
-                                       var     attrs = element.attributes,\r
-                                               parent = element.parent;\r
-\r
-                                       var listStyleType,\r
-                                               indentLevel = 1;\r
+                                       level = typeof level == 'number' ? level : 1;\r
 \r
-                                       // Resolve how many level nested.\r
-                                       while ( parent )\r
-                                       {\r
-                                               parent.attributes && parent.attributes[ 'cke:list' ] && indentLevel++;\r
-                                               parent = parent.parent;\r
-                                       }\r
+                                       var     attrs = element.attributes,\r
+                                               listStyleType;\r
 \r
                                        // All list items are of the same type.\r
                                        switch ( attrs.type )\r
@@ -378,6 +351,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                case 'a' :\r
                                                        listStyleType = 'lower-alpha';\r
                                                        break;\r
+                                               case '1' :\r
+                                                       listStyleType = 'decimal';\r
+                                                       break;\r
                                                // TODO: Support more list style type from MS-Word.\r
                                        }\r
 \r
@@ -387,23 +363,22 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        for ( var i = 0; i < children.length; i++ )\r
                                        {\r
                                                child = children[ i ];\r
-                                               var attributes = child.attributes;\r
 \r
                                                if ( child.name in CKEDITOR.dtd.$listItem )\r
                                                {\r
-                                                       var listItemChildren = child.children,\r
+                                                       var attributes = child.attributes,\r
+                                                               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
                                                        {\r
-                                                               children.splice( i + 1, 0, last );\r
-                                                               last.parent = element;\r
+                                                               element.add( last, i + 1 );\r
 \r
                                                                // Remove the parent list item if it's just a holder.\r
                                                                if ( !--listItemChildren.length )\r
-                                                                       children.splice( i, 1 );\r
+                                                                       children.splice( i--, 1 );\r
                                                        }\r
 \r
                                                        child.name = 'cke:li';\r
@@ -413,24 +388,34 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                                        plugin.filters.stylesFilter(\r
                                                                [\r
-                                                                   [ 'tab-stops', null, function( val )\r
+                                                                       [ 'tab-stops', null, function( val )\r
                                                                        {\r
                                                                                var margin = val.split( ' ' )[ 1 ].match( cssLengthRelativeUnit );\r
-                                                                               margin && ( previousListItemMargin = parseInt( plugin.utils.convertToPx( margin[ 0 ] ), 10 ) );\r
+                                                                               margin && ( previousListItemMargin = CKEDITOR.tools.convertToPx( margin[ 0 ] ) );\r
                                                                        } ],\r
-                                                                       [ 'mso-list', null, function( val )\r
+                                                                       ( level == 1 ? [ 'mso-list', null, function( val )\r
                                                                        {\r
                                                                                val = val.split( ' ' );\r
                                                                                var listId = Number( val[ 0 ].match( /\d+/ ) );\r
                                                                                listId !== previousListId && ( attributes[ 'cke:reset' ] = 1 );\r
                                                                                previousListId = listId;\r
-                                                                       } ]\r
+                                                                        } ] : null )\r
                                                                ] )( attributes.style );\r
 \r
-                                                       attributes[ 'cke:indent' ] = indentLevel;\r
+                                                       attributes[ 'cke:indent' ] = level;\r
                                                        attributes[ 'cke:listtype' ] = element.name;\r
                                                        attributes[ 'cke:list-style-type' ] = listStyleType;\r
                                                }\r
+                                               // Flatten sub list.\r
+                                               else if ( child.name in CKEDITOR.dtd.$list )\r
+                                               {\r
+                                                       // Absorb sub list children.\r
+                                                       arguments.callee.apply( this, [ child, level + 1 ] );\r
+                                                       children = children.slice( 0, i ).concat( child.children ).concat( children.slice( i + 1 ) );\r
+                                                       element.children = [];\r
+                                                       for ( var j = 0, num = children.length; j < num ; j++ )\r
+                                                               element.add( children[ j ] );\r
+                                               }\r
                                        }\r
 \r
                                        delete element.name;\r
@@ -771,7 +756,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                isListBulletIndicator = this.utils.isListBulletIndicator,\r
                                containsNothingButSpaces = this.utils.isContainingOnlySpaces,\r
                                resolveListItem = this.utils.resolveList,\r
-                               convertToPx = this.utils.convertToPx,\r
+                               convertToPx = function( value )\r
+                                       {\r
+                                               value = CKEDITOR.tools.convertToPx( value );\r
+                                               return isNaN( value ) ? value : value + 'px';\r
+                                       },\r
                                getStyleComponents = this.utils.getStyleComponents,\r
                                listDtdParents = this.utils.listDtdParents,\r
                                removeFontStyles = config.pasteFromWordRemoveFontStyles !== false,\r
@@ -1120,6 +1109,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                var attrs = element.attributes;\r
                                                if ( attrs && !attrs.href && attrs.name )\r
                                                        delete element.name;\r
+                                               else if ( CKEDITOR.env.webkit && attrs.href && attrs.href.match( /file:\/\/\/[\S]+#/i ) )\r
+                                                       attrs.href = attrs.href.replace( /file:\/\/\/[^#]+/i,'' );\r
                                        },\r
                                        'cke:listbullet' : function( element )\r
                                        {\r