// syringe.js v0.6.5. Copyright (c) 2015 M Holt, holt.org. Distributed under the MIT License (function(){"use strict";var t=this,e={},n={}.hasOwnProperty,r=[].slice,i={getObj:function(t,e,n){return t.split(n||".").filter(function(t){return t.length}).reduce(function(t,e,n,r){return t?t[r[n]]:void 0},e||this)},setObj:function(t,e,n){return t.split(n||".").reduce(function(t,e){return t[e]?t[e]:t[e]={}},e||this)},bindArgs:function(){var t=r.call(arguments),e=this;return function(){return e.apply(this,t.concat(r.call(arguments)))}},makeId:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})},getType:function(t,e){var n="Undefined",r=["Window","HTMLDocument","Global","Document"];return t?(n={}.toString.call(t).match(/\s([a-z|A-Z]+)/)[1],r=r.some(function(t){return t.toLowerCase()===n.toLowerCase()}),n=r?"Object":n):null===t?n="Null":t===!1?n="Boolean":"string"==typeof t?n="String":0===t?n="Number":isNaN(t)&&"number"==typeof t&&(n="NaN"),"string"==typeof e?e.toLowerCase()===n.toLowerCase():n},matchArgs:function(t,e){return e=e||[],t=[].slice.call(t),e.length?e.length===t.length?t.reduce(function(t,n,r){return!t&&i.getType(e[r],"string")?!1:i.getType(n,e[r])},!0):!1:t.map(function(t){return i.getType(t)})},getReg:function(t,n){var r=e[n].registry;return t.map(function(t){switch(t){case"":return void 0;case"*":return r;case"this":return this;default:return i.getObj(t,r,e[n].sep)}},this)},getData:function(t,e){var n;i.getType(XMLHttpRequest,"undefined")?["MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp.2.0","Microsoft.XmlHttp"].forEach(function(t){try{return void(n=new window.ActiveXObject(t))}catch(e){throw new Error(e)}}):n=new XMLHttpRequest,n.onreadystatechange=function(){n.readyState<4||(200!==n.status?e(null):4===n.readyState&&e(n))},n.open("GET",t,!0),n.setRequestHeader("Accept","application/json, text/javascript, */*; q=0.01"),n.setRequestHeader("Content-Type","application/json; charset=utf-8"),n.send("")},isEmpty:function(t){return Object.keys(t).length?!1:!0},fetch:function(t,e,n){e=e||{},e.success=e.success||!1,e.xss=e.xss||!1;var r=this,s=0,a="",o=function(t){var e=new RegExp("//"+location.host+"($|/)");return"http"===t.substring(0,4)?e.test(t):!0},c=function(a){if(a&&a.responseText){var o=JSON.parse(a.responseText);if(o)if(r.get(t[s].bind)){if(i.getType(o,"array"))r.add(t[s].bind+".json",o);else if(i.getType(o,"object"))for(var c in o)o.hasOwnProperty(c)&&r.add(t[s].bind+"."+c,o[c])}else r.add(t[s].bind,o)}++s===t.length&&i.getType(e.success,"function")&&e.success.apply(r,[n||r,a])};t.forEach(function(t){(o(a=t.path)||e.xss===!0)&&i.getData(t.path,c)})},run:function(n,s,a){var o,c,u,p,f=r.call(arguments);return f.splice(2,1),c=e[a.id].cabinet.filter(function(t){return t.fn===s})[0],s=c?c.fn:s,o=i.getReg.apply(a,[n,a.id]).concat(f.slice(2,f.length)),n.forEach(function(e,n){i.getType(e,"string")&&0===e.indexOf("global:")&&(o[n]=i.getObj(e.slice(7,e.length),t,"."))}),i.isEmpty(s.prototype)?s.apply(this,o):(u=Object.create(s.prototype),p=s.apply(u,o),i.getType(p,"object")?p:u)},fire:function(t,n,r){e[n].events[t].forEach(function(s){if(i.getType(s.fn,"function")){if(r.unshift(t),s.path&&"*"===s.path.split(e[n].separator).pop()){var a=s.path.split(e[n].separator),o=r[1].split(e[n].separator);a.pop(),o.pop(),a=a.join(e[n].separator),o=o.join(e[n].separator),o===a&&s.fn.apply(this,r)}else s.path&&r[1]!==s.path&&r[1].split(e[n].separator).pop()!==s.path||s.fn.apply(this,r);r.shift()}},this)}},s=function(t){e[this.id=i.makeId()]={cabinet:[],registry:t&&i.getType(t,"object")?t:{},separator:".",events:{add:[],set:[],get:[],remove:[],listops:[],all:[]}}},a=s.prototype={separator:function(t){return i.getType(t,"string")&&1===t.replace(/[?a-zA-Z\d]|\s/g,"").length?(e[this.id].separator=t,this):!1},listops:function(t,n){var r=e[this.id].registry,s=e[this.id].separator,a=t.split(s),o=i.getObj(t,r,s),c=null;if(!i.getType(o,"array")||"function"!=typeof n)throw new Error('Key "'+t+'" is not an array!');return c=n(o),a=[t,o],c&&a.push(c),i.fire("listops",this.id,a),this},add:function(t,n,r){var s=e[this.id].registry,a=e[this.id].separator;switch(i.getType(t)){case"Array":return t.forEach(function(t){this.add.apply(this,[t])},this),this;case"Object":return Object.keys(t).forEach(function(e){this.add.apply(this,[e,t[e]])},this),this}if(!i.getType(t,"string"))throw new Error("Name must be a string!");if(t=t.trim(),0===t.indexOf("global:"))throw new Error("You can't add a key with this prefix!");if(i.getObj(t,s,a))throw new Error('Key "'+t+'" already exists in the map; use .remove() to unregister it first!');i.getType(n,"function")&&r&&(n=this.on(r,n));var o=t.split(a),c=o.length>1?o.pop():!1;return c?i.setObj(o.join(a),s,a)[c]=n:s[o.toString()]=n,i.fire("add",this.id,[t,n]),this},remove:function(t){if(i.getType(t,"array"))return t.forEach(function(t){i.getType(t,"string")&&this.remove(t)},this),this;if(i.getType(t,"string")){t=t.trim();var n=e[this.id].registry,r=e[this.id].separator,s=t.trim().split(r),a=s.pop(),o={},c={};s=s.join(r),c=s?i.getObj(s,n,r):n,i.getType(c,"object")&&(t=a||s,Object.keys(c).forEach(function(e){e!==t&&(o[e]=c[e])}),s?this.set(s,o):e[this.id].registry=o),i.fire("remove",this.id,[s+r+t])}return this},on:function(){var n,s,a,o,c=e[this.id].cabinet,u=r.call(arguments),p=t,f={args:u},h=i.getType,g=i.matchArgs,l=i.bindArgs.bind(i.run),d=function(n,r,s){var a=e[this.id].separator,o=n.split(a),c=o.length>1?o.pop():!1;s=h(s,"object")?s:t,c?i.setObj(o.join(a),s,a)[c]=r:s[o.join(a)]=r}.bind(this);if(n=g(u,["array","function"]),s=g(u,["array","function","object"]),a=g(u,["string","array","function"]),o=g(u,["string","array","function","object"]),n||s||a||o){var y=a||o?1:0;return f.fn=u[y+1],f.ctx=s?u[y+2]:p,n||a?f.bind=l(u[y+0],u[y+1],this):(s||o)&&(f.bind=i.run.bind(u[y+2],u[y+0],u[y+1],this)),c.push(f),y?(d(u[0],f.bind,p),this):f.bind}return this},exec:function(t,n,r){r=r||this;var s=this.get(t),a=e[this.id].cabinet.filter(function(t){return t.bind===s})[0];return n=i.getType(n,"array")?n:[n],i.getType(t,"string")&&i.getType(s,"function")?a?(s=a?a.fn:s,i.run.apply(r,[a.args[0],s,this].concat(n))):s.apply(r,n):!1},get:function(t){var n=e[this.id].registry;if(i.fire("get",this.id,[t]),i.getType(t,"string")){var r=i.getObj(t,n,e[this.id].separator);return i.getType(r,"undefined")?!1:r}return n},set:function(t,r,s){var a,o=e[this.id].registry,c=e[this.id].separator,u=t.split(c),p=u.length>1?u.pop():!1;if(void 0===i.getObj(t,o,c))if(a=i.getObj(u.join(c),o,c),p){if(a&&!n.call(a,p)||!a)throw new Error('Key "'+t+'" does not exist in the map!')}else if(!n.call(o,u.toString()))throw new Error('Key "'+t+'" does not exist in the map!');return i.getType(r,"function")&&s&&(r=this.on(s,r)),p?i.setObj(u.join(c),o,c)[p]=r:o[u.toString()]=r,i.fire("set",this.id,[t,r]),this},wrap:function(t,n,i){i=i||this;var s=e[this.id].cabinet.filter(function(e){return e.bind===t})[0];return s?function(){var t=r.call(arguments);return n.apply(i,[function(){return t=arguments.length?arguments:t,s.bind.apply(i,t)}].concat(t))}:!1},copy:function(t,n,s){s=s||this;var a=e[this.id].cabinet,o=a.filter(function(t){return t.bind===n})[0];if(o){var c={fn:n,ctx:r.call(arguments)[0],bind:i.run.bind(o.ctx,t,o.fn,this)};return a.push(c),c.bind}return!1},listen:function(t,r){var s=t.split(":");if(t=s.shift(),i.getType(t,"string")&&i.getType(r,"function")){var a=function(t,e){i.getType(e,"array")&&e.push({path:t.length?t[0]:!1,fn:r})},o=e[this.id].events;if("all"!==t)a(s,o[t]);else for(var c in e[this.id].events)n.call(o,c)&&a(s,o[c])}return this},create:function(t){return new s(t)}};a.mixin=function(t){return i.getType(t,"object")?(Object.keys(t).forEach(function(e){i.getType(t[e],"function")&&(a[e]=t[e])}),this):!1},a.bind=a.on,a.register=a.add,a.unregister=a.remove,a.VERSION="0.6.5",this.window?(a.fetch=i.fetch,t.Syringe=new s):"undefined"!=typeof module&&module.exports&&(exports=module.exports=new s)}).call(this); //# sourceMappingURL=syringe.min.map