Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 't/6504'
  • Loading branch information
oleq committed May 29, 2013
2 parents 89d7407 + bf43638 commit 33a7150
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/editor.js
Expand Up @@ -250,7 +250,9 @@
editor.fireOnce( 'customConfigLoaded' );
} else {
// Load the custom configuration file.
CKEDITOR.scriptLoader.load( customConfig, function() {
// To resolve customConfig race conflicts, use scriptLoader#queue
// instead of scriptLoader#load (#6504).
CKEDITOR.scriptLoader.queue( customConfig, function() {
// If the CKEDITOR.editorConfig function has been properly
// defined in the custom configuration file, cache it.
if ( CKEDITOR.editorConfig )
Expand Down
47 changes: 46 additions & 1 deletion core/scriptloader.js
Expand Up @@ -152,6 +152,51 @@ CKEDITOR.scriptLoader = (function() {
for ( var i = 0; i < scriptCount; i++ ) {
loadScript( scriptUrl[ i ] );
}
}
},

/**
* Loads a script in a queue, so only one is loaded at the same time.
*
* @since 4.1.2
* @param {String} scriptUrl URL pointing to the script to be loaded.
* @param {Function} [callback] A function to be called when the script
* is loaded and executed. A boolean parameter is passed to the callback,
* indicating the success of the load.
*
* @see CKEDITOR.scriptLoader#load
*/
queue: ( function() {
var pending = [];

// Loads the very first script from queue and removes it.
function loadNext() {
var script;

if ( ( script = pending[ 0 ] ) )
this.load( script.scriptUrl, script.callback, CKEDITOR, 0 );
}

return function( scriptUrl, callback ) {
var that = this;

// This callback calls the standard callback for the script
// and loads the very next script from pending list.
function callbackWrapper() {
callback && callback.apply( this, arguments );

// Removed the just loaded script from the queue.
pending.shift();

loadNext.call( that );
};

// Let's add this script to the queue
pending.push( { 'scriptUrl': scriptUrl, 'callback': callbackWrapper } );

// If the queue was empty, then start loading.
if ( pending.length == 1 )
loadNext.call( this );
};
})()
};
})();

0 comments on commit 33a7150

Please sign in to comment.