X-Git-Url: http://git.roojs.org/?p=app.Builder.js;a=blobdiff_plain;f=Observable.js;h=46cb8a27d7b83cc7eef6b7fea230f9b983b90f94;hp=45d9f4929cb4b859945681359cc1ff7b0c44553a;hb=24c4a7c1f13871c989c819ec7355ee79cefeea0e;hpb=b7e2670c4d8bbb458b77d727cba76fe4a54acfb1 diff --git a/Observable.js b/Observable.js index 45d9f4929..46cb8a27d 100644 --- a/Observable.js +++ b/Observable.js @@ -89,9 +89,9 @@ Observable = XObject.define( * @param {Object} options (optional) An object containing handler configuration * properties. This may contain any of the following properties:
@@ -160,7 +160,7 @@ Observable = XObject.define( eventName = eventName.toLowerCase(); var ce = this.events[eventName] || true; if(typeof ce == "boolean"){ - ce = new Roo.Event(this, eventName); + ce = new Event(this, eventName); this.events[eventName] = ce; } ce.addListener(fn, scope, o); @@ -189,11 +189,26 @@ Observable = XObject.define( } } }, - + _combine : function(){ + var as = arguments, l = as.length, r = []; + for(var i = 0; i < l; i++){ + var a = as[i]; + if(a instanceof Array){ + r = r.concat(a); + }else if(a.length !== undefined && !a.substr){ + r = r.concat(Array.prototype.slice.call(a, 0)); + }else{ + r.push(a); + } + } + return r; + }, + relayEvents : function(o, events){ var createHandler = function(ename){ return function(){ - return this.fireEvent.apply(this, Roo.combine(ename, Array.prototype.slice.call(arguments, 0))); + return this.fireEvent.apply(this, Event.prototype.combine(ename, + Array.prototype.slice.call(arguments, 0))); }; }; for(var i = 0, len = events.length; i < len; i++){ @@ -211,7 +226,7 @@ Observable = XObject.define( if(!this.events){ this.events = {}; } - Roo.applyIf(this.events, o); + XObject.extendIf(this.events, o); }, /** @@ -223,7 +238,7 @@ Observable = XObject.define( var e = this.events[eventName]; return typeof e == "object" && e.listeners.length > 0; } -}; +}); /** * Starts capture on the specified Observable. All events will be passed @@ -248,53 +263,66 @@ Observable.releaseCapture = function(o){ o.fireEvent = Observable.prototype.fireEvent; }; -(function(){ + - var createBuffered = function(h, o, scope){ - var task = new Roo.DelayedTask(); - return function(){ - task.delay(o.buffer, h, scope, Array.prototype.slice.call(arguments, 0)); - }; +var createSingle = function(h, e, fn, scope){ + return function(){ + e.removeListener(fn, scope); + return h.apply(scope, arguments); }; +}; - var createSingle = function(h, e, fn, scope){ - return function(){ - e.removeListener(fn, scope); - return h.apply(scope, arguments); - }; - }; +// NOT SUPPORTED YET> +//var createBuffered = function(h, o, scope){ +// var task = new DelayedTask(); +// return function(){ +// task.delay(o.buffer, h, scope, Array.prototype.slice.call(arguments, 0)); +// }; +//}; + + +//var createDelayed = function(h, o, scope){ +// return function(){ +// var args = Array.prototype.slice.call(arguments, 0); +// setTimeout(function(){ +// h.apply(scope, args); +// }, o.delay || 10); +// }; +//}; - var createDelayed = function(h, o, scope){ - return function(){ - var args = Array.prototype.slice.call(arguments, 0); - setTimeout(function(){ - h.apply(scope, args); - }, o.delay || 10); - }; - }; - Roo.Event = function(obj, name){ +/** + * Event Object - manages a specific event. + * + * + * + */ + + + +Event = XObject.define( + function(obj, name){ this.name = name; this.obj = obj; this.listeners = []; - }; - - Roo.Event.prototype = { + }, + Object, + { addListener : function(fn, scope, options){ var o = options || {}; scope = scope || this.obj; if(!this.isListening(fn, scope)){ var l = {fn: fn, scope: scope, options: o}; var h = fn; - if(o.delay){ - h = createDelayed(h, o, scope); - } + // if(o.delay){ + // h = createDelayed(h, o, scope); + // } if(o.single){ h = createSingle(h, this, fn, scope); } - if(o.buffer){ - h = createBuffered(h, o, scope); - } + //if(o.buffer){ + // h = createBuffered(h, o, scope); + //} l.fireFn = h; if(!this.firing){ // if we are currently firing this event, don't disturb the listener loop this.listeners.push(l); @@ -355,5 +383,5 @@ Observable.releaseCapture = function(o){ } return true; } - }; -})(); \ No newline at end of file + } +);