Load scripts into the page, and call a callback when they are loaded.

@param {Array} scripts The scripts to be loaded.
@param {Function} loadedCallback The function to be called when all the scripts have loaded.
8488
function loadScripts(scripts, loadedCallback) {
    var srcs = [], property, count, i, src,
        countDown = function () {
          count -= 1;
          if (!count) {
            loadedCallback();
          }
        };

    for (property in scripts) {
      if (!(property in window)) {
        srcs.push(scripts[property]);
      }
    }

    count = srcs.length;
    if (!count) {
      loadedCallback();
    }

    for (i = 0; i < srcs.length; i += 1) {
      src = srcs[i];
      loadScript(src, countDown);
    }
  }
630133
public void setScripts(java.util.Collection<Script> scripts) {
        if (scripts == null) {
            this.scripts = null;
            return;
        }

        this.scripts = new java.util.ArrayList<Script>(scripts);
    }
763569
function loadModuleList() {
  $.getScript( modulesPath+"portal-ng-modules.js" )
    .done(
      function( script, textStatus ) {
        log( 'loadModuleList', textStatus );
        ajaxOngoing--;
      }
    )
    .fail(
      function( jqxhr, settings, exception ) {
        logErr( 'loadModuleList', exception );
        ajaxOngoing--;
      }
    );
}
1165771
function _load(url) {

    var script = document.createElement('script'),
      done = false;
    script.src = url;

    // Once the script has been loaded remove the tag from the document.
    script.onload = script.onreadystatechange = function() {
      if ( !done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") ) {
        done = true;
        script.onload = script.onreadystatechange = null;
        if ( script && script.parentNode ) {
          script.parentNode.removeChild( script );
        }
      }
    };

    if ( !head ) {
      head = document.getElementsByTagName('head')[0];
    }

    // Actually load script.
    head.appendChild( script );
  }
324317
public static void loadAsync(final ThemeBundle bundle, final ThemeAsyncCallback callback) {
        GWT.runAsync(new RunAsyncCallback() {
            @Override
            public void onSuccess() {
                if(bundle != null) {
                    if(elements == null) {
                        elements = new ArrayList<>();
                    } else {
                        unload();
                    }

                    // More resources might be loaded in the future.
                    elements.add(StyleInjector.injectStylesheet(bundle.style().getText()));
                    elements.add(StyleInjector.injectStylesheet(bundle.overrides().getText()));
                }

                if(callback != null) {
                    callback.onSuccess(elements.size());
                }
            }
            @Override
            public void onFailure(Throwable reason) {
                if(callback != null) {
                    callback.onFailure(reason);
                }
            }
        });
    }
290530
function(images, callback) {
            var loaded = 0;
            images.forEach(function(src) {
                var image = new Image();
                image.onload = function() {
                    ++loaded;
                    loaded === images.length && callback();
                };
                image.src = src;
            });
        }
807566
private function checkCallback() : void
    {
        if (isset($this->onload) && !$this->is_loaded) {
            $this->is_loaded = true;
            call_user_func($this->onload, $this);
        }
    }
364275
function init(callbackName, callbacks = [() => {}], vars){

	callbacks.forEach(cb => cb(this, vars));

	this[callbackName]? this[callbackName](vars): null;
	this::trigger(callbackName, vars);
}
1319473
protected function autoloadJS()
	{
		if (!is_string($this->callback))
		{
			return;
		}

		try
		{
			$this->js = FunctionProvider::get($this->callback);
		}
		catch (InvalidArgumentException $e)
		{
			// Do nothing
		}
	}
1214868
function(script){
			var myqueue, 
				stel, 
				src = (script && script.src) || this.options.src,
				rootSrc = this.options.rootSrc;
			
			//set yourself as the current file
			File.cur(rootSrc);
			
			// mark yourself as 'loaded'.  
			this.isLoaded = true;
			
			// If we are IE, get the queue from interactives
			// TODO move this out of this function
			if (support.interactive && src) {
				myqueue = interactives[src];
			}
			// is there a case in IE where, this makes sense?
			// in other browsers, the queue of items to load is
			// what is in pending
			if(!myqueue){
				myqueue = pending.slice(0);
				pending = [];
			}
			
			// if we have nothing, mark us as complete (resolve if deferred)
			if(!myqueue.length){
				this.complete();
				return;
			}
			
			// now we have to figure out how to wire up our pending steals
			var self = this,
				set = [],
				// the current
				joiner,  
				initial = [],
				
				isProduction = steal.options.env == 'production',
				
				files = [],
				
				// a helper that basically does a join
				// when everything in arr's func method is called,
				// call func2 on obj
				whenEach = function(arr, func, obj, func2){
					var big = [obj, func2];
					each(arr, function(i, item){
						big.unshift(item, func)
					});
					when.apply(steal, big);
				},
				// a helper that does the oposite of a join.  When
				// obj's func method is called, call func2 on all items.
				whenThe = function(obj, func, items, func2){
					each(items, function(i, item){
						when(obj, func, item, func2)
					})
				};
			
			
			//now go through what you stole and hook everything up
			//BUT, we go through backwards
			each(myqueue.reverse(), function(i, item){
				
				//in production, ignore ignored items (like steal/dev
				if(isProduction && item.ignore){
					return;
				}
				
				// make a steal object
				stel = steal.p.make( item );
				
				// add it as a dependency, circular are not allowed
				self.dependencies.unshift(stel)
				
				
				if(stel.waits === false){ // file
					// on the current 
					files.push(stel);
				
				}else{ // function
					
					// essentially have to bind current files to call previous joiner's load
					// and to wait for current stel's complete
					
					if(!joiner){ // if no previous joiner, then we are at the start of a file
						
						// when they are complete, complete the file
						whenEach( files.concat(stel), "complete", self, "complete");
						
						// if there was a function then files, then end, function loads all files
						if(files.length){
							whenThe(stel,"complete", files ,"load")
						}
						
					} else { //   function,  file1, file2, file3, joiner function
						
						whenEach(files.concat(stel) , "complete", joiner, "load");
						
						// make stel complete load files
						whenThe(stel,"complete", files.length ? files : [joiner] ,"load")
						
					}
					// the joiner is the previous thing
					joiner = stel;
					files = [];
					
				}
			});
			
			// now we should be left with the starting files
			if(files.length){
				// we have initial files
				// if there is a joiner, we need to load it when the initial files are complete
				if(joiner){
					whenEach(files, "complete", joiner, "load");
				} else {
					whenEach(files, "complete", self, "complete");
				}
				// reverse it back and load each initial file
				each(files.reverse(), function(){
					this.load();
				});
			} else if(joiner){
				// we have inital function
				joiner.load()
			} else {
				// we had nothing
				self.complete();
			}

		}
1101294
function (images, callback) {
        var self = this,
            unloaded = images.length;

        if (unloaded === 0) {
          callback(images);
        }

        images.each(function () {
          single_image_loaded(self.S(this), function () {
            unloaded -= 1;
            if (unloaded === 0) {
              callback(images);
            }
          });
        });
      }
1097064
function(script) {
			if (gui.Type.isString(script)) {
				var func = gui.Object.lookup(script);
				if (func) {
					script = func;
				} else {
					throw new Error(this + ' could not locate "' + script + '"');
				}
			}
			if (gui.Type.isFunction(script)) {
				this.script.load(script);
			} else {
				throw new TypeError(this + " could not load script");
			}
		}
1134980
function () {
                    var i, len;

                    // eval scripts.
                    if (data.scripts && data.scripts.length) {
                        for (i = 0, len = data.scripts.length; i < len; i++) {
                            Util.globalEval(data.scripts[i]);
                        }
                    }

                    callback && callback(data);
                }
44423
public static void whenReady(final String scriptname, final EventListener function) {
    List<EventListener> eventList = JsResources.eventLisenerQueue.get(scriptname);
    if (eventList == null) {
      eventList = new ArrayList<>();
      JsResources.eventLisenerQueue.put(scriptname, eventList);
    }
    eventList.add(function);
    if (BooleanUtils.isTrue(JsResources.initializationStarted.get(scriptname))
        || JsResources.isInHeader(scriptname)) {
      if (JsResources.isInitialized(scriptname)) {
        JsResources.eventLisenerQueue.get(scriptname)
            .forEach(action -> action.handleEvent(JsResources.rememberEvent.get(scriptname)));
        JsResources.eventLisenerQueue.get(scriptname).clear();
      }
      return;
    }
    JsResources.initializationStarted.put(scriptname, Boolean.TRUE);

    final ScriptElement jsScript = Browser.getDocument().createScriptElement();
    if (StringUtils.endsWith(scriptname, ".js")) {
      jsScript.setSrc(scriptname);
    } else {
      jsScript.setInnerHTML(scriptname);
    }
    jsScript.setType(JsResources.SCRIPT_TYPE);

    Browser.getDocument().getHead().appendChild(jsScript);

    jsScript.setOnload(event -> {
      JsResources.eventLisenerQueue.get(scriptname).forEach(action -> action.handleEvent(event));
      JsResources.eventLisenerQueue.get(scriptname).clear();
      JsResources.rememberEvent.put(scriptname, event);
    });
  }
756407
@Override
	public void addCallback(Callback callback) {
		if (manager != null) {
			callback.initialize(manager);
		}
		callbacks.add(callback);
	}
875044
function onImagesLoaded(images, callback){
  var self = this,
      unloaded = images.length;

  if (unloaded === 0) {
    callback();
  }

  images.each(function(){
    // Check if image is loaded
    if (this.complete && this.naturalWidth !== undefined) {
      singleImageLoaded();
    }
    else {
      // If the above check failed, simulate loading on detached element.
      var image = new Image();
      // Still count image as loaded if it finalizes with an error.
      var events = "load.zf.images error.zf.images";
      $(image).one(events, function me(event){
        // Unbind the event listeners. We're using 'one' but only one of the two events will have fired.
        $(this).off(events, me);
        singleImageLoaded();
      });
      image.src = $(this).attr('src');
    }
  });

  function singleImageLoaded() {
    unloaded--;
    if (unloaded === 0) {
      callback();
    }
  }
}
372219
function whenReady(callback) {

		function onLoaded() {
			document.removeEventListener( "DOMContentLoaded", onLoaded, false );
			callback();
		}

		if ( document.readyState === 'complete' ) {
			callback();
		} else {
			document.addEventListener( "DOMContentLoaded", onLoaded, false );
		}
	}