Skip to content

Commit ca6b17d

Browse files
committed
Merge branch 't/10103' into major
2 parents 1974bda + 497f1d4 commit ca6b17d

File tree

3 files changed

+57
-16
lines changed

3 files changed

+57
-16
lines changed

core/creators/inline.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
// data retrieval possible immediately after the editor creation.
3737
editor.setData( element.getHtml(), null, true );
3838

39-
// Clean during initialization.
40-
editor.resetDirty();
41-
4239
// Once the editor is loaded, start the UI.
4340
editor.on( 'loaded', function() {
4441
editor.fire( 'uiReady' );
@@ -62,6 +59,7 @@
6259
editor.fire( 'mode' );
6360

6461
// The editor is completely loaded for interaction.
62+
editor.status = 'ready';
6563
editor.fireOnce( 'instanceReady' );
6664
CKEDITOR.fire( 'instanceReady', null, editor );
6765

core/creators/themedui.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,6 @@ CKEDITOR.replaceClass = 'ckeditor';
252252

253253
data && editor.setData( data, null, true );
254254

255-
// Clean during initialization.
256-
editor.resetDirty();
257-
258255
// Once the editor is loaded, start the UI.
259256
editor.on( 'loaded', function() {
260257
loadTheme( editor );
@@ -267,6 +264,7 @@ CKEDITOR.replaceClass = 'ckeditor';
267264
editor.resetDirty();
268265

269266
// Editor is completely loaded for interaction.
267+
editor.status = 'ready';
270268
editor.fireOnce( 'instanceReady' );
271269
CKEDITOR.fire( 'instanceReady', null, editor );
272270
});

core/editor.js

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@
103103
*/
104104
this.id = CKEDITOR.tools.getNextId();
105105

106+
/**
107+
* Indicates editor initialization status. The following statuses are available:
108+
*
109+
* * **unloaded**: the initial state - editor's instance has been initialized,
110+
* but its components (config, plugins, language files) are not loaded yet.
111+
* * **loaded**: editor's components have been loaded - see {@link CKEDITOR.editor#loaded} event.
112+
* * **ready**: editor is fully initialized and ready - see {@link CKEDITOR.editor#instanceReady} event.
113+
* * **destroyed**: the editor has been destroyed - see {@link CKEDITOR.editor#method-destroy} method.
114+
*
115+
* @property {String}
116+
*/
117+
this.status = 'unloaded';
118+
106119
/**
107120
* The configurations for this editor instance. It inherits all
108121
* settings defined in {@link CKEDITOR.config}, combined with settings
@@ -140,14 +153,18 @@
140153
this.keystrokeHandler = new CKEDITOR.keystrokeHandler( this );
141154

142155
// Make the editor update its command states on mode change.
143-
this.on( 'mode', updateCommands );
144156
this.on( 'readOnly', updateCommands );
145157
this.on( 'selectionChange', updateCommandsContext );
146158

147159
// Handle startup focus.
148160
this.on( 'instanceReady', function() {
161+
updateCommands.call( this );
162+
// First 'mode' event is fired before this 'instanceReady',
163+
// so to avoid updating commands twice, add this listener here.
164+
this.on( 'mode', updateCommands );
165+
149166
this.config.startupFocus && this.focus();
150-
});
167+
} );
151168

152169
CKEDITOR.fire( 'instanceCreated', null, this );
153170

@@ -172,17 +189,18 @@
172189
}
173190

174191
function updateCommands() {
175-
var command,
176-
commands = this.commands,
192+
var commands = this.commands,
177193
mode = this.mode;
178194

179195
if ( !mode )
180196
return;
181197

182-
for ( var name in commands ) {
183-
command = commands[ name ];
184-
command[ command.startDisabled ? 'disable' : this.readOnly && !command.readOnly ? 'disable' : command.modes[ mode ] ? 'enable' : 'disable' ]();
185-
}
198+
for ( var name in commands )
199+
updateCommand( this, commands[ name ] );
200+
}
201+
202+
function updateCommand( editor, cmd ) {
203+
cmd[ cmd.startDisabled ? 'disable' : editor.readOnly && !cmd.readOnly ? 'disable' : cmd.modes[ editor.mode ] ? 'enable' : 'disable' ]();
186204
}
187205

188206
function updateCommandsContext( ev ) {
@@ -526,6 +544,7 @@
526544
for ( i = 0; i < editor.config.blockedKeystrokes.length; i++ )
527545
editor.keystrokeHandler.blockedKeystrokes[ editor.config.blockedKeystrokes[ i ] ] = 1;
528546

547+
editor.status = 'loaded';
529548
editor.fireOnce( 'loaded' );
530549
CKEDITOR.fire( 'instanceLoaded', null, editor );
531550
});
@@ -571,6 +590,11 @@
571590
addCommand: function( commandName, commandDefinition ) {
572591
commandDefinition.name = commandName.toLowerCase();
573592
var cmd = new CKEDITOR.command( this, commandDefinition );
593+
594+
// Update command when added after editor has been already initialized.
595+
if ( this.status == 'ready' && this.mode )
596+
updateCommand( this, cmd );
597+
574598
return this.commands[ commandName ] = cmd;
575599
},
576600

@@ -593,6 +617,8 @@
593617

594618
this.editable( null );
595619

620+
this.status = 'destroyed';
621+
596622
this.fire( 'destroy' );
597623

598624
// Plug off all listeners to prevent any further events firing.
@@ -865,7 +891,7 @@
865891
*
866892
* function beforeUnload( evt ) {
867893
* if ( CKEDITOR.instances.editor1.checkDirty() )
868-
* return e.returnValue = "You will lose the changes made in the editor.";
894+
* return evt.returnValue = "You will lose the changes made in the editor.";
869895
* }
870896
*
871897
* if ( window.addEventListener )
@@ -876,7 +902,7 @@
876902
* @returns {Boolean} `true` if the contents contain changes.
877903
*/
878904
checkDirty: function() {
879-
return this._.previousValue !== this.getSnapshot();
905+
return this.status == 'ready' && this._.previousValue !== this.getSnapshot();
880906
},
881907

882908
/**
@@ -1080,6 +1106,16 @@ CKEDITOR.ELEMENT_MODE_INLINE = 3;
10801106
* @param {CKEDITOR.editor} editor The editor instance that has been created.
10811107
*/
10821108

1109+
/**
1110+
* Fired when CKEDITOR instance's components (config, languages and plugins) are fully
1111+
* loaded and initialized. However, the editor will be fully ready to for interaction
1112+
* on {@link CKEDITOR#instanceReady}.
1113+
*
1114+
* @event instanceLoaded
1115+
* @member CKEDITOR
1116+
* @param {CKEDITOR.editor} editor This editor instance that has been loaded.
1117+
*/
1118+
10831119
/**
10841120
* Fired when a CKEDITOR instance is destroyed.
10851121
*
@@ -1230,6 +1266,15 @@ CKEDITOR.ELEMENT_MODE_INLINE = 3;
12301266
* @param {CKEDITOR.editor} editor This editor instance.
12311267
*/
12321268

1269+
/**
1270+
* Fired when editor's components (config, languages and plugins) are fully
1271+
* loaded and initialized. However, the editor will be fully ready to for interaction
1272+
* on {@link #instanceReady}.
1273+
*
1274+
* @event loaded
1275+
* @param {CKEDITOR.editor} editor This editor instance.
1276+
*/
1277+
12331278
/**
12341279
* Internal event to perform the {@link #method-insertHtml} call.
12351280
*

0 commit comments

Comments
 (0)