Skip to content

Commit 33a7150

Browse files
committed
Merge branch 't/6504'
2 parents 89d7407 + bf43638 commit 33a7150

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

core/editor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@
250250
editor.fireOnce( 'customConfigLoaded' );
251251
} else {
252252
// Load the custom configuration file.
253-
CKEDITOR.scriptLoader.load( customConfig, function() {
253+
// To resolve customConfig race conflicts, use scriptLoader#queue
254+
// instead of scriptLoader#load (#6504).
255+
CKEDITOR.scriptLoader.queue( customConfig, function() {
254256
// If the CKEDITOR.editorConfig function has been properly
255257
// defined in the custom configuration file, cache it.
256258
if ( CKEDITOR.editorConfig )

core/scriptloader.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,51 @@ CKEDITOR.scriptLoader = (function() {
152152
for ( var i = 0; i < scriptCount; i++ ) {
153153
loadScript( scriptUrl[ i ] );
154154
}
155-
}
155+
},
156+
157+
/**
158+
* Loads a script in a queue, so only one is loaded at the same time.
159+
*
160+
* @since 4.1.2
161+
* @param {String} scriptUrl URL pointing to the script to be loaded.
162+
* @param {Function} [callback] A function to be called when the script
163+
* is loaded and executed. A boolean parameter is passed to the callback,
164+
* indicating the success of the load.
165+
*
166+
* @see CKEDITOR.scriptLoader#load
167+
*/
168+
queue: ( function() {
169+
var pending = [];
170+
171+
// Loads the very first script from queue and removes it.
172+
function loadNext() {
173+
var script;
174+
175+
if ( ( script = pending[ 0 ] ) )
176+
this.load( script.scriptUrl, script.callback, CKEDITOR, 0 );
177+
}
178+
179+
return function( scriptUrl, callback ) {
180+
var that = this;
181+
182+
// This callback calls the standard callback for the script
183+
// and loads the very next script from pending list.
184+
function callbackWrapper() {
185+
callback && callback.apply( this, arguments );
186+
187+
// Removed the just loaded script from the queue.
188+
pending.shift();
189+
190+
loadNext.call( that );
191+
};
192+
193+
// Let's add this script to the queue
194+
pending.push( { 'scriptUrl': scriptUrl, 'callback': callbackWrapper } );
195+
196+
// If the queue was empty, then start loading.
197+
if ( pending.length == 1 )
198+
loadNext.call( this );
199+
};
200+
})()
156201
};
157202
})();

0 commit comments

Comments
 (0)