Ticket #676: 676_2.patch
File 676_2.patch, 10.7 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 // Force the creation only if some of the special attributes have changed: 230 var bChanged = false; 231 for( var attName in oAttributes ) 232 bChanged |= ( oOriginal.getAttribute( attName, 2) != oAttributes[attName] ) ; 233 234 if ( bChanged ) 235 { 236 oldNode = oOriginal ; 237 oOriginal = null ; 238 } 239 } 240 241 // If the node existed (and it's not IE), then we just have to update its attributes 242 if ( oOriginal ) 243 { 244 oNewNode = oOriginal ; 245 } 246 else 247 { 248 // #676, IE doesn't play nice with the name or type attribute 249 if ( oEditor.FCKBrowserInfo.IsIE ) 250 { 251 var sbHTML = [] ; 252 sbHTML.push( '<' + nodeName ) ; 253 for( var prop in oAttributes ) 254 { 255 sbHTML.push( ' ' + prop + '="' + oAttributes[prop] + '"' ) ; 256 } 257 sbHTML.push( '>' ) ; 258 if ( !oEditor.FCKListsLib.EmptyElements[nodeName.toLowerCase()] ) 259 sbHTML.push( '</' + nodeName + '>' ) ; 260 261 oNewNode = oEditor.FCK.EditorDocument.createElement( sbHTML.join('') ) ; 262 // Check if we are just changing the properties of an existing node: copy its properties 263 if ( oldNode ) 264 { 265 CopyAttributes( oldNode, oNewNode, oAttributes ) ; 266 MoveContents( oldNode, oNewNode ) ; 267 oldNode.parentNode.removeChild( oldNode ) ; 268 oldNode = null ; 269 270 if ( oEditor.FCKDialog.SelectionData ) 271 { 272 // Trick to refresh the selection object and avoid error in fckdialog.html Selection.EnsureSelection 273 var oSel = oEditor.FCK.EditorDocument.selection ; 274 oEditor.FCKDialog.SelectionData = oSel.createRange() ; // Now oSel.type will be 'None' reflecting the real situation 275 } 276 } 277 oNewNode = oEditor.FCK.InsertElement( oNewNode ) ; 278 279 // FCKDialog.SelectionData is broken by now since we've deleted the previously selected element. 280 // So we need to reassign it. 281 if ( oEditor.FCKDialog.SelectionData ) 282 { 283 var range = oEditor.FCK.EditorDocument.body.createControlRange() ; 284 range.add( oNewNode ) ; 285 oEditor.FCKDialog.SelectionData = range ; 286 } 287 } 288 else 289 { 290 oNewNode = oEditor.FCK.InsertElement( nodeName ) ; 291 } 292 } 293 294 // Set the basic attributes 295 for( var attName in oAttributes ) 296 oNewNode.setAttribute( attName, oAttributes[attName], 0 ) ; // 0 : Case Insensitive 297 298 return oNewNode ; 299 } 300 301 // Copy all the attributes from one node to the other, kinda like a clone 302 // But oSkipAttributes is an object with the attributes that must NOT be copied 303 function CopyAttributes( oSource, oDest, oSkipAttributes ) 304 { 305 var aAttributes = oSource.attributes ; 306 307 for ( var n = 0 ; n < aAttributes.length ; n++ ) 308 { 309 var oAttribute = aAttributes[n] ; 310 311 if ( oAttribute.specified ) 312 { 313 var sAttName = oAttribute.nodeName ; 314 // We can set the type only once, so do it with the proper value, not copying it. 315 if ( sAttName in oSkipAttributes ) 316 continue ; 317 318 var sAttValue = oSource.getAttribute( sAttName, 2 ) ; 319 if ( sAttValue == null ) 320 sAttValue = oAttribute.nodeValue ; 321 322 oDest.setAttribute( sAttName, sAttValue, 0 ) ; // 0 : Case Insensitive 323 } 324 } 325 // The style: 326 oDest.style.cssText = oSource.style.cssText ; 327 } 328 329 // Move the contents from one node to the other 330 function MoveContents( oSource, oDest ) 331 { 332 while ( oSource.firstChild ) 333 { 334 var oNode = oSource.removeChild( oSource.firstChild ) ; 335 oDest.appendChild( oNode ) ; 336 } 337 } -
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 ) ;