/*! Sauron - v1.1.0 - 2013-01-07 * https://github.com/Ensighten/Sauron * Copyright (c) 2013 Ensighten; Licensed MIT */ window.Sauron=function(){function r(){this.stack=[]}function i(){return this.stack.pop()}function o(e){return function(){var t=this.clone();t=t.of(e);if(arguments.length>0){var n=[].slice.call(arguments),r=t.method||"voice";return n.unshift(null),t[r].apply(t,n)}return t}}var e={},t={},n=window.console||{log:function(){}},s=r.prototype={channel:function(e){var t=this.stack,n=this._prefix,r=this._controller,i=this._model,s=t[t.length-1]||"";return e||(n!==undefined&&(s=n+"/"+s),r!==undefined?s="controller/"+r+"/"+s:i!==undefined&&(s="model/"+i+"/"+s)),s},pushStack:function(e){return this.stack.push(e),this},popStack:i,end:function(){var e=this.clone();return i.call(e),e},of:function(e){var t=this.clone(),n=t.channel(!0),r=n+"/"+e;return t.pushStack(r),t.log("CHANNEL EDITED: ",t.channel()),t},on:function(t,n){var r=this.clone();r.method!=="on"&&(r.method="on",r.log("METHOD CHANGED TO: on"));if(arguments.length>0){arguments.length===1&&typeof t=="function"&&(n=t,t=null);if(t||t===0)r=r.of(t);if(n){var i=r.channel(),s=e[i];r.log("FUNCTION ADDED TO: ",i),s===undefined&&(s=[],e[i]=s),r.fn=n,n.SAURON_CONTEXT=r,s.push(n)}}return r},off:function(n,r){var i=this.clone();i.method!=="off"&&(i.method="off",i.log("METHOD CHANGED TO: off")),r=r||i.fn;if(arguments.length>0||r){arguments.length===1&&typeof n=="function"&&(r=n,n=null);if(n||n===0)i=i.of(n);var s=i.channel();if(r){var o=e[s]||[],u=o.length;i.log("REMOVING FUNCTION FROM: ",s);while(u--)o[u]===r&&o.splice(u,1);return t}e[s]=[]}return i},voice:function(n){var r=this.clone();if(n||n===0)r=r.of(n);var i=[].slice.call(arguments,1),s=r.channel(),o=(e[s]||[]).slice(),u,a=0,f=o.length;r.log("EXECUTING FUNCTIONS IN: ",s);for(;a0){arguments.length===1&&typeof e=="function"&&(t=e,e=null);if(typeof t!="function")throw new Error("Sauron.once expected a function, received: "+t.toString);var r=function(){this.off();var e=[].slice.call(arguments);return t.apply(this,e)};return n.on(e,r)}return n},make:function(){var e=this.clone();e.log("PREFIX UPDATED TO: make"),e._prefix="make";if(arguments.length>0){var t=[].slice.call(arguments),n=e.method||"voice";return e[n].apply(e,t)}return e},destroy:function(){var e=this.clone();e.log("PREFIX UPDATED TO: destroy"),e._prefix="destroy";if(arguments.length>0){var t=[].slice.call(arguments),n=e.method||"voice";return e[n].apply(e,t)}return e},controller:function(e){var t=this.clone();t._controller=e,t.log("CHANNEL UPDATED TO:",t.channel());if(require){var r=require.getContext().config.paths._controllerDir||"",i=r+e;require.has(i)||n.log(e+" has not been loaded by requirejs")}if(arguments.length>1){var s=[].slice.call(arguments,1),o=t.method||"voice";return s.unshift(null),t[o].apply(t,s)}return t},createController:function(e){var t=this.clone();t=t.make(),t=t.controller(e);var n=[].slice.call(arguments,1),r=t.method||"voice";return n.unshift(null),t[r].apply(t,n)},start:o("start"),stop:o("stop"),model:function(e){var t=this.clone();t._model=e,t.log("CHANNEL UPDATED TO:",t.channel());if(require){var r=require.getContext().config.paths._modelDir||"",i=r+e;require.has(i)||n.log(e+" has not been loaded by requirejs")}if(arguments.length>1){var s=[].slice.call(arguments,1),o=t.method||"voice";return s.unshift(null),t[o].apply(t,s)}return t},createModel:function(e){var t=this.clone();t=t.make(),t=t.model(e);var n=[].slice.call(arguments,1),r=t.method||"voice";return n.unshift(null),t[r].apply(t,n)},create:o("create"),retrieve:o("retrieve"),update:o("update"),"delete":o("delete"),createEvent:o("createEvent"),retrieveEvent:o("retrieveEvent"),updateEvent:o("updateEvent"),deleteEvent:o("deleteEvent"),noError:function(e){return function(t){if(t)return n.error(t);var r=[].slice.call(arguments,1);e.apply(this,r)}},debug:function(e){var t=this.clone();return t._debug=e,t},log:function(){return(this._debug===!0||t._debug===!0)&&n.log.apply(n,arguments),this}};for(var u in s)s.hasOwnProperty(u)&&function(e){t[u]=function(){var t=[].slice.call(arguments);return e.apply(new r,t)}}(s[u]);return t}();