Ticket #676: 676.patch

File 676.patch, 10.1 KB (added by Alfonso Martínez de Lizarrondo, 16 years ago)

Proposed SVN patch

  • editor/dialog/common/fck_dialog_common.js

     
    206206    else
    207207                window.open( url, 'FCKBrowseWindow', sOptions ) ;
    208208}
     209
     210/**
     211 Utility function to create/update an element with a name attribute in IE, so it behaves properly when moved around
     212 It also allows to change the name or other special attributes in an existing node
     213        oEditor : instance of FCKeditor where the element will be created
     214        oOriginal : current element being edited or null if it has to be created
     215        nodeName : string with the name of the element to create
     216        oAttributes : Hash object with the attributes that must be set at creation time in IE
     217                                                                Those attributes will be set also after the element has been
     218                                                                created for any other browser to avoid redudant code
     219*/
     220function CreateNamedElement( oEditor, oOriginal, nodeName, oAttributes )
     221{
     222        var oNewNode ;
     223
     224        // IE doesn't allow easily to change properties of an existing object,
     225        // so remove the old and force the creation of a new one.
     226        var oldNode = null ;
     227        if ( oOriginal && oEditor.FCKBrowserInfo.IsIE )
     228        {
     229                oldNode = oOriginal ;
     230                oOriginal = null ;
     231        }
     232
     233        // If the node existed (and it's not IE), then we just have to update its attributes
     234        if ( oOriginal )
     235        {
     236                oNewNode = oOriginal ;
     237        }
     238        else
     239        {
     240                // #676, IE doesn't play nice with the name or type attribute
     241                if ( oEditor.FCKBrowserInfo.IsIE )
     242                {
     243                        var sbHTML = [] ;
     244                        sbHTML.push( '<' + nodeName ) ;
     245                        for( var prop in oAttributes )
     246                        {
     247                                sbHTML.push( ' ' + prop + '="' + oAttributes[prop] + '"' ) ;
     248                        }
     249                        sbHTML.push( '>' ) ;
     250                        if ( !oEditor.FCKListsLib.EmptyElements[nodeName.toLowerCase()] )
     251                                sbHTML.push( '</' + nodeName + '>' ) ;
     252
     253                        oNewNode = oEditor.FCK.EditorDocument.createElement( sbHTML.join('') ) ;
     254                        // Check if we are just changing the properties of an existing node: copy its properties
     255                        if ( oldNode )
     256                        {
     257                                CopyAttributes( oldNode, oNewNode, oAttributes ) ;
     258                                MoveContents( oldNode, oNewNode ) ;
     259                                oldNode.parentNode.removeChild( oldNode ) ;
     260                                oldNode = null ;
     261
     262                                // Trick to refresh the selection object and avoid error in fckdialog.html Selection.EnsureSelection
     263                                // We have removed the existing node (that was selected), so we can't try to select it later
     264                                var oSel = oEditor.FCK.EditorDocument.selection ;
     265                                oEditor.FCKDialog.SelectionData = oSel.createRange() ; // Now oSel.type will be 'None' reflecting the real situation
     266                        }
     267                        oNewNode = oEditor.FCK.InsertElement( oNewNode ) ;
     268                }
     269                else
     270                {
     271                        oNewNode = oEditor.FCK.InsertElement( nodeName ) ;
     272                }
     273        }       
     274
     275        // Set the basic attributes
     276        for( var attName in oAttributes )
     277                oNewNode.setAttribute( attName, oAttributes[attName], 0 ) ;     // 0 : Case Insensitive
     278
     279        return oNewNode ;
     280}
     281
     282// Copy all the attributes from one node to the other, kinda like a clone
     283// But oSkipAttributes is an object with the attributes that must NOT be copied
     284function CopyAttributes( oSource, oDest, oSkipAttributes )
     285{
     286        var aAttributes = oSource.attributes ;
     287
     288        for ( var n = 0 ; n < aAttributes.length ; n++ )
     289        {
     290                var oAttribute = aAttributes[n] ;
     291
     292                if ( oAttribute.specified )
     293                {
     294                        var sAttName = oAttribute.nodeName ;
     295                        // We can set the type only once, so do it with the proper value, not copying it.
     296                        if ( sAttName in oSkipAttributes )
     297                                continue ;
     298
     299                        var sAttValue = oSource.getAttribute( sAttName, 2 ) ;
     300                        if ( sAttValue == null )
     301                                sAttValue = oAttribute.nodeValue ;
     302
     303                        oDest.setAttribute( sAttName, sAttValue, 0 ) ;  // 0 : Case Insensitive
     304                }
     305        }
     306        // The style:
     307        oDest.style.cssText = oSource.style.cssText ;
     308}
     309
     310// Move the contents from one node to the other
     311function MoveContents( oSource, oDest )
     312{
     313        while ( oSource.firstChild )
     314        {
     315                var oNode = oSource.removeChild( oSource.firstChild ) ;
     316                oDest.appendChild( oNode ) ;
     317        }
     318}
  • editor/dialog/fck_button.html

     
    4747                GetE('txtName').value   = oActiveEl.name ;
    4848                GetE('txtValue').value  = oActiveEl.value ;
    4949                GetE('txtType').value   = oActiveEl.type ;
    50 
    51                 GetE('txtType').disabled = true ;
    5250        }
    5351        else
    5452                oActiveEl = null ;
     
    6260{
    6361        oEditor.FCKUndo.SaveUndoStep() ;
    6462       
    65         if ( !oActiveEl )
    66         {
    67                 oActiveEl = oEditor.FCK.EditorDocument.createElement( 'INPUT' ) ;
    68                 oActiveEl.type = GetE('txtType').value ;
    69                 oActiveEl = oEditor.FCK.InsertElement( oActiveEl ) ;
    70         }
     63        oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {name: GetE('txtName').value, type: GetE('txtType').value } ) ;
    7164
    72         oActiveEl.name = GetE('txtName').value ;
    7365        SetAttribute( oActiveEl, 'value', GetE('txtValue').value ) ;
    7466
    7567        return true ;
  • editor/dialog/fck_checkbox.html

     
    6060{
    6161        oEditor.FCKUndo.SaveUndoStep() ;
    6262       
    63         if ( !oActiveEl )
    64         {
    65                 oActiveEl = oEditor.FCK.EditorDocument.createElement( 'INPUT' ) ;
    66                 oActiveEl.type = 'checkbox' ;
    67                 oActiveEl = oEditor.FCK.InsertElement( oActiveEl ) ;
    68         }
     63        oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {name: GetE('txtName').value, type: 'checkbox' } ) ;
    6964
    70         if ( GetE('txtName').value.length > 0 )
    71                 oActiveEl.name = GetE('txtName').value ;
    72 
    7365        if ( oEditor.FCKBrowserInfo.IsIE )
    7466                oActiveEl.value = GetE('txtValue').value ;
    7567        else
  • editor/dialog/fck_hiddenfield.html

     
    7070{
    7171        oEditor.FCKUndo.SaveUndoStep() ;
    7272       
    73         if ( !oActiveEl )
    74         {
    75                 oActiveEl = FCK.EditorDocument.createElement( 'INPUT' ) ;
    76                 oActiveEl.type = 'hidden' ;
     73        oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {name: GetE('txtName').value, type: 'hidden' } ) ;
    7774
    78                 oFakeImage = null ;
    79         }
    80 
    81         oActiveEl.name = GetE('txtName').value ;
    8275        SetAttribute( oActiveEl, 'value', GetE('txtValue').value ) ;
    8376
    8477        if ( !oFakeImage )
    8578        {
    8679                oFakeImage      = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__InputHidden', oActiveEl ) ;
    8780                oFakeImage.setAttribute( '_fckinputhidden', 'true', 0 ) ;
    88                 oFakeImage      = FCK.InsertElement( oFakeImage ) ;
     81
     82                oActiveEl.parentNode.insertBefore( oFakeImage, oActiveEl ) ;
     83                oActiveEl.parentNode.removeChild( oActiveEl ) ;
    8984        }
    9085        else
    9186                oEditor.FCKUndo.SaveUndoStep() ;
    9287
    93         oEditor.FCKFlashProcessor.RefreshView( oFakeImage, oActiveEl ) ;
    94 
    9588        return true ;
    9689}
    9790
  • editor/dialog/fck_radiobutton.html

     
    6060{
    6161        oEditor.FCKUndo.SaveUndoStep() ;
    6262       
    63         if ( !oActiveEl )
    64         {
    65                 oActiveEl = oEditor.FCK.EditorDocument.createElement( 'INPUT' ) ;
    66                 oActiveEl.type = 'radio' ;
    67                 oActiveEl = oEditor.FCK.InsertElement( oActiveEl ) ;
    68         }
     63        oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {name: GetE('txtName').value, type: 'radio' } ) ;
    6964
    70         if ( GetE('txtName').value.length > 0 )
    71                 oActiveEl.name = GetE('txtName').value ;
    72 
    7365        if ( oEditor.FCKBrowserInfo.IsIE )
    7466                oActiveEl.value = GetE('txtValue').value ;
    7567        else
  • editor/dialog/fck_select.html

     
    8282        if ( sSize == null || isNaN( sSize ) || sSize <= 1 )
    8383                sSize = '' ;
    8484
    85         if ( !oActiveEl )
    86         {
    87                 oActiveEl = oEditor.FCK.InsertElement( 'select' ) ;
    88         }
     85        oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'SELECT', {name: GetE('txtName').value} ) ;
    8986
    90         SetAttribute( oActiveEl, 'name' , GetE('txtName').value ) ;
    9187        SetAttribute( oActiveEl, 'size' , sSize ) ;
    9288        oActiveEl.multiple = ( sSize.length > 0 && GetE('chkMultiple').checked ) ;
    9389
  • editor/dialog/fck_textarea.html

     
    5959function Ok()
    6060{
    6161        oEditor.FCKUndo.SaveUndoStep() ;
    62        
    63         if ( !oActiveEl )
    64         {
    65                 oActiveEl = oEditor.FCK.InsertElement( 'textarea' ) ;
    66         }
    6762
    68         oActiveEl.name = GetE('txtName').value ;
     63        oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'TEXTAREA', {name: GetE('txtName').value} ) ;
     64
    6965        SetAttribute( oActiveEl, 'cols', GetE('txtCols').value ) ;
    7066        SetAttribute( oActiveEl, 'rows', GetE('txtRows').value ) ;
    7167
  • editor/dialog/fck_textfield.html

     
    4949                GetE('txtSize').value   = GetAttribute( oActiveEl, 'size' ) ;
    5050                GetE('txtMax').value    = GetAttribute( oActiveEl, 'maxLength' ) ;
    5151                GetE('txtType').value   = oActiveEl.type ;
    52 
    53                 GetE('txtType').disabled = true ;
    5452        }
    5553        else
    5654                oActiveEl = null ;
     
    7573                return false ;
    7674        }
    7775
    78         if ( !oActiveEl )
    79         {
    80                 oActiveEl = oEditor.FCK.EditorDocument.createElement( 'INPUT' ) ;
    81                 oActiveEl.type = GetE('txtType').value ;
    82                 oEditor.FCKUndo.SaveUndoStep() ;
    83                 oActiveEl = oEditor.FCK.InsertElement( oActiveEl ) ;
    84         }
     76        oEditor.FCKUndo.SaveUndoStep() ;
    8577
    86         oActiveEl.name = GetE('txtName').value ;
     78        oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {name: GetE('txtName').value, type: GetE('txtType').value } ) ;
     79
    8780        SetAttribute( oActiveEl, 'value'        , GetE('txtValue').value ) ;
    8881        SetAttribute( oActiveEl, 'size'         , GetE('txtSize').value ) ;
    8982        SetAttribute( oActiveEl, 'maxlength', GetE('txtMax').value ) ;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy