/*! Observer - v0.1.0 - 2012-06-27 * https://github.com/jkroso/Observer * Copyright (c) 2012 Jakeb Rosoman; Licensed MIT */ define(function(){function a(b){typeof b=="object"&&(b.publish=a.prototype.publish,b.run=a.prototype.run,b.on=a.prototype.on,b.off=a.prototype.off),(b||this).__base__=new d}function b(a,c,d){var e=a._listeners,f;if(f=a[c.shift()])if(b(f,c,d)===!1)return!1;f=e.length-1;if(f!==-1)do if((a=e[f]).callback.call(a.context,d)===!1)return!1;while(f--);return!0}function c(a,b,c){this.context=a,this.callback=b,this.priority=c}function d(){this._listeners=[]}function e(a){var b=a.indexOf(".");return b===-1?a:a.substr(0,b)}function f(a){var b=a.indexOf(".");return b===-1?"":a.substr(b+1)}return"use strict",a.prototype={publish:function(a,c){return b(this.__base__,a.split("."),c)},run:function(a,b){var c;if(a=this.__base__[a]){a=a._listeners,c=a.length-1;if(c!==-1)do if(a[c].trigger(b)===!1)return!1;while(c--);return!0}},on:function(a,b,g,h){switch(arguments.length){case 3:typeof g=="number"?(h=g,g=b,b=window):h=0;break;case 2:g=b,b=window,h=0;break;case 1:g=a,a="",b=window,h=0;break;case 0:throw"Insufficient arguments"}if(typeof g!="function")throw"Incorrect argument format";if(typeof h!="number")throw"Incorrect argument format";var i=new c(b,g,h);return a.split(" ").forEach(function j(a){var b=e(a);b?(this.hasOwnProperty(b)||(this[b]=new d),j.call(this[b],f(a))):this.insertListener(i)},this.__base__),i},off:function(a,b){if(typeof a!="string")throw"Need tp provide a topic";a.split(" ").forEach(function c(a){var d=e(a);if(!d)this.removeListener(b);else{if(!this.hasOwnProperty(d))return;c.call(this[d],f(a))}},this.__base__)},constructor:a},c.prototype={trigger:function(a){return this.callback.call(this.context,a)}},d.prototype={insertListener:function(a){var b=this._listeners.slice(),c=b.length,d=a.priority,e=0,f=!1;for(;e=d){b.splice(e,0,a),f=!0;break}f||b.push(a),this._listeners=b},removeListener:function(a){var b;switch(typeof a){case"function":b=function(b){return b.callback!==a};break;case"string":b=function(b){return b.callback.name!==a};break;case"object":b=function(b){return b!==a};break;default:b=function(){return!1}}this._listeners=this._listeners.filter(b)},invokeListeners:function(a){var b=this._listeners,c=b.length-1;if(c!==-1)do if(b[c].trigger(a)===!1)return!1;while(c--);return!0}},a.prototype.unsubscribe=a.prototype.off,a.prototype.subscribe=a.prototype.on,a.Subscription=c,a})