-
Notifications
You must be signed in to change notification settings - Fork 0
/
arch.min.js
2 lines (2 loc) · 3.06 KB
/
arch.min.js
1
2
/*arch.js - @jontyy - MIT licensed - https://github.com/Jontyy/arch.js*/
(function(a){"use strict",a.arch={}})(window),function(a){"use strict",a.core={}}(window.arch),function(a){"use strict";var b={},c={},d=function(a){throw new Error(a)},e=function(a,c,d){b[a]=b[a]||[],b[a].push({callback:c,context:d})},f=function(a,d){var e;if(typeof c[a]=="function"&&c[a](d)===!1)return!1;if(b[a])for(e in b[a])b[a].hasOwnProperty(e)&&b[a][e].callback.apply(b[a][e].context,d)},g=function(a,c){var d;if(!b[a]instanceof Array)return!1;if(typeof c!="function")return delete b[a],!1;for(d in b[a])if(b[a].hasOwnProperty(d)&&b[a][d].callback===c)return delete b[a][d],!0};a.mediator={publish:function(a){var b,c=Array.prototype.slice.call(arguments,1);typeof a!="string"&&d("Event name must be a string."),a=a.split(" ");for(b in a)a.hasOwnProperty(b)&&a[b].length>0&&f(a[b],c)},subscribe:function(a,b,c){var f;typeof a!="string"&&d("Event name must be a string."),typeof b!="function"&&d("Callback must be a function."),a=a.split(" ");for(f in a)a.hasOwnProperty(f)&&a[f].length>0&&e(a[f],b,c)},unsubscribe:function(a,b){var c;typeof a!="string"&&d("Event must be a string."),typeof b!="undefined"&&typeof b!="function"&&d("Callback must be a function."),a=a.split(" ");for(c in a)a.hasOwnProperty(c)&&g(a[c],b)},validate:function(a,b){var e;typeof a!="string"&&d("Event name must be a string."),typeof b!="function"&&d("Callback must be a function."),a=a.split(" ");for(e in a)a.hasOwnProperty(e)&&a[e].length>0&&(c[a[e]]=b)}}}(window.arch),function(a){"use strict",a.Sandbox=function(a,b){this.elem=a,this.core=b,typeof this.init=="function"&&this.init(a)},a.Sandbox.prototype=a.mediator}(window.arch),function(a){"use strict";var b={},c={},d={},e=function(a){throw new Error(a)},f=function(b,c){typeof b!="object"&&e("Events must be an object.");for(var d in b)b.hasOwnProperty(d)&&((typeof d!="string"||typeof b[d]!="string")&&e("Events must be an object with string keys and values."),typeof c[b[d]]!="function"&&e("'"+b[d]+"' is not a method of this module."),a.mediator.subscribe(d,c[b[d]],c))},g=function(b){var g=d[b],h=document.getElementById(b);g=g.call(h,new a.Sandbox(h,a.core)),(typeof g!="object"||typeof g.init!="function"||typeof g.destroy!="function")&&e("Module constructor should return an object with init and destroy methods."),typeof g.events!="undefined"&&f(g.events,g),g.init(),c[b]=g};b.register=function(a,b){typeof a!="string"&&e("Module name must be a string."),typeof b!="function"&&e("Module constructor must be a function."),d[a]=b},b.start=function(a){var b,c,f;for(b in arguments)arguments.hasOwnProperty(b)&&(typeof arguments[b]!="string"&&e("Module names must be strings."),typeof d[arguments[b]]!="function"&&e("Module not found."),g(arguments[b]))},b.stop=function(a){var b=0,d=Array.prototype.slice.call(arguments),f=d.length;for(b;b<f;b+=1)typeof d[b]!="string"&&e("Module names must be strings."),typeof c[d[b]]=="object"&&c[d[b]].destroy()},b.startAll=function(){var a;for(a in d)d.hasOwnProperty(a)&&g(a)},b.stopAll=function(){var a;for(a in c)c.hasOwnProperty(a)&&c[a].destroy()},a.module=b}(window.arch)