| 1 | (function(entries) { |
|---|
| 2 | function defined(prop) { |
|---|
| 3 | try{ |
|---|
| 4 | return eval('typeof ' + prop) != "undefined"; |
|---|
| 5 | } catch(e) { |
|---|
| 6 | } |
|---|
| 7 | return false; |
|---|
| 8 | } |
|---|
| 9 | |
|---|
| 10 | function loadScript(src) { |
|---|
| 11 | var script = document.createElement('script'); |
|---|
| 12 | script.type = 'text/javascript'; |
|---|
| 13 | script.src = src; |
|---|
| 14 | (document.body || document.documentElement).appendChild(script); |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | var onComplete; |
|---|
| 18 | (function doNextEntry() { |
|---|
| 19 | var entry = entries.shift(); |
|---|
| 20 | if (!entry) { |
|---|
| 21 | return onComplete && onComplete(); |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | if (typeof entry == 'string' || entry instanceof String) { |
|---|
| 25 | entry = {'window':entry}; |
|---|
| 26 | } |
|---|
| 27 | for (var prop in entry) { |
|---|
| 28 | if (prop == 'window' || !defined(prop)) { |
|---|
| 29 | loadScript(entry[prop]); |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | var timer = setInterval(function() { |
|---|
| 33 | for (var prop in entry) { |
|---|
| 34 | if (!defined(prop)) { |
|---|
| 35 | return; |
|---|
| 36 | } |
|---|
| 37 | } |
|---|
| 38 | clearInterval(timer); |
|---|
| 39 | doNextEntry(); |
|---|
| 40 | }, 99); |
|---|
| 41 | })(); |
|---|
| 42 | |
|---|
| 43 | return function(callback) { |
|---|
| 44 | return function() { |
|---|
| 45 | var args = arguments; |
|---|
| 46 | onComplete = function() { |
|---|
| 47 | callback.apply(callback, args); |
|---|
| 48 | }; |
|---|
| 49 | } |
|---|
| 50 | }; |
|---|
| 51 | }) |
|---|
| 52 | |
|---|
| 53 | // SYNOPSIS |
|---|
| 54 | // |
|---|
| 55 | // (function(entries) { |
|---|
| 56 | // ... script above. You can use loader-min.js.inc instead of. |
|---|
| 57 | // }) |
|---|
| 58 | // ([ |
|---|
| 59 | // {'jQuery':'http://example.com/js/jquery.js'}, // 1st |
|---|
| 60 | // |
|---|
| 61 | // {'jQuery.iUtil':'http://example.com/js/iutil.js', // |
|---|
| 62 | // 'jQuery.iDrag':'http://example.com/js/idrag.js', // 2nd |
|---|
| 63 | // 'jQuery.iDrop':'http://example.com/js/idrop.js'}, // |
|---|
| 64 | // // iutil.js, idrag.js and idrop.js are loaded at the same time. |
|---|
| 65 | // |
|---|
| 66 | // {'jQuery.iSort':'http://example.com/js/isortables.js'}, // 3rd |
|---|
| 67 | // |
|---|
| 68 | // 'http://example.com/myutil.js' // 4th |
|---|
| 69 | // // It is loaded without property check. |
|---|
| 70 | // ]) |
|---|
| 71 | // (function() { |
|---|
| 72 | // // Now, these has been correct and ensured. |
|---|
| 73 | // console.info([jQuery, jQuery.iUtil, jQuery.iDrag, jQuery.iDrop, jQuery.iSort]); |
|---|
| 74 | // })(); |
|---|