+++ /dev/null
-<html>\r
-<head>\r
- <title>The source code</title>\r
- <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
- <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
-</head>\r
-<body onload="prettyPrint();">\r
- <pre class="prettyprint lang-js">/**\r
- * @class Ext.util.Observable\r
- */\r
-Ext.apply(Ext.util.Observable.prototype, function(){ \r
- // this is considered experimental (along with beforeMethod, afterMethod, removeMethodListener?)\r
- // allows for easier interceptor and sequences, including cancelling and overwriting the return value of the call\r
- // private\r
- function getMethodEvent(method){\r
- var e = (this.methodEvents = this.methodEvents ||\r
- {})[method], returnValue, v, cancel, obj = this;\r
- \r
- if (!e) {\r
- this.methodEvents[method] = e = {};\r
- e.originalFn = this[method];\r
- e.methodName = method;\r
- e.before = [];\r
- e.after = [];\r
- \r
- var makeCall = function(fn, scope, args){\r
- if (!Ext.isEmpty(v = fn.apply(scope || obj, args))) {\r
- if (Ext.isObject(v)) {\r
- returnValue = !Ext.isEmpty(v.returnValue) ? v.returnValue : v;\r
- cancel = !!v.cancel;\r
- }\r
- else \r
- if (v === false) {\r
- cancel = true;\r
- }\r
- else {\r
- returnValue = v;\r
- }\r
- }\r
- };\r
- \r
- this[method] = function(){\r
- var args = Ext.toArray(arguments);\r
- returnValue = v = undefined;\r
- cancel = false;\r
- \r
- Ext.each(e.before, function(b){\r
- makeCall(b.fn, b.scope, args);\r
- if (cancel) {\r
- return returnValue;\r
- }\r
- });\r
- \r
- if (!Ext.isEmpty(v = e.originalFn.apply(obj, args))) {\r
- returnValue = v;\r
- }\r
- Ext.each(e.after, function(a){\r
- makeCall(a.fn, a.scope, args);\r
- if (cancel) {\r
- return returnValue;\r
- }\r
- });\r
- return returnValue;\r
- };\r
- }\r
- return e;\r
- }\r
- \r
- return {\r
- // these are considered experimental\r
- // allows for easier interceptor and sequences, including cancelling and overwriting the return value of the call\r
- // adds an "interceptor" called before the original method\r
- beforeMethod: function(method, fn, scope){\r
- getMethodEvent.call(this, method).before.push({\r
- fn: fn,\r
- scope: scope\r
- });\r
- },\r
- \r
- // adds a "sequence" called after the original method\r
- afterMethod: function(method, fn, scope){\r
- getMethodEvent.call(this, method).after.push({\r
- fn: fn,\r
- scope: scope\r
- });\r
- },\r
- \r
- removeMethodListener: function(method, fn, scope){\r
- var e = getMethodEvent.call(this, method), found = false;\r
- Ext.each(e.before, function(b, i, arr){\r
- if (b.fn == fn && b.scope == scope) {\r
- arr.splice(i, 1);\r
- found = true;\r
- return false;\r
- }\r
- });\r
- if (!found) {\r
- Ext.each(e.after, function(a, i, arr){\r
- if (a.fn == fn && a.scope == scope) {\r
- arr.splice(i, 1);\r
- return false;\r
- }\r
- });\r
- }\r
- },\r
- \r
- <div id="method-Ext.util.Observable-relayEvents"></div>/**\r
- * Relays selected events from the specified Observable as if the events were fired by <tt><b>this</b></tt>.\r
- * @param {Object} o The Observable whose events this object is to relay.\r
- * @param {Array} events Array of event names to relay.\r
- */\r
- relayEvents: function(o, events){\r
- var me = this;\r
- function createHandler(ename){\r
- return function(){\r
- return me.fireEvent.apply(me, [ename].concat(Ext.toArray(arguments)));\r
- };\r
- }\r
- Ext.each(events, function(ename){\r
- me.events[ename] = me.events[ename] || true;\r
- o.on(ename, createHandler(ename), me);\r
- });\r
- },\r
- \r
- <div id="method-Ext.util.Observable-enableBubble"></div>/**\r
- * Used to enable bubbling of events\r
- * @param {Object} events\r
- */\r
- enableBubble: function(events){\r
- var me = this;\r
- events = Ext.isArray(events) ? events : Ext.toArray(arguments);\r
- Ext.each(events, function(ename){\r
- ename = ename.toLowerCase();\r
- var ce = me.events[ename] || true;\r
- if (typeof ce == "boolean") {\r
- ce = new Ext.util.Event(me, ename);\r
- me.events[ename] = ce;\r
- }\r
- ce.bubble = true;\r
- });\r
- }\r
- };\r
-}());\r
-\r
-\r
-<div id="method-Ext.util.Observable-Observable.capture"></div>/**\r
- * Starts capture on the specified Observable. All events will be passed\r
- * to the supplied function with the event name + standard signature of the event\r
- * <b>before</b> the event is fired. If the supplied function returns false,\r
- * the event will not fire.\r
- * @param {Observable} o The Observable to capture\r
- * @param {Function} fn The function to call\r
- * @param {Object} scope (optional) The scope (this object) for the fn\r
- * @static\r
- */\r
-Ext.util.Observable.capture = function(o, fn, scope){\r
- o.fireEvent = o.fireEvent.createInterceptor(fn, scope);\r
-};\r
-\r
-\r
-<div id="method-Ext.util.Observable-Observable.observeClass"></div>/**\r
- * Sets observability on the passed class constructor.<p>\r
- * <p>This makes any event fired on any instance of the passed class also fire a single event through\r
- * the <i>class</i> allowing for central handling of events on many instances at once.</p>\r
- * <p>Usage:</p><pre><code>\r
-Ext.util.Observable.observeClass(Ext.data.Connection);\r
-Ext.data.Connection.on('beforerequest', function(con, options) {\r
- console.log("Ajax request made to " + options.url);\r
-});</code></pre>\r
- * @param {Function} c The class constructor to make observable.\r
- * @static\r
- */\r
-Ext.util.Observable.observeClass = function(c){\r
- Ext.apply(c, new Ext.util.Observable());\r
- c.prototype.fireEvent = function(){\r
- return (c.fireEvent.apply(c, arguments) !== false) &&\r
- (Ext.util.Observable.prototype.fireEvent.apply(this, arguments) !== false);\r
- };\r
-};</pre> \r
-</body>\r
-</html>
\ No newline at end of file