Ticket #1355: 1355_4.patch
File 1355_4.patch, 9.4 KB (added by , 17 years ago) |
---|
-
editor/_source/classes/fckdomrange_gecko.js
101 101 var selection = this.Window.getSelection() ; 102 102 selection.removeAllRanges() ; 103 103 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 28 var FCKHtmlIterator = function( source ) 29 { 30 this._sourceHtml = source ; 31 } 32 FCKHtmlIterator.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
747 747 }, 748 748 749 749 /** 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 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, ' ' ) ; 770 if ( beginSpaces ) 771 innerHTML = beginSpaces[0].replace( /[ \t]/g, ' ' ) + innerHTML.substr( beginSpaces[0].length ) ; 772 773 // 2. Convert \n to <BR>. 774 // 3. Convert contiguous (i.e. non-singular) spaces or tabs to 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, ' ' ) ; 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 to spaces since 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]+| )/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 /** 750 845 * Apply an inline style to a FCKDomRange. 751 846 * 752 847 * TODO … … 759 854 var bookmark ; 760 855 761 856 if ( selectIt ) 762 bookmark = range.CreateBookmark( true) ;857 bookmark = range.CreateBookmark() ; 763 858 764 859 var iterator = new FCKDomRangeIterator( range ) ; 765 860 iterator.EnforceRealBlocks = true ; 766 861 767 862 var block ; 863 var doc = range.Window.document ; 864 768 865 while( ( block = iterator.GetNextParagraph() ) ) // Only one = 769 866 { 770 867 // 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 ) ; 772 869 773 870 // 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 ) ; 775 877 776 // Delete the current node. 878 // Replace the current block. 879 block.parentNode.insertBefore( newBlock, block ) ; 777 880 FCKDomTools.RemoveNode( block ) ; 778 881 } 779 882 … … 782 885 range.SelectBookmark( bookmark ) ; 783 886 784 887 if ( updateRange ) 785 range.MoveToBookmark( range) ;888 range.MoveToBookmark( bookmark ) ; 786 889 }, 787 890 788 891 /** -
editor/_source/internals/fckregexlib.js
93 93 // name is returned with $2. 94 94 StyleVariableAttName : /#\(\s*("|')(.+?)\1[^\)]*\s*\)/g, 95 95 96 RegExp : /^\/(.*)\/([gim]*)$/ 96 RegExp : /^\/(.*)\/([gim]*)$/, 97 98 HtmlTag : /<[^\s<>](?:"[^"]*"|'[^']*'|[^<])*>/ 97 99 } ; -
editor/fckeditor.html
186 186 LoadScript( '_source/classes/fckmenublockpanel.js' ) ; 187 187 LoadScript( '_source/classes/fckcontextmenu.js' ) ; 188 188 LoadScript( '_source/internals/fck_contextmenu.js' ) ; 189 LoadScript( '_source/classes/fckhtmliterator.js' ) ; 189 190 LoadScript( '_source/classes/fckplugin.js' ) ; 190 191 LoadScript( '_source/internals/fckplugins.js' ) ; 191 192 -
fckpackager.xml
157 157 <File path="editor/_source/classes/fckmenublockpanel.js" /> 158 158 <File path="editor/_source/classes/fckcontextmenu.js" /> 159 159 <File path="editor/_source/internals/fck_contextmenu.js" /> 160 <File path="editor/_source/class/fckhtmliterator.js" /> 160 161 161 162 <File path="editor/_source/classes/fckplugin.js" /> 162 163 <File path="editor/_source/internals/fckplugins.js" /> … … 252 253 <File path="editor/_source/classes/fckmenublockpanel.js" /> 253 254 <File path="editor/_source/classes/fckcontextmenu.js" /> 254 255 <File path="editor/_source/internals/fck_contextmenu.js" /> 256 <File path="editor/_source/class/fckhtmliterator.js" /> 255 257 256 258 <File path="editor/_source/classes/fckplugin.js" /> 257 259 <File path="editor/_source/internals/fckplugins.js" />