MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / load

Function load

lib/web/lazyload/lazyload.js:161–262  ·  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 is spec

(type, urls, callback, obj, context)

Source from the content-addressed store, hash-verified

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

Callers 3

finishFunction · 0.85
lazyload.jsFile · 0.85
getMethod · 0.85

Calls 7

getEnvFunction · 0.85
createNodeFunction · 0.85
_finishFunction · 0.85
pollWebKitFunction · 0.85
pollGeckoFunction · 0.85
pushMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected