Ticket #676: 676.patch
File 676.patch, 10.1 KB (added by , 17 years ago) |
---|
-
editor/dialog/common/fck_dialog_common.js
206 206 else 207 207 window.open( url, 'FCKBrowseWindow', sOptions ) ; 208 208 } 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 */ 220 function 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 284 function 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 311 function 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
47 47 GetE('txtName').value = oActiveEl.name ; 48 48 GetE('txtValue').value = oActiveEl.value ; 49 49 GetE('txtType').value = oActiveEl.type ; 50 51 GetE('txtType').disabled = true ;52 50 } 53 51 else 54 52 oActiveEl = null ; … … 62 60 { 63 61 oEditor.FCKUndo.SaveUndoStep() ; 64 62 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 } ) ; 71 64 72 oActiveEl.name = GetE('txtName').value ;73 65 SetAttribute( oActiveEl, 'value', GetE('txtValue').value ) ; 74 66 75 67 return true ; -
editor/dialog/fck_checkbox.html
60 60 { 61 61 oEditor.FCKUndo.SaveUndoStep() ; 62 62 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' } ) ; 69 64 70 if ( GetE('txtName').value.length > 0 )71 oActiveEl.name = GetE('txtName').value ;72 73 65 if ( oEditor.FCKBrowserInfo.IsIE ) 74 66 oActiveEl.value = GetE('txtValue').value ; 75 67 else -
editor/dialog/fck_hiddenfield.html
70 70 { 71 71 oEditor.FCKUndo.SaveUndoStep() ; 72 72 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' } ) ; 77 74 78 oFakeImage = null ;79 }80 81 oActiveEl.name = GetE('txtName').value ;82 75 SetAttribute( oActiveEl, 'value', GetE('txtValue').value ) ; 83 76 84 77 if ( !oFakeImage ) 85 78 { 86 79 oFakeImage = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__InputHidden', oActiveEl ) ; 87 80 oFakeImage.setAttribute( '_fckinputhidden', 'true', 0 ) ; 88 oFakeImage = FCK.InsertElement( oFakeImage ) ; 81 82 oActiveEl.parentNode.insertBefore( oFakeImage, oActiveEl ) ; 83 oActiveEl.parentNode.removeChild( oActiveEl ) ; 89 84 } 90 85 else 91 86 oEditor.FCKUndo.SaveUndoStep() ; 92 87 93 oEditor.FCKFlashProcessor.RefreshView( oFakeImage, oActiveEl ) ;94 95 88 return true ; 96 89 } 97 90 -
editor/dialog/fck_radiobutton.html
60 60 { 61 61 oEditor.FCKUndo.SaveUndoStep() ; 62 62 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' } ) ; 69 64 70 if ( GetE('txtName').value.length > 0 )71 oActiveEl.name = GetE('txtName').value ;72 73 65 if ( oEditor.FCKBrowserInfo.IsIE ) 74 66 oActiveEl.value = GetE('txtValue').value ; 75 67 else -
editor/dialog/fck_select.html
82 82 if ( sSize == null || isNaN( sSize ) || sSize <= 1 ) 83 83 sSize = '' ; 84 84 85 if ( !oActiveEl ) 86 { 87 oActiveEl = oEditor.FCK.InsertElement( 'select' ) ; 88 } 85 oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'SELECT', {name: GetE('txtName').value} ) ; 89 86 90 SetAttribute( oActiveEl, 'name' , GetE('txtName').value ) ;91 87 SetAttribute( oActiveEl, 'size' , sSize ) ; 92 88 oActiveEl.multiple = ( sSize.length > 0 && GetE('chkMultiple').checked ) ; 93 89 -
editor/dialog/fck_textarea.html
59 59 function Ok() 60 60 { 61 61 oEditor.FCKUndo.SaveUndoStep() ; 62 63 if ( !oActiveEl )64 {65 oActiveEl = oEditor.FCK.InsertElement( 'textarea' ) ;66 }67 62 68 oActiveEl.name = GetE('txtName').value ; 63 oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'TEXTAREA', {name: GetE('txtName').value} ) ; 64 69 65 SetAttribute( oActiveEl, 'cols', GetE('txtCols').value ) ; 70 66 SetAttribute( oActiveEl, 'rows', GetE('txtRows').value ) ; 71 67 -
editor/dialog/fck_textfield.html
49 49 GetE('txtSize').value = GetAttribute( oActiveEl, 'size' ) ; 50 50 GetE('txtMax').value = GetAttribute( oActiveEl, 'maxLength' ) ; 51 51 GetE('txtType').value = oActiveEl.type ; 52 53 GetE('txtType').disabled = true ;54 52 } 55 53 else 56 54 oActiveEl = null ; … … 75 73 return false ; 76 74 } 77 75 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() ; 85 77 86 oActiveEl.name = GetE('txtName').value ; 78 oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {name: GetE('txtName').value, type: GetE('txtType').value } ) ; 79 87 80 SetAttribute( oActiveEl, 'value' , GetE('txtValue').value ) ; 88 81 SetAttribute( oActiveEl, 'size' , GetE('txtSize').value ) ; 89 82 SetAttribute( oActiveEl, 'maxlength', GetE('txtMax').value ) ;