Ticket #1355: 1355_4.patch

File 1355_4.patch, 9.4 KB (added by Martin Kou, 16 years ago)

Simplified the 1355_3.patch.

  • editor/_source/classes/fckdomrange_gecko.js

     
    101101        var selection = this.Window.getSelection() ;
    102102        selection.removeAllRanges() ;
    103103        selection.addRange( domRange ) ;
    104 }
    105  No newline at end of file
     104}
  • editor/_source/classes/fckhtmliterator.js

     
     1/*
     2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
     3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
     4 *
     5 * == BEGIN LICENSE ==
     6 *
     7 * Licensed under the terms of any of the following licenses at your
     8 * choice:
     9 *
     10 *  - GNU General Public License Version 2 or later (the "GPL")
     11 *    http://www.gnu.org/licenses/gpl.html
     12 *
     13 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
     14 *    http://www.gnu.org/licenses/lgpl.html
     15 *
     16 *  - Mozilla Public License Version 1.1 or later (the "MPL")
     17 *    http://www.mozilla.org/MPL/MPL-1.1.html
     18 *
     19 * == END LICENSE ==
     20 *
     21 * This class can be used to interate through nodes inside a range.
     22 *
     23 * During interation, the provided range can become invalid, due to document
     24 * mutations, so CreateBookmark() used to restore it after processing, if
     25 * needed.
     26 */
     27
     28var FCKHtmlIterator = function( source )
     29{
     30        this._sourceHtml = source ;
     31}
     32FCKHtmlIterator.prototype =
     33{
     34        Next : function()
     35        {
     36                var sourceHtml = this._sourceHtml ;
     37                if ( sourceHtml == null )
     38                        return null ;
     39
     40                var match = FCKRegexLib.HtmlTag.exec( sourceHtml ) ;
     41                var isTag = false ;
     42                var value = "" ;
     43                if ( match )
     44                {
     45                        if ( match.index > 0 )
     46                        {
     47                                value = sourceHtml.substr( 0, match.index ) ;
     48                                this._sourceHtml = sourceHtml.substr( match.index ) ;
     49                        }
     50                        else
     51                        {
     52                                isTag = true ;
     53                                value = match[0] ;
     54                                this._sourceHtml = sourceHtml.substr( match[0].length ) ;
     55                        }
     56                }
     57                else
     58                {
     59                        value = sourceHtml ;
     60                        this._sourceHtml = null ;
     61                }
     62                return { 'isTag' : isTag, 'value' : value } ;
     63        },
     64
     65        Each : function( func )
     66        {
     67                var chunk ;
     68                while ( ( chunk = this.Next() ) )
     69                        func( chunk.isTag, chunk.value ) ;
     70        }
     71} ;
  • editor/_source/classes/fckstyle.js

     
    747747        },
    748748
    749749        /**
     750         * Converting from a PRE block to a non-PRE block in formatting operations.
     751         */
     752        _FromPre : function( doc, block, newBlock )
     753        {
     754                var innerHTML = block.innerHTML ;
     755
     756                // Trim the first and last linebreaks immediately after and before <pre>, </pre>,
     757                // if they exist.
     758                // This is done because the linebreaks are not rendered.
     759                innerHTML = innerHTML.replace( /(\r\n|\r)/g, '\n' ) ;
     760                innerHTML = innerHTML.match( /^(?:[ \t]*\n)?((?:[a]|[^a])*)$/ )[1] ;
     761                var lastWhiteSpaceMatch = /\n$/.exec( innerHTML ) ;
     762                if ( lastWhiteSpaceMatch )
     763                        innerHTML = innerHTML.substr( 0, lastWhiteSpaceMatch.index ) ;
     764
     765                // 1. Convert spaces or tabs at the beginning or at the end to &nbsp;
     766                var beginSpaces = /^[ \t]+/.exec( innerHTML ) ;
     767                var endSpaces = /[ \t]+$/.exec( innerHTML ) ;
     768                if ( endSpaces )
     769                        innerHTML = innerHTML.substr( 0, endSpaces.index ) + endSpaces[0].replace( /[ \t]/g, '&nbsp;' ) ;
     770                if ( beginSpaces )
     771                        innerHTML = beginSpaces[0].replace( /[ \t]/g, '&nbsp;' ) + innerHTML.substr( beginSpaces[0].length ) ;
     772
     773                // 2. Convert \n to <BR>.
     774                // 3. Convert contiguous (i.e. non-singular) spaces or tabs to &nbsp;
     775                var htmlIterator = new FCKHtmlIterator( innerHTML ) ;
     776                var results = [] ;
     777                var processor = function( isTag, value )
     778                {
     779                        if ( !isTag )
     780                        {
     781                                value = value.replace( /\n/g, '<BR>' ) ;
     782                                value = value.replace( /[ \t]{2}/g, '&nbsp;&nbsp;' ) ;
     783                        }
     784                        results.push( value ) ;
     785                }
     786                htmlIterator.Each( processor ) ;
     787                newBlock.innerHTML = results.join( '' ) ;
     788        },
     789
     790        /**
     791         * Converting from a non-PRE block to a PRE block in formatting operations.
     792         */
     793        _ToPre : function( doc, block, newBlock )
     794        {
     795                // Handle converting from a regular block to a <pre> block.
     796                var innerHTML = block.innerHTML.Trim() ;
     797                var htmlIterator = new FCKHtmlIterator( innerHTML ) ;
     798                var results = [] ;
     799                var lastNodeWasBr = false ;
     800
     801                // 1. Delete ANSI whitespaces immediately before and after <BR> because they are not visible.
     802                // 2. Compress other ANSI whitespaces since they're only visible as one single space previously.
     803                // 3. Convert &nbsp; to spaces since &nbsp; is no longer needed in <PRE>.
     804                var processor = function( isTag, value )
     805                {
     806                        if ( isTag )
     807                        {
     808                                if ( /^<BR/i.test( value ) )
     809                                {
     810                                        value = '\n' ;
     811                                        if ( results.length > 0 )
     812                                                results[results.length - 1] = results[results.length - 1].RTrim() ;
     813                                        lastNodeWasBr = true ;
     814                                }
     815                                else
     816                                        lastNodeWasBr = false ;
     817                        }
     818                        else
     819                        {
     820                                if ( lastNodeWasBr )
     821                                        value = value.LTrim() ;
     822                                value = value.replace( /([ \t\n\r]+|&nbsp;)/g, ' ' ) ;
     823                                lastNodeWasBr = false ;
     824                        }
     825                        results.push( value ) ;
     826                }
     827                htmlIterator.Each( processor ) ;
     828
     829                // Assigning innerHTML to <PRE> in IE causes all linebreaks to be reduced to spaces.
     830                // Assigning outerHTML to <PRE> in IE doesn't work if the <PRE> isn't contained in another node
     831                // since the node reference is changed after outerHTML assignment.
     832                // So, we need some hacks to workaround IE bugs here.
     833                if ( FCKBrowserInfo.IsIE )
     834                {
     835                        var temp = doc.createElement( 'div' ) ;
     836                        temp.appendChild( newBlock ) ;
     837                        newBlock.outerHTML = '<PRE>\n' + results.join( '' ) + '</PRE>' ;
     838                        newBlock = temp.removeChild( temp.firstChild ) ;
     839                }
     840                else
     841                        newBlock.innerHTML = results.join( '' ) ;
     842        },
     843
     844        /**
    750845         * Apply an inline style to a FCKDomRange.
    751846         *
    752847         * TODO
     
    759854                var bookmark ;
    760855
    761856                if ( selectIt )
    762                         bookmark = range.CreateBookmark( true ) ;
     857                        bookmark = range.CreateBookmark() ;
    763858
    764859                var iterator = new FCKDomRangeIterator( range ) ;
    765860                iterator.EnforceRealBlocks = true ;
    766861
    767862                var block ;
     863                var doc = range.Window.document ;
     864
    768865                while( ( block = iterator.GetNextParagraph() ) )                // Only one =
    769866                {
    770867                        // Create the new node right before the current one.
    771                         var newBlock = block.parentNode.insertBefore( this.BuildElement( range.Window.document ), block ) ;
     868                        var newBlock = this.BuildElement( doc ) ;
    772869
    773870                        // Move everything from the current node to the new one.
    774                         FCKDomTools.MoveChildren( block, newBlock ) ;
     871                        if ( newBlock.nodeName.IEquals( 'pre' ) && !block.nodeName.IEquals( 'pre' ) )
     872                                this._ToPre( doc, block, newBlock ) ;
     873                        else if ( !newBlock.nodeName.IEquals( 'pre' ) && block.nodeName.IEquals( 'pre' ) )
     874                                this._FromPre( doc, block, newBlock ) ;
     875                        else    // Convering from a regular block to another regular block.
     876                                FCKDomTools.MoveChildren( block, newBlock ) ;
    775877
    776                         // Delete the current node.
     878                        // Replace the current block.
     879                        block.parentNode.insertBefore( newBlock, block ) ;
    777880                        FCKDomTools.RemoveNode( block ) ;
    778881                }
    779882
     
    782885                        range.SelectBookmark( bookmark ) ;
    783886
    784887                if ( updateRange )
    785                         range.MoveToBookmark( range ) ;
     888                        range.MoveToBookmark( bookmark ) ;
    786889        },
    787890
    788891        /**
  • editor/_source/internals/fckregexlib.js

     
    9393// name is returned with $2.
    9494StyleVariableAttName : /#\(\s*("|')(.+?)\1[^\)]*\s*\)/g,
    9595
    96 RegExp : /^\/(.*)\/([gim]*)$/
     96RegExp : /^\/(.*)\/([gim]*)$/,
     97
     98HtmlTag : /<[^\s<>](?:"[^"]*"|'[^']*'|[^<])*>/
    9799} ;
  • editor/fckeditor.html

     
    186186LoadScript( '_source/classes/fckmenublockpanel.js' ) ;
    187187LoadScript( '_source/classes/fckcontextmenu.js' ) ;
    188188LoadScript( '_source/internals/fck_contextmenu.js' ) ;
     189LoadScript( '_source/classes/fckhtmliterator.js' ) ;
    189190LoadScript( '_source/classes/fckplugin.js' ) ;
    190191LoadScript( '_source/internals/fckplugins.js' ) ;
    191192
  • fckpackager.xml

     
    157157                <File path="editor/_source/classes/fckmenublockpanel.js" />
    158158                <File path="editor/_source/classes/fckcontextmenu.js" />
    159159                <File path="editor/_source/internals/fck_contextmenu.js" />
     160                <File path="editor/_source/class/fckhtmliterator.js" />
    160161
    161162                <File path="editor/_source/classes/fckplugin.js" />
    162163                <File path="editor/_source/internals/fckplugins.js" />
     
    252253                <File path="editor/_source/classes/fckmenublockpanel.js" />
    253254                <File path="editor/_source/classes/fckcontextmenu.js" />
    254255                <File path="editor/_source/internals/fck_contextmenu.js" />
     256                <File path="editor/_source/class/fckhtmliterator.js" />
    255257
    256258                <File path="editor/_source/classes/fckplugin.js" />
    257259                <File path="editor/_source/internals/fckplugins.js" />
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy