X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/25ef3491bd9ae007ff1fc2b0d7943e6eaaccf775..10a866c12701c0a0afd0ac85dcdcf32a421514ac:/docs/source/Observable-more.html diff --git a/docs/source/Observable-more.html b/docs/source/Observable-more.html index 2bd2141d..faa7e7fd 100644 --- a/docs/source/Observable-more.html +++ b/docs/source/Observable-more.html @@ -1,41 +1,36 @@ - - - The source code - - - - -
/*!
- * Ext JS Library 3.0.3
- * Copyright(c) 2006-2009 Ext JS, LLC
- * licensing@extjs.com
- * http://www.extjs.com/license
- */
-/**
+
+
+      
+  The source code
+    
+    
+
+
+    
/**
  * @class Ext.util.Observable
  */
-Ext.apply(Ext.util.Observable.prototype, function(){    
+Ext.apply(Ext.util.Observable.prototype, function(){
     // this is considered experimental (along with beforeMethod, afterMethod, removeMethodListener?)
     // allows for easier interceptor and sequences, including cancelling and overwriting the return value of the call
     // private
     function getMethodEvent(method){
         var e = (this.methodEvents = this.methodEvents ||
         {})[method], returnValue, v, cancel, obj = this;
-        
+
         if (!e) {
             this.methodEvents[method] = e = {};
             e.originalFn = this[method];
             e.methodName = method;
             e.before = [];
             e.after = [];
-            
+
             var makeCall = function(fn, scope, args){
                 if (!Ext.isEmpty(v = fn.apply(scope || obj, args))) {
                     if (Ext.isObject(v)) {
                         returnValue = !Ext.isEmpty(v.returnValue) ? v.returnValue : v;
                         cancel = !!v.cancel;
                     }
-                    else 
+                    else
                         if (v === false) {
                             cancel = true;
                         }
@@ -44,19 +39,19 @@ Ext.apply(Ext.util.Observable.prototype, function(){
                         }
                 }
             };
-            
+
             this[method] = function(){
                 var args = Ext.toArray(arguments);
                 returnValue = v = undefined;
                 cancel = false;
-                
+
                 Ext.each(e.before, function(b){
                     makeCall(b.fn, b.scope, args);
                     if (cancel) {
                         return returnValue;
                     }
                 });
-                
+
                 if (!Ext.isEmpty(v = e.originalFn.apply(obj, args))) {
                     returnValue = v;
                 }
@@ -71,26 +66,26 @@ Ext.apply(Ext.util.Observable.prototype, function(){
         }
         return e;
     }
-    
+
     return {
         // these are considered experimental
         // allows for easier interceptor and sequences, including cancelling and overwriting the return value of the call
-        // adds an "interceptor" called before the original method
-        beforeMethod: function(method, fn, scope){
+        // adds an 'interceptor' called before the original method
+        beforeMethod : function(method, fn, scope){
             getMethodEvent.call(this, method).before.push({
                 fn: fn,
                 scope: scope
             });
         },
-        
-        // adds a "sequence" called after the original method
-        afterMethod: function(method, fn, scope){
+
+        // adds a 'sequence' called after the original method
+        afterMethod : function(method, fn, scope){
             getMethodEvent.call(this, method).after.push({
                 fn: fn,
                 scope: scope
             });
         },
-        
+
         removeMethodListener: function(method, fn, scope){
             var e = getMethodEvent.call(this, method), found = false;
             Ext.each(e.before, function(b, i, arr){
@@ -109,13 +104,13 @@ Ext.apply(Ext.util.Observable.prototype, function(){
                 });
             }
         },
-        
+
         
/** * Relays selected events from the specified Observable as if the events were fired by this. * @param {Object} o The Observable whose events this object is to relay. * @param {Array} events Array of event names to relay. */ - relayEvents: function(o, events){ + relayEvents : function(o, events){ var me = this; function createHandler(ename){ return function(){ @@ -127,7 +122,7 @@ Ext.apply(Ext.util.Observable.prototype, function(){ o.on(ename, createHandler(ename), me); }); }, - +
/** *

Enables events fired by this Observable to bubble up an owner hierarchy by calling * this.getBubbleTarget() if present. There is no implementation in the Observable base class.

@@ -136,13 +131,13 @@ Ext.apply(Ext.util.Observable.prototype, function(){ * access the required target more quickly.

*

Example:


 Ext.override(Ext.form.Field, {
-//  Add functionality to Field's initComponent to enable the change event to bubble
-    initComponent: Ext.form.Field.prototype.initComponent.createSequence(function() {
+    //  Add functionality to Field's initComponent to enable the change event to bubble
+    initComponent : Ext.form.Field.prototype.initComponent.createSequence(function() {
         this.enableBubble('change');
     }),
 
-//  We know that we want Field's events to bubble directly to the FormPanel.
-    getBubbleTarget: function() {
+    //  We know that we want Field's events to bubble directly to the FormPanel.
+    getBubbleTarget : function() {
         if (!this.formPanel) {
             this.formPanel = this.findParentByType('form');
         }
@@ -157,15 +152,15 @@ var myForm = new Ext.formPanel({
     }],
     listeners: {
         change: function() {
-//          Title goes red if form has been modified.
-            myForm.header.setStyle("color", "red");
+            // Title goes red if form has been modified.
+            myForm.header.setStyle('color', 'red');
         }
     }
 });
 
- * @param {Object} events The event name to bubble, or an Array of event names. + * @param {String/Array} events The event name to bubble, or an Array of event names. */ - enableBubble: function(events){ + enableBubble : function(events){ var me = this; if(!Ext.isEmpty(events)){ events = Ext.isArray(events) ? events : Ext.toArray(arguments); @@ -189,9 +184,9 @@ var myForm = new Ext.formPanel({ * to the supplied function with the event name + standard signature of the event * before the event is fired. If the supplied function returns false, * the event will not fire. - * @param {Observable} o The Observable to capture - * @param {Function} fn The function to call - * @param {Object} scope (optional) The scope (this object) for the fn + * @param {Observable} o The Observable to capture events from. + * @param {Function} fn The function to call when an event is fired. + * @param {Object} scope (optional) The scope (this reference) in which the function is executed. Defaults to the Observable firing the event. * @static */ Ext.util.Observable.capture = function(o, fn, scope){ @@ -206,17 +201,23 @@ Ext.util.Observable.capture = function(o, fn, scope){ *

Usage:


 Ext.util.Observable.observeClass(Ext.data.Connection);
 Ext.data.Connection.on('beforerequest', function(con, options) {
-    console.log("Ajax request made to " + options.url);
+    console.log('Ajax request made to ' + options.url);
 });
* @param {Function} c The class constructor to make observable. + * @param {Object} listeners An object containing a series of listeners to add. See {@link #addListener}. * @static */ -Ext.util.Observable.observeClass = function(c){ - Ext.apply(c, new Ext.util.Observable()); - c.prototype.fireEvent = function(){ - return (c.fireEvent.apply(c, arguments) !== false) && - (Ext.util.Observable.prototype.fireEvent.apply(this, arguments) !== false); - }; -};
- +Ext.util.Observable.observeClass = function(c, listeners){ + if(c){ + if(!c.fireEvent){ + Ext.apply(c, new Ext.util.Observable()); + Ext.util.Observable.capture(c.prototype, c.fireEvent, c); + } + if(Ext.isObject(listeners)){ + c.on(listeners); + } + return c; + } +};
+ \ No newline at end of file