summaryrefslogtreecommitdiff
path: root/_includes/include.js
blob: 4f1cf2f7fbf3c23dcda230450a9682a7c74befb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
include = function() {

  // save references to save a few bytes
	var args = arguments;
	var doc = document;

	var toLoad = args.length; // load this many scripts
  var lastArgument = args[toLoad - 1];
	var hasCallback = lastArgument.call; // is the last arg a callback?
	if (hasCallback) {
		toLoad --;
	}

	function onScriptLoaded() {
    var readyState = this.readyState; // we test for "complete" or "loaded" if on IE
    if (!readyState || /ded|te/.test(readyState)) {
      toLoad --;
      if (!toLoad && hasCallback) {
        lastArgument();
      }
    }
	}

	var script;
	for (var i = 0; i < toLoad; i ++) {

		script = doc.createElement('script');
		script.src = arguments[i];
    script.async = true;
		script.onload = script.onerror = script.onreadystatechange = onScriptLoaded;
		(
			doc.head ||
			doc.getElementsByTagName('head')[0]
		).appendChild(script);

	}

};