-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.min.js
9 lines (8 loc) · 1.5 KB
/
Package.min.js
1
2
3
4
5
6
7
8
9
/*
Package.js v1.0.0 - Add package support to the browser
Copyright 2011, Oliver Caldwell (olivercaldwell.co.uk)
Licenced under GPL v3 <http://www.gnu.org/licences/gpl.html>
*/
(function(h){function e(a,b){a&&(this.setPath(a),b&&this.load(b))}function d(a){this.settings={};typeof a==="string"?this.set("path",a):this.set(a)}e.prototype.setPath=function(a){this.path=a;return this};e.prototype.load=function(){var a=document.createElement("script");a.src=this.path;a.type="text/javascript";document.getElementsByTagName("head")[0].appendChild(a);return this};d.prototype.set=function(a,b){var c=null;if(typeof a==="string")this.settings[a]=b;else for(c in a)a.hasOwnProperty(c)&&
this.set(c,a[c]);return this};d.prototype.get=function(a){return this.settings[a]};d.prototype.register=function(){var a=this.get("path"),b=d.registrationCallbacks[a];a&&(d.registeredPackages[a]=!0,b&&b());return this};d.prototype.loadDependencies=function(a){function b(){g+=1;g===c.length&&a&&a()}var c=this.get("dependencies"),f=null,e=null,g=0;if(c)for(f=0;f<c.length;f+=1)e=new d(c[f]),c[f].root||e.set("root",this.get("root")),e.load(b);else!c&&a&&a();return this};d.prototype.load=function(a){var b=
null,c=this.get("path"),b=null,f=new e;d.registeredPackages[c]?d.registeredPackages[c]&&a&&a():(b=this.settings.root||d.defaultRoot||"",b[b.length-1]!=="/"&&(b+="/"),b=b+c.split(".").join("/")+".js",a&&(d.registrationCallbacks[c]=a),f.setPath(b).load());return this};d.registeredPackages={};d.registrationCallbacks={};h.Package=d})(window);