Show
Ignore:
Timestamp:
2008-07-09 06:04:42 (6 months ago)
Author:
martinkou
Message:

Changed Div creation/modification dialog to handle multiple div containers.

Files:
1 modified

Legend:

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

    r2187 r2197  
    5959} 
    6060 
    61 var ActiveEl = null ; 
     61var CurrentContainers = [] ; 
    6262if ( !AlwaysCreate ) 
    6363{ 
    64         var oSelection = dialog.Selection.GetSelection() ; 
    65         ActiveEl = ( new FCKElementPath( oSelection.GetSelectedElement() || oSelection.GetParentElement() ) ).BlockLimit ; 
    66         if ( ActiveEl && ActiveEl.nodeName.toLowerCase() != 'div' ) 
    67                 ActiveEl = null ; 
     64        dialog.Selection.EnsureSelection() ; 
     65        var range = new FCKDomRange( FCK.EditorWindow ) ; 
     66        range.MoveToSelection() ; 
     67 
     68        var startNode = range.StartNode ; 
     69        var endNode = range.EndNode ; 
     70        var currentNode = startNode ; 
     71        var elementMarkers = {} ; 
     72 
     73        do 
     74        { 
     75                if ( currentNode.nodeName.IEquals( 'div' ) && currentNode.firstChild && 
     76                                oEditor.FCKListsLib.BlockElements[ currentNode.firstChild.nodeName.toLowerCase() ] ) 
     77                { 
     78                        CurrentContainers.push( currentNode ) ; 
     79                        if ( currentNode.parentNode.nodeName.IEquals( 'div' ) ) 
     80                                FCKDomTools.SetElementMarker( elementMarkers, currentNode, '_fckignorethisnode', true ) ; 
     81                } 
     82        } 
     83        while ( ( currentNode = FCKDomTools.GetNextSourceElement( currentNode ) ) && currentNode != endNode 
     84                        && currentNode != endNode.parentNode ) ; 
     85 
     86        for ( var i = CurrentContainers.length - 1 ; i >= 0 ; i-- ) 
     87        { 
     88                if ( CurrentContainers[i]['_fckignorethisnode'] ) 
     89                        CurrentContainers.splice( i, 1 ) ; 
     90        } 
    6891} 
    6992 
     
    114137        var match = null ; 
    115138        var selectableStyles = {} ; 
    116         for ( var i in styles ) 
    117         { 
    118                 if ( ! /^_FCK_/.test( i ) && styles[i].Element == 'div' ) 
    119                 { 
    120                         if ( ActiveEl && styles[i].CheckElementRemovable( ActiveEl, true ) ) 
    121                                 match = i ; 
    122                         selectableStyles[i] = styles[i] ; 
    123                 } 
    124         } 
    125         if ( !match ) 
    126                 AddStyleOption( "" ) ; 
    127         for ( var i in selectableStyles ) 
    128                 AddStyleOption( i ) ; 
    129         if ( match ) 
    130                 GetE( 'selStyle' ).value = match ; 
    131  
    132         // Set the value for other inputs 
    133         if ( ActiveEl ) 
    134         { 
    135                 GetE( 'txtClass' ).value = ActiveEl.className ; 
    136                 GetE( 'txtId' ).value = ActiveEl.id ; 
    137                 GetE( 'txtLang' ).value = ActiveEl.lang ; 
    138                 GetE( 'txtInlineStyle').value = ActiveEl.getAttribute( 'style' ) ; 
    139                 GetE( 'txtTitle' ).value = ActiveEl.title ; 
    140                 GetE( 'selLangDir').value = ActiveEl.dir || GetNearestAncestorDirection( ActiveEl ) ; 
     139        if ( CurrentContainers.length <= 1 ) 
     140        { 
     141                var target = CurrentContainers[0] ; 
     142                for ( var i in styles ) 
     143                { 
     144                        if ( ! /^_FCK_/.test( i ) && styles[i].Element == 'div' ) 
     145                        { 
     146                                if ( target && styles[i].CheckElementRemovable( target, true ) ) 
     147                                        match = i ; 
     148                                selectableStyles[i] = styles[i] ; 
     149                        } 
     150                } 
     151                if ( !match ) 
     152                        AddStyleOption( "" ) ; 
     153                for ( var i in selectableStyles ) 
     154                        AddStyleOption( i ) ; 
     155                if ( match ) 
     156                        GetE( 'selStyle' ).value = match ; 
     157 
     158                // Set the value for other inputs 
     159                if ( target ) 
     160                { 
     161                        GetE( 'txtClass' ).value = target.className ; 
     162                        GetE( 'txtId' ).value = target.id ; 
     163                        GetE( 'txtLang' ).value = target.lang ; 
     164                        GetE( 'txtInlineStyle').value = target.getAttribute( 'style' ) ; 
     165                        GetE( 'txtTitle' ).value = target.title ; 
     166                        GetE( 'selLangDir').value = target.dir || GetNearestAncestorDirection( target ) ; 
     167                } 
     168        } 
     169        else 
     170        { 
     171                GetE( 'txtId' ).disabled = GetE( 'selStyle' ).disabled = true  ; 
    141172        } 
    142173} 
     
    144175function CreateDiv() 
    145176{ 
    146         var bqBlock ; 
     177        var newBlocks = [] ; 
    147178        var range = new FCKDomRange( FCK.EditorWindow ) ; 
    148179        range.MoveToSelection() ; 
     
    214245                for ( var j = 0 ; j < groups[i].length ; j++ ) 
    215246                        FCKDomTools.MoveNode( groups[i][j], divNode ) ; 
    216                 bqBlock = divNode ; 
     247                newBlocks.push( divNode ) ; 
    217248        } 
    218249 
     
    223254        FCK.Events.FireEvent( 'OnSelectionChange' ) ; 
    224255 
    225         return bqBlock ; 
     256        return newBlocks ; 
    226257} 
    227258 
     
    230261        oEditor.FCKUndo.SaveUndoStep() ; 
    231262 
    232         if ( !ActiveEl ) 
    233                 ActiveEl = CreateDiv(); 
     263        if ( CurrentContainers.length < 1 ) 
     264                CurrentContainers = CreateDiv(); 
    234265 
    235266        var setValue = function( attrName, inputName ) 
    236267        { 
    237268                var val = GetE( inputName ).value ; 
    238                 if ( val == '' ) 
    239                         ActiveEl.removeAttribute( attrName ) ; 
    240                 else 
    241                         ActiveEl.setAttribute( attrName, val ) ; 
     269                for ( var i = 0 ; i < CurrentContainers.length ; i++ ) 
     270                { 
     271                        if ( val == '' ) 
     272                                CurrentContainers[i].removeAttribute( attrName ) ; 
     273                        else 
     274                                CurrentContainers[i].setAttribute( attrName, val ) ; 
     275                } 
    242276        } 
    243277 
    244278        // Apply modifications to the DIV container according to dialog inputs. 
    245         setValue( 'class', 'txtClass' ) ; 
    246         setValue( 'id', 'txtId' ) ; 
     279        if ( CurrentContainers.length == 1 ) 
     280        { 
     281                setValue( 'class', 'txtClass' ) ; 
     282                setValue( 'id', 'txtId' ) ; 
     283        } 
    247284        setValue( 'lang', 'txtLang' ) ; 
    248285        if ( FCKBrowserInfo.IsIE ) 
    249                 ActiveEl.style.cssText = GetE( 'txtInlineStyle' ).value ; 
     286        { 
     287                for ( var i = 0 ; i < CurrentContainers.length ; i++ ) 
     288                        CurrentContainers[i].style.cssText = GetE( 'txtInlineStyle' ).value ; 
     289        } 
    250290        else 
    251291                setValue( 'style', 'txtInlineStyle' ) ; 
    252292        setValue( 'title', 'txtTitle' ) ; 
    253         var dir = GetE( 'selLangDir' ).value ; 
    254         if ( GetNearestAncestorDirection( ActiveEl ) != dir ) 
    255                 ActiveEl.dir = dir ; 
    256         else 
    257                 ActiveEl.removeAttribute( 'dir' ) ; 
    258  
    259         var styleName = GetE( 'selStyle' ).value ; 
    260         if ( styleName ) 
    261                 FCKStyles.GetStyle( styleName ).ApplyToObject( ActiveEl ) ; 
     293        for ( var i = 0 ; i < CurrentContainers.length ; i++ ) 
     294        { 
     295                var dir = GetE( 'selLangDir' ).value ; 
     296                var styleName = GetE( 'selStyle' ).value ; 
     297                if ( GetNearestAncestorDirection( CurrentContainers[i] ) != dir ) 
     298                        CurrentContainers[i].dir = dir ; 
     299                else 
     300                        CurrentContainers[i].removeAttribute( 'dir' ) ; 
     301                 
     302                if ( styleName ) 
     303                        FCKStyles.GetStyle( styleName ).ApplyToObject( CurrentContainers[i] ) ; 
     304        } 
    262305 
    263306        return true ;