Changeset 2185 for FCKeditor/branches

Show
Ignore:
Timestamp:
2008-07-07 05:21:57 (5 months ago)
Author:
martinkou
Message:

Removed the new fckblockcontainercommand.js and restored the old fckblockquotecommand.js.
Moved Div creation logic of the Div dialog into the dialog HTML.

Location:
FCKeditor/branches/features/div_container
Files:
1 added
1 removed
4 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/branches/features/div_container/editor/dialog/fck_div.html

    r2173 r2185  
    3131var dialog      = window.parent ; 
    3232var oEditor = dialog.InnerDialogLoaded() ; 
     33var FCK = oEditor.FCK ; 
    3334var FCKLang = oEditor.FCKLang ; 
    3435var FCKBrowserInfo = oEditor.FCKBrowserInfo ; 
    3536var FCKStyles = oEditor.FCKStyles ; 
    3637var FCKElementPath = oEditor.FCKElementPath ; 
    37 var FCKBlockContainerCommand = oEditor.FCKBlockContainerCommand ; 
     38var FCKDomRange = oEditor.FCKDomRange ; 
     39var FCKDomTools = oEditor.FCKDomTools ; 
     40var FCKDomRangeIterator = oEditor.FCKDomRangeIterator ; 
    3841var AlwaysCreate = dialog.Args().CustomValue ; 
     42 
     43String.prototype.IEquals = function() 
     44{ 
     45        var thisUpper = this.toUpperCase() ; 
     46 
     47        var aArgs = arguments ; 
     48 
     49        // The arguments could also be a single array. 
     50        if ( aArgs.length == 1 && aArgs[0].pop ) 
     51                aArgs = aArgs[0] ; 
     52 
     53        for ( var i = 0 ; i < aArgs.length ; i++ ) 
     54        { 
     55                if ( thisUpper == aArgs[i].toUpperCase() ) 
     56                        return true ; 
     57        } 
     58        return false ; 
     59} 
    3960 
    4061var ActiveEl = null ; 
     
    121142} 
    122143 
     144function CreateDiv() 
     145{ 
     146        var bqBlock ; 
     147        var range = new FCKDomRange( FCK.EditorWindow ) ; 
     148        range.MoveToSelection() ; 
     149 
     150        var bookmark = range.CreateBookmark() ; 
     151 
     152        // Kludge for #1592: if the bookmark nodes are in the beginning of 
     153        // $tagName, then move them to the nearest block element in the 
     154        // $tagName. 
     155        if ( FCKBrowserInfo.IsIE ) 
     156        { 
     157                var bStart      = range.GetBookmarkNode( bookmark, true ) ; 
     158                var bEnd        = range.GetBookmarkNode( bookmark, false ) ; 
     159 
     160                var cursor ; 
     161 
     162                if ( bStart 
     163                                && bStart.parentNode.nodeName.IEquals( 'div' ) 
     164                                && !bStart.previousSibling ) 
     165                { 
     166                        cursor = bStart ; 
     167                        while ( ( cursor = cursor.nextSibling ) ) 
     168                        { 
     169                                if ( FCKListsLib.BlockElements[ cursor.nodeName.toLowerCase() ] ) 
     170                                        FCKDomTools.MoveNode( bStart, cursor, true ) ; 
     171                        } 
     172                } 
     173 
     174                if ( bEnd 
     175                                && bEnd.parentNode.nodeName.IEquals( 'div' ) 
     176                                && !bEnd.previousSibling ) 
     177                { 
     178                        cursor = bEnd ; 
     179                        while ( ( cursor = cursor.nextSibling ) ) 
     180                        { 
     181                                if ( FCKListsLib.BlockElements[ cursor.nodeName.toLowerCase() ] ) 
     182                                { 
     183                                        if ( cursor.firstChild == bStart ) 
     184                                                FCKDomTools.InsertAfterNode( bStart, bEnd ) ; 
     185                                        else 
     186                                                FCKDomTools.MoveNode( bEnd, cursor, true ) ; 
     187                                } 
     188                        } 
     189                } 
     190        } 
     191 
     192        var iterator = new FCKDomRangeIterator( range ) ; 
     193        var block ; 
     194 
     195        if ( true ) 
     196        { 
     197                iterator.EnforceRealBlocks = true ; 
     198                var paragraphs = [] ; 
     199                while ( ( block = iterator.GetNextParagraph() ) ) 
     200                        paragraphs.push( block ) ; 
     201 
     202                // If no paragraphs, create one from the current selection position. 
     203                if ( paragraphs.length < 1 ) 
     204                { 
     205                        para = range.Window.document.createElement( FCKConfig.EnterMode.IEquals( 'p' ) ? 'p' : 'div' ) ; 
     206                        range.InsertNode( para ) ; 
     207                        para.appendChild( range.Window.document.createTextNode( '\ufeff' ) ) ; 
     208                        range.MoveToBookmark( bookmark ) ; 
     209                        range.MoveToNodeContents( para ) ; 
     210                        range.Collapse( true ) ; 
     211                        bookmark = range.CreateBookmark() ; 
     212                        paragraphs.push( para ) ; 
     213                } 
     214 
     215                // Make sure all paragraphs have the same parent. 
     216                var commonParent = paragraphs[0].parentNode ; 
     217                var tmp = [] ; 
     218                for ( var i = 0 ; i < paragraphs.length ; i++ ) 
     219                { 
     220                        block = paragraphs[i] ; 
     221                        commonParent = FCKDomTools.GetCommonParents( block.parentNode, commonParent ).pop() ; 
     222                } 
     223                var lastBlock = null ; 
     224                while ( paragraphs.length > 0 ) 
     225                { 
     226                        block = paragraphs.shift() ; 
     227                        while ( block.parentNode != commonParent ) 
     228                                block = block.parentNode ; 
     229                        if ( block != lastBlock ) 
     230                                tmp.push( block ) ; 
     231                        lastBlock = block ; 
     232                } 
     233 
     234                // If any of the selected blocks is a $tagName, remove it to prevent nested $tagNames. 
     235                while ( tmp.length > 0 ) 
     236                { 
     237                        block = tmp.shift() ; 
     238                        if ( block.nodeName.IEquals( 'div' ) ) 
     239                        { 
     240                                var docFrag = FCKTools.GetElementDocument( block ).createDocumentFragment() ; 
     241                                while ( block.firstChild ) 
     242                                { 
     243                                        docFrag.appendChild( block.removeChild( block.firstChild ) ) ; 
     244                                        paragraphs.push( docFrag.lastChild ) ; 
     245                                } 
     246                                block.parentNode.replaceChild( docFrag, block ) ; 
     247                        } 
     248                        else 
     249                                paragraphs.push( block ) ; 
     250                } 
     251 
     252                // Now we have all the blocks to be included in a new $tagName node. 
     253                bqBlock = range.Window.document.createElement( 'div' ) ; 
     254                commonParent.insertBefore( bqBlock, paragraphs[0] ) ; 
     255                while ( paragraphs.length > 0 ) 
     256                { 
     257                        block = paragraphs.shift() ; 
     258                        bqBlock.appendChild( block ) ; 
     259                } 
     260        } 
     261 
     262        range.MoveToBookmark( bookmark ) ; 
     263        range.Select() ; 
     264 
     265        FCK.Focus() ; 
     266        FCK.Events.FireEvent( 'OnSelectionChange' ) ; 
     267 
     268        return bqBlock ; 
     269} 
     270 
    123271function Ok() 
    124272{ 
     
    126274 
    127275        if ( !ActiveEl ) 
    128         { 
    129                 var cmd = new FCKBlockContainerCommand( 'div', AlwaysCreate ) ; 
    130                 cmd.Execute() ; 
    131                 ActiveEl = cmd.createdBlock ; 
    132         } 
     276                ActiveEl = CreateDiv(); 
    133277 
    134278        var setValue = function( attrName, inputName ) 
  • FCKeditor/branches/features/div_container/editor/fckeditor.html

    r2102 r2185  
    156156LoadScript( '_source/commandclasses/fckjustifycommands.js' ) ; 
    157157LoadScript( '_source/commandclasses/fckindentcommands.js' ) ; 
    158 LoadScript( '_source/commandclasses/fckblockcontainercommand.js' ) ; 
     158LoadScript( '_source/commandclasses/fckblockquotecommand.js' ) ; 
    159159LoadScript( '_source/commandclasses/fckcorestylecommand.js' ) ; 
    160160LoadScript( '_source/commandclasses/fckremoveformatcommand.js' ) ; 
  • FCKeditor/branches/features/div_container/editor/_source/internals/fckcommands.js

    r2118 r2185  
    9494                case 'Indent'   : oCommand = new FCKIndentCommand( 'indent', FCKConfig.IndentLength ) ; break ; 
    9595                case 'Outdent'  : oCommand = new FCKIndentCommand( 'outdent', FCKConfig.IndentLength * -1 ) ; break ; 
    96                 case 'Blockquote'       : oCommand = new FCKBlockContainerCommand( 'blockquote' ) ; break ; 
     96                case 'Blockquote'       : oCommand = new FCKBlockQuoteCommand() ; break ; 
    9797                case 'CreateDiv'        : oCommand = new FCKDialogCommand( 'CreateDiv', FCKLang.CreateDiv, 'dialog/fck_div.html', 380, 210, null, null, true ) ; break ; 
    9898                case 'EditDiv'          : oCommand = new FCKDialogCommand( 'EditDiv', FCKLang.EditDiv, 'dialog/fck_div.html', 380, 210, null, null, false ) ; break ; 
  • FCKeditor/branches/features/div_container/fckpackager.xml

    r2102 r2185  
    131131                <File path="editor/_source/commandclasses/fckjustifycommands.js" /> 
    132132                <File path="editor/_source/commandclasses/fckindentcommands.js" /> 
    133                 <File path="editor/_source/commandclasses/fckblockcontainercommand.js" /> 
     133                <File path="editor/_source/commandclasses/fckblockquotecommand.js" /> 
    134134                <File path="editor/_source/commandclasses/fckcorestylecommand.js" /> 
    135135                <File path="editor/_source/commandclasses/fckremoveformatcommand.js" /> 
     
    227227                <File path="editor/_source/commandclasses/fckjustifycommands.js" /> 
    228228                <File path="editor/_source/commandclasses/fckindentcommands.js" /> 
    229                 <File path="editor/_source/commandclasses/fckblockcontainercommand.js" /> 
     229                <File path="editor/_source/commandclasses/fckblockquotecommand.js" /> 
    230230                <File path="editor/_source/commandclasses/fckcorestylecommand.js" /> 
    231231                <File path="editor/_source/commandclasses/fckremoveformatcommand.js" />