MCPcopy
hub / github.com/NUKnightLab/TimelineJS3 / load

Method load

src/js/core/Load.js:158–259  ·  view source on GitHub ↗

Loads the specified resources, or the next resource of the specified type in the queue if no resources are specified. If a resource of the specified type is already being loaded, the new request will be queued until the first request has been finished. When an array of resource URLs

(type, urls, callback, obj, context)

Source from the content-addressed store, hash-verified

156 @private
157 */
158 load(type, urls, callback, obj, context) {
159 var _finish = function() { this.finish(type); }.bind(this),
160 isCSS = type === 'css',
161 nodes = [],
162 i, len, node, p, pendingUrls, url;
163
164
165
166 if (urls) {
167 // If urls is a string, wrap it in an array. Otherwise assume it's an
168 // array and create a copy of it so modifications won't be made to the
169 // original.
170 urls = typeof urls === 'string' ? [urls] : urls.concat();
171
172 // Create a request object for each URL. If multiple URLs are specified,
173 // the callback will only be executed after all URLs have been loaded.
174 //
175 // Sadly, Firefox and Opera are the only browsers capable of loading
176 // scripts in parallel while preserving execution order. In all other
177 // browsers, scripts must be loaded sequentially.
178 //
179 // All browsers respect CSS specificity based on the order of the link
180 // elements in the DOM, regardless of the order in which the stylesheets
181 // are actually downloaded.
182 if (isCSS || this.env.async || this.env.gecko || this.env.opera) {
183 // Load in parallel.
184 this.queue[type].push({
185 urls: urls,
186 callback: callback,
187 obj: obj,
188 context: context
189 });
190 } else {
191 // Load sequentially.
192 for (i = 0, len = urls.length; i < len; ++i) {
193 this.queue[type].push({
194 urls: [urls[i]],
195 callback: i === len - 1 ? callback : null, // callback is only added to the last URL
196 obj: obj,
197 context: context
198 });
199 }
200 }
201 }
202
203 // If a previous load request of this type is currently in progress, we'll
204 // wait our turn. Otherwise, grab the next item in the queue.
205 if (this.pending[type] || !(p = this.pending[type] = this.queue[type].shift())) {
206 return;
207 }
208
209
210 pendingUrls = p.urls;
211
212 for (i = 0, len = pendingUrls.length; i < len; ++i) {
213 url = pendingUrls[i];
214
215 if (isCSS) {

Callers 5

finishMethod · 0.95
cssMethod · 0.95
jsMethod · 0.95
createMediaMethod · 0.80
convert_json.pyFile · 0.80

Calls 4

finishMethod · 0.95
createNodeMethod · 0.95
pollWebKitMethod · 0.95
pollGeckoMethod · 0.95

Tested by

no test coverage detected