Skip to content
Permalink
Browse files

Merge branch 't/6504'

  • Loading branch information...
oleq committed May 29, 2013
2 parents 89d7407 + bf43638 commit 33a71502f0fb3d4821bc439a15dc6986135fe41e
Showing with 49 additions and 2 deletions.
  1. +3 −1 core/editor.js
  2. +46 −1 core/scriptloader.js
@@ -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 )
@@ -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.
You can’t perform that action at this time.