@@ -152,6 +152,51 @@ CKEDITOR.scriptLoader = (function() {
152
152
for ( var i = 0 ; i < scriptCount ; i ++ ) {
153
153
loadScript ( scriptUrl [ i ] ) ;
154
154
}
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
+ } ) ( )
156
201
} ;
157
202
} ) ( ) ;
0 commit comments