Ticket #2816: 2816_2.patch
File 2816_2.patch, 22.4 KB (added by , 15 years ago) |
---|
-
_source/core/editor.js
380 380 execCommand : function( commandName, data ) 381 381 { 382 382 var command = this.getCommand( commandName ); 383 var exeResult; 384 var commandEvent = 385 386 /** 387 * The event data for this command 388 * @type FCKEDITOR.command.Event 389 */ 390 { 391 name :commandName, 392 command :command 393 }; 383 394 if ( command && command.state != CKEDITOR.TRISTATE_DISABLED ) 384 return command.exec( this, data ); 395 { 396 this.fire( 'beforeCommandExec' , commandEvent ); 397 exeResult = command.exec( this , data ); 398 this.fire( 'afterCommandExec' , commandEvent ); 399 return exeResult; 400 } 385 401 386 402 // throw 'Unknown command name "' + commandName + '"'; 387 403 return false; -
_source/plugins/dialog/plugin.js
205 205 206 206 this.on( 'ok', function( evt ) 207 207 { 208 this._.editor.fire('beforeDialogClose'); 208 209 iterContents( function( item ) 209 210 { 210 211 if ( item.validate ) … … 234 235 235 236 this.on( 'cancel', function( evt ) 236 237 { 238 this._.editor.fire('beforeDialogClose'); 237 239 iterContents( function( item ) 238 240 { 239 241 if ( item.isChanged() ) … … 461 463 } ); 462 464 463 465 // Save editor selection and grab the focus. 464 if ( !this._.parentDialog )465 this.saveSelection();466 466 this._.dummyText.focus(); 467 467 this._.dummyText.$.select(); 468 468 469 this._.editor.fire('beforeDialogShow', this); 469 470 // Execute onLoad for the first show. 470 471 this.fireOnce( 'load', {} ); 471 472 this.fire( 'show', {} ); … … 575 576 CKEDITOR.document.removeListener( 'keydown', accessKeyDownHandler ); 576 577 CKEDITOR.document.removeListener( 'keyup', accessKeyUpHandler ); 577 578 578 // Restore focus and (if not already restored) selection in the editing area.579 this.restoreSelection();580 this._.editor.focus();581 579 } 582 580 else 583 581 CKEDITOR.dialog._.currentZIndex -= 10; … … 818 816 getParentEditor : function() 819 817 { 820 818 return this._.editor; 821 },822 823 /**824 * Saves the current selection position in the editor.825 * This function is automatically called when a non-nested dialog is opened,826 * but it may also be called by event handlers in dialog definition.827 * @example828 */829 saveSelection : function()830 {831 if ( this._.editor.mode )832 {833 var selection = new CKEDITOR.dom.selection( this._.editor.document );834 this._.selectedRanges = selection.getRanges();835 }836 },837 838 /**839 * Clears the saved selection in the dialog object.840 * This function should be called if the dialog's code has already changed the841 * current selection position because the dialog closed. (e.g. at onOk())842 * @example843 */844 clearSavedSelection : function()845 {846 delete this._.selectedRanges;847 },848 849 /**850 * Restores the editor's selection from the previously saved position in this851 * dialog.852 * This function is automatically called when a non-nested dialog is closed,853 * but it may also be called by event handlers in dialog definition.854 * @example855 */856 restoreSelection : function()857 {858 if ( this._.editor.mode && this._.selectedRanges )859 ( new CKEDITOR.dom.selection( this._.editor.document ) ).selectRanges( this._.selectedRanges );860 819 } 820 861 821 }; 862 822 863 823 CKEDITOR.tools.extend( CKEDITOR.dialog, … … 879 839 { 880 840 this._.dialogDefinitions[name] = dialogDefinition; 881 841 }, 882 842 883 843 exists : function( name ) 884 844 { 885 845 return !!this._.dialogDefinitions[ name ]; -
_source/plugins/link/dialogs/link.js
636 636 onShow : function() 637 637 { 638 638 this.fakeObj = false; 639 // IE BUG: Selection must be in the editor for getSelection() to work.640 this.restoreSelection();641 639 var editor = this.getParentEditor(), 642 640 selection = editor.getSelection(), 643 641 ranges = selection.getRanges(), … … 696 694 { 697 695 loadLink.apply( this, [ editor, selection, ranges, element ] ); 698 696 selection.selectElement( element ); 699 this.saveSelection();700 697 } 701 698 702 699 element = rangeRoot.getAscendant( 'img', true ); … … 706 703 element = editor.fakeobjects.restoreElement( this.fakeObj ); 707 704 loadLink.apply( this, [ editor, selection, ranges, element ] ); 708 705 selection.selectElement( this.fakeObj ); 709 this.saveSelection();710 706 } 711 707 } 712 708 … … 803 799 804 800 if ( !this._.selectedElement ) 805 801 { 806 // IE BUG: Selection must be in the editor for getSelection() to work.807 this.restoreSelection();808 this.clearSavedSelection();809 810 802 // Create element if current selection is collapsed. 811 803 var selection = editor.getSelection(), 812 804 ranges = selection.getRanges(); -
_source/plugins/link/dialogs/anchor.js
8 8 // Function called in onShow to load selected element. 9 9 var loadElements = function( editor, selection, ranges, element ) 10 10 { 11 this.saveSelection();12 11 this.editMode = true; 13 12 this.editObj = element; 14 13 … … 36 35 // Insert a new anchor. 37 36 if ( !this.editMode ) 38 37 { 39 // It doesn't work with IE.40 this.restoreSelection();41 this.clearSavedSelection();42 38 43 39 var fakeElement = editor.fakeobjects.protectElement( this.editObj ); 44 40 editor.insertElement( fakeElement ); … … 53 49 this.fakeObj = false; 54 50 this.editMode = false; 55 51 56 // IE BUG: Selection must be in the editor for getSelection() to work.57 this.restoreSelection();58 59 52 var editor = this.getParentEditor(), 60 53 selection = editor.getSelection(), 61 54 ranges = selection.getRanges(); … … 71 64 element = editor.fakeobjects.restoreElement( this.fakeObj ); 72 65 loadElements.apply( this, [ editor, selection, ranges, element ] ); 73 66 selection.selectElement( this.fakeObj ); 74 this.saveSelection();75 67 } 76 68 } 77 69 this.pushDefault(); -
_source/plugins/specialchar/dialogs/specialchar.js
46 46 { 47 47 var columns = this.definition.charColumns, 48 48 chars = this.definition.chars; 49 49 50 50 var html = [ '<table style="width: 320px; height: 100%; border-collapse: separate;" align="center" cellspacing="2" cellpadding="2" border="0">' ]; 51 51 52 52 var i = 0 ; … … 53 53 while ( i < chars.length ) 54 54 { 55 55 html.push( '<tr>' ) ; 56 56 57 57 for( var j = 0 ; j < columns ; j++, i++ ) 58 58 { 59 59 if ( chars[ i ] ) … … 58 58 { 59 59 if ( chars[ i ] ) 60 60 { 61 html.push( 61 html.push( 62 62 '<td width="1%"' + 63 63 ' title="', chars[i].replace( /&/g, '&' ), '"' + 64 64 ' value="', chars[i].replace( /&/g, "&" ), '"' + … … 67 67 } 68 68 else 69 69 html.push( '<td class="DarkBackground"> ' ); 70 70 71 71 html.push( '</td>' ); 72 72 } 73 73 html.push( '</tr>' ); … … 140 140 target = target.$; 141 141 if ( value = target.getAttribute( 'value' ) ) 142 142 { 143 this.getDialog().restoreSelection();144 143 editor.insertHtml( value ); 145 144 this.getDialog().hide(); 146 145 } -
_source/plugins/image/dialogs/image.js
228 228 var oImageOriginal = dialog.editObj[ 'imageOriginal' ]; 229 229 if ( oImageOriginal && oImageOriginal.getCustomData( 'isReady' ) == 'true' ) 230 230 { 231 231 if ( value != undefined ) 232 232 dialog.imageLockRatio = value 233 233 else 234 234 dialog.imageLockRatio = !dialog.imageLockRatio; … … 341 341 { 342 342 this.editObj[ 'image' ] = false; 343 343 this.editMode[ 'image' ] = false; // Default: Create a new Image 344 this.saveSelection();345 344 346 345 this.setValueOf( "Link", "txtUrl", "" ); 347 346 this.setValueOf( "Link", "cmbTarget", "" ); … … 501 500 // Insert a new Image. 502 501 if ( this.editMode[ 'image' ] == false ) 503 502 { 504 // It doesn't work with IE.505 this.restoreSelection();506 this.clearSavedSelection();507 503 508 504 if ( useLink ) 509 505 //Insert a new Link. … … 559 555 this.dimensionsInStyle[ 'height' ] = false; 560 556 this.forceResetSize = false; 561 557 562 // IE BUG: Selection must be in the editor for getSelection() to work.563 this.restoreSelection();564 558 565 559 var editor = this.getParentEditor(), 566 560 selection = editor.getSelection(), … … 602 596 { 603 597 loadElements.apply( this, [ editor, selection, ranges, element ] ); 604 598 selection.selectElement( element ); 605 this.saveSelection();606 599 } 607 600 } 608 601 updateOriginal( this, false ); -
_source/plugins/forms/dialogs/textfield.js
17 17 // Function called in onShow to load selected element. 18 18 var loadSelection = function( editor, selection, ranges, element ) 19 19 { 20 this.saveSelection();21 20 this.editObj = element; 22 21 this.editMode = true; 23 22 … … 49 48 // Default: create a new element. 50 49 this.editMode = false; 51 50 52 // IE BUG: Selection must be in the editor for getSelection() to work.53 this.restoreSelection();54 51 55 52 var editor = this.getParentEditor(), 56 53 selection = editor.getSelection(), … … 86 83 87 84 if ( this.editMode == false ) 88 85 { 89 this.restoreSelection();90 this.clearSavedSelection();91 86 editor.insertElement( this.editObj ); 92 87 } 93 88 return true; -
_source/plugins/forms/dialogs/select.js
44 44 45 45 dialog.editObj = element; 46 46 dialog.editMode = true; 47 dialog.saveSelection();48 47 49 48 dialog.getContentElement( 'info', 'txtName' ).setValue( dialog.editObj.getAttribute( "name" ) ); 50 49 dialog.getContentElement( 'info', 'txtSize' ).setValue( dialog.editObj.getAttribute( "size" ) ); … … 74 73 this.editMode = false; 75 74 this.changedAttibutes = new Array(); 76 75 77 // IE BUG: Selection must be in the editor for getSelection() to work.78 this.restoreSelection();79 76 80 77 var editor = this.getParentEditor(), 81 78 selection = editor.getSelection(), … … 91 88 { 92 89 loadSelection.apply( this, [ editor, selection, ranges, element ] ); 93 90 selection.selectElement( element ); 94 this.saveSelection();95 91 } 96 92 } 97 93 … … 139 135 140 136 if ( this.editMode == false ) 141 137 { 142 this.restoreSelection();143 138 parentEditor.insertElement( this.editObj ); 144 139 } 145 140 return true; -
_source/plugins/forms/dialogs/textarea.js
17 17 // Function called in onShow to load selected element. 18 18 var loadSelection = function( editor, selection, ranges, element ) 19 19 { 20 this.saveSelection();21 20 this.editObj = element; 22 21 this.editMode = true; 23 22 … … 47 46 // Default: create a new element. 48 47 this.editMode = false; 49 48 50 // IE BUG: Selection must be in the editor for getSelection() to work.51 this.restoreSelection();52 49 53 50 var editor = this.getParentEditor(), 54 51 selection = editor.getSelection(), … … 80 77 81 78 if ( this.editMode == false ) 82 79 { 83 this.restoreSelection();84 this.clearSavedSelection();85 80 editor.insertElement( this.editObj ); 86 81 } 87 82 return true; -
_source/plugins/forms/dialogs/radio.js
17 17 // Function called in onShow to load selected element. 18 18 var loadSelection = function( editor, selection, ranges, element ) 19 19 { 20 this.saveSelection();21 20 this.editObj = element; 22 21 this.editMode = true; 23 22 … … 44 43 this.editMode = false; 45 44 this.changedAttibutes = new Array(); 46 45 47 // IE BUG: Selection must be in the editor for getSelection() to work.48 this.restoreSelection();49 46 50 47 var editor = this.getParentEditor(), 51 48 selection = editor.getSelection(), … … 79 76 if ( this.editMode == false ) 80 77 { 81 78 // It doesn't work with IE. 82 this.restoreSelection();83 this.clearSavedSelection();84 79 editor.insertElement( this.editObj ); 85 80 } 86 81 return true; -
_source/plugins/forms/dialogs/button.js
26 26 this.setValueOf( 'info', 'txtValue', value ); 27 27 this.setValueOf( 'info', 'txtType', type ); 28 28 29 this.saveSelection();30 29 this.editMode = true; 31 30 this.editObj = element; 32 31 … … 43 42 // Default: create a new element. 44 43 this.editMode = false; 45 44 46 // IE BUG: Selection must be in the editor for getSelection() to work.47 this.restoreSelection();48 45 49 46 var editor = this.getParentEditor(), 50 47 selection = editor.getSelection(), … … 80 77 81 78 if ( this.editMode == false ) 82 79 { 83 this.restoreSelection();84 this.clearSavedSelection();85 80 editor.insertElement( this.editObj ); 86 81 } 87 82 return true; -
_source/plugins/forms/dialogs/checkbox.js
10 10 minHeight : 230, 11 11 onShow : function() 12 12 { 13 // IE BUG: Selection must be in the editor for getSelectedElement()14 // to work.15 this.restoreSelection();16 17 13 var element = this.getParentEditor().getSelection().getSelectedElement(); 18 14 19 15 if ( element && element.getAttribute( 'type' ) == "checkbox" ) … … 39 35 40 36 if ( isInsertMode ) 41 37 { 42 this.restoreSelection();43 this.clearSavedSelection();44 38 editor.insertElement( element ); 45 39 } 46 40 }, -
_source/plugins/forms/dialogs/hiddenfield.js
17 17 // Function called in onShow to load selected element. 18 18 var loadSelection = function( editor, selection, ranges, element ) 19 19 { 20 this.saveSelection();21 20 this.editObj = element; 22 21 this.editMode = true; 23 22 … … 41 40 this.editMode = false; 42 41 this.changedAttibutes = new Array(); 43 42 44 // IE BUG: Selection must be in the editor for getSelection() to work.45 this.restoreSelection();46 43 47 44 var editor = this.getParentEditor(), 48 45 selection = editor.getSelection(), … … 74 71 75 72 if ( this.editMode == false ) 76 73 { 77 this.restoreSelection();78 this.clearSavedSelection();79 74 editor.insertElement( this.editObj ); 80 75 } 81 76 return true; -
_source/plugins/forms/dialogs/form.js
17 17 // Function called in onShow to load selected element. 18 18 var loadSelection = function( editor, selection, ranges, element ) 19 19 { 20 this.saveSelection();21 20 this.editObj = element; 22 21 this.editMode = true; 23 22 … … 54 53 55 54 if ( this.editMode == false ) 56 55 { 57 this.restoreSelection();58 this.clearSavedSelection();59 56 editor.insertElement( this.editObj ); 60 57 } 61 58 return true; … … 66 63 this.editMode = false; 67 64 this.changedAttibutes = new Array(); 68 65 69 // IE BUG: Selection must be in the editor for getSelection() to work.70 this.restoreSelection();71 66 72 67 var editor = this.getParentEditor(), 73 68 selection = editor.getSelection(), -
_source/plugins/flash/dialogs/flash.js
163 163 var loadElements = function( editor, selection, ranges, fakeElement, realElement ) 164 164 { 165 165 selection.selectElement( fakeElement ); 166 this.saveSelection();167 166 this.editMode[ 'fakeobject' ] = realElement.getName(); 168 167 this.editObj[ 'fakeobject' ] = fakeElement; 169 168 … … 326 325 this.dimensionsInStyle[ 'width' ] = false; 327 326 this.dimensionsInStyle[ 'height' ] = false; 328 327 329 // IE BUG: Selection must be in the editor for getSelection() to work.330 this.restoreSelection();331 328 332 329 var editor = this.getParentEditor(), 333 330 selection = editor.getSelection(), … … 415 412 else 416 413 this.editObj[ 'fakeobject' ] = CKEDITOR.plugins.fakeobjects.protectElement( this.editObj[ 'object' ] ); 417 414 418 // It doesn't work with IE.419 this.restoreSelection();420 this.clearSavedSelection();421 415 editor.insertElement( this.editObj[ 'fakeobject' ] ); 422 416 } 423 417 else -
_source/plugins/table/dialogs/table.js
16 16 onShow : function() 17 17 { 18 18 // Detect if there's a selected table. 19 this.restoreSelection();20 19 var selection = editor.getSelection(), 21 20 ranges = selection.getRanges(), 22 21 me = this, … … 148 147 // Insert the table element if we're creating one. 149 148 if ( !this._.selectedElement ) 150 149 { 151 this.restoreSelection();152 150 editor.insertElement( table ); 153 151 this.clearSavedSelection(); 154 152 } -
_source/plugins/styles/plugin.js
595 595 596 596 CKEDITOR.styleCommand.prototype.exec = function( editor ) 597 597 { 598 editor.focus();599 598 600 599 var doc = editor.document; 601 600 -
_source/plugins/selection/plugin.js
90 90 // IE is the only to provide the "selectionchange" 91 91 // event. 92 92 editor.document.on( 'selectionchange', checkSelectionChangeTimeout, editor ); 93 94 //Destory previous saved selection. 95 editor.document.on( 'selectionchange', function () 96 { 97 editor.dropSavedRanges(); 98 } ); 99 100 // Save selection on editor window blur 101 ( new CKEDITOR.dom.element( editor.document.$.body ) ).on( 'beforedeactivate', 102 function (){ 103 editor.saveSelection(); 104 } ); 93 105 } 94 106 else 95 107 { … … 102 114 } 103 115 }); 104 116 105 editor.addCommand( 'selectAll', selectAllCmd ); 117 //restore selection for commands. 118 if ( CKEDITOR.env.ie ) 119 { 120 editor.on( 'beforeCommandExec', editor.restoreSelection, editor); 121 editor.on( 'beforeDialogShow', editor.restoreSelection, editor); 122 editor.on( 'beforeDialogClose', editor.restoreSelection, editor); 123 } 124 editor.addCommand( 'selectAll', selectAllCmd ); 106 125 editor.ui.addButton( 'SelectAll', 107 126 { 108 127 label : editor.lang.selectAll, … … 142 161 }; 143 162 144 163 /** 164 * Last selection ranges recording 165 * @name selectedRanges 166 * @private 167 * @memberof CKEDITOR.editor 168 * @type CKEDITOR.dom.range 169 */ 170 171 //Selection restore APIs for IE, see #2816 172 if( CKEDITOR.env.ie ) 173 { 174 CKEDITOR.tools.extend( CKEDITOR.editor.prototype, { 175 176 /** 177 * Record the current selection status range of this document. 178 * Note: This save doesn't resistant to dom changes, resort to undo/redo plugin for such need. 179 */ 180 saveSelection : function() 181 { 182 if ( this.mode === 'wysiwyg' && !this._.selectedRanges ) 183 { 184 var selection = new CKEDITOR.dom.selection( this.document ); 185 this._.selectedRanges = selection.getRanges(); 186 } 187 }, 188 189 /** 190 * Clears the saved selection ranges when expired. 191 */ 192 dropSavedRanges : function() 193 { 194 if( this._.selectedRanges ) 195 { 196 delete this._.selectedRanges; 197 } 198 }, 199 200 /** 201 * Retrieve the last saved ranges 202 * @return {CKEDITOR.dom.range} 203 */ 204 getSavedRange: function() 205 { 206 return this._.selectionRanges||null; 207 }, 208 209 /** 210 * Restores the last ranges record and select the ranges in document. 211 */ 212 restoreSelection : function() 213 { 214 if ( this._.selectedRanges && this.mode === 'wysiwyg' ) 215 { 216 ( new CKEDITOR.dom.selection( this.document ) ).selectRanges( this._.selectedRanges ); 217 } 218 } 219 }); 220 } 221 222 223 /** 145 224 * Gets the current selection from the document. 146 225 * @returns {CKEDITOR.dom.selection} A selection object. 147 226 * @example -
_source/plugins/smiley/dialogs/smiley.js
54 54 else if ( targetName != 'img' ) 55 55 return; 56 56 57 this.getDialog().restoreSelection();58 59 57 var src = target.getAttribute( 'src' ), 60 58 title = target.getAttribute( 'title' ); 61 59