Observable-min.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.util.Observable = function() {
  7. if (this.listeners) {
  8. this.on(this.listeners);
  9. delete this.listeners
  10. }
  11. };
  12. Ext.util.Observable.prototype = {
  13. fireEvent : function() {
  14. if (this.eventsSuspended !== true) {
  15. var A = this.events[arguments[0].toLowerCase()];
  16. if (typeof A == "object") {
  17. return A.fire
  18. .apply(A, Array.prototype.slice.call(arguments, 1))
  19. }
  20. }
  21. return true
  22. },
  23. filterOptRe : /^(?:scope|delay|buffer|single)$/,
  24. addListener : function(A, C, B, F) {
  25. if (typeof A == "object") {
  26. F = A;
  27. for (var E in F) {
  28. if (this.filterOptRe.test(E)) {
  29. continue
  30. }
  31. if (typeof F[E] == "function") {
  32. this.addListener(E, F[E], F.scope, F)
  33. } else {
  34. this.addListener(E, F[E].fn, F[E].scope, F[E])
  35. }
  36. }
  37. return
  38. }
  39. F = (!F || typeof F == "boolean") ? {} : F;
  40. A = A.toLowerCase();
  41. var D = this.events[A] || true;
  42. if (typeof D == "boolean") {
  43. D = new Ext.util.Event(this, A);
  44. this.events[A] = D
  45. }
  46. D.addListener(C, B, F)
  47. },
  48. removeListener : function(A, C, B) {
  49. var D = this.events[A.toLowerCase()];
  50. if (typeof D == "object") {
  51. D.removeListener(C, B)
  52. }
  53. },
  54. purgeListeners : function() {
  55. for (var A in this.events) {
  56. if (typeof this.events[A] == "object") {
  57. this.events[A].clearListeners()
  58. }
  59. }
  60. },
  61. relayEvents : function(F, D) {
  62. var E = function(G) {
  63. return function() {
  64. return this.fireEvent.apply(this, Ext.combine(G,
  65. Array.prototype.slice.call(arguments, 0)))
  66. }
  67. };
  68. for (var C = 0, A = D.length; C < A; C++) {
  69. var B = D[C];
  70. if (!this.events[B]) {
  71. this.events[B] = true
  72. }
  73. F.on(B, E(B), this)
  74. }
  75. },
  76. addEvents : function(D) {
  77. if (!this.events) {
  78. this.events = {}
  79. }
  80. if (typeof D == "string") {
  81. for (var C = 0, A = arguments, B; B = A[C]; C++) {
  82. if (!this.events[A[C]]) {
  83. D[A[C]] = true
  84. }
  85. }
  86. } else {
  87. Ext.applyIf(this.events, D)
  88. }
  89. },
  90. hasListener : function(A) {
  91. var B = this.events[A];
  92. return typeof B == "object" && B.listeners.length > 0
  93. },
  94. suspendEvents : function() {
  95. this.eventsSuspended = true
  96. },
  97. resumeEvents : function() {
  98. this.eventsSuspended = false
  99. },
  100. getMethodEvent : function(G) {
  101. if (!this.methodEvents) {
  102. this.methodEvents = {}
  103. }
  104. var F = this.methodEvents[G];
  105. if (!F) {
  106. F = {};
  107. this.methodEvents[G] = F;
  108. F.originalFn = this[G];
  109. F.methodName = G;
  110. F.before = [];
  111. F.after = [];
  112. var C, B, D;
  113. var E = this;
  114. var A = function(J, I, H) {
  115. if ((B = J.apply(I || E, H)) !== undefined) {
  116. if (typeof B === "object") {
  117. if (B.returnValue !== undefined) {
  118. C = B.returnValue
  119. } else {
  120. C = B
  121. }
  122. if (B.cancel === true) {
  123. D = true
  124. }
  125. } else {
  126. if (B === false) {
  127. D = true
  128. } else {
  129. C = B
  130. }
  131. }
  132. }
  133. };
  134. this[G] = function() {
  135. C = B = undefined;
  136. D = false;
  137. var I = Array.prototype.slice.call(arguments, 0);
  138. for (var J = 0, H = F.before.length; J < H; J++) {
  139. A(F.before[J].fn, F.before[J].scope, I);
  140. if (D) {
  141. return C
  142. }
  143. }
  144. if ((B = F.originalFn.apply(E, I)) !== undefined) {
  145. C = B
  146. }
  147. for (var J = 0, H = F.after.length; J < H; J++) {
  148. A(F.after[J].fn, F.after[J].scope, I);
  149. if (D) {
  150. return C
  151. }
  152. }
  153. return C
  154. }
  155. }
  156. return F
  157. },
  158. beforeMethod : function(D, B, A) {
  159. var C = this.getMethodEvent(D);
  160. C.before.push({
  161. fn : B,
  162. scope : A
  163. })
  164. },
  165. afterMethod : function(D, B, A) {
  166. var C = this.getMethodEvent(D);
  167. C.after.push({
  168. fn : B,
  169. scope : A
  170. })
  171. },
  172. removeMethodListener : function(F, D, C) {
  173. var E = this.getMethodEvent(F);
  174. for (var B = 0, A = E.before.length; B < A; B++) {
  175. if (E.before[B].fn == D && E.before[B].scope == C) {
  176. E.before.splice(B, 1);
  177. return
  178. }
  179. }
  180. for (var B = 0, A = E.after.length; B < A; B++) {
  181. if (E.after[B].fn == D && E.after[B].scope == C) {
  182. E.after.splice(B, 1);
  183. return
  184. }
  185. }
  186. }
  187. };
  188. Ext.util.Observable.prototype.on = Ext.util.Observable.prototype.addListener;
  189. Ext.util.Observable.prototype.un = Ext.util.Observable.prototype.removeListener;
  190. Ext.util.Observable.capture = function(C, B, A) {
  191. C.fireEvent = C.fireEvent.createInterceptor(B, A)
  192. };
  193. Ext.util.Observable.releaseCapture = function(A) {
  194. A.fireEvent = Ext.util.Observable.prototype.fireEvent
  195. };
  196. (function() {
  197. var B = function(F, G, E) {
  198. var D = new Ext.util.DelayedTask();
  199. return function() {
  200. D.delay(G.buffer, F, E, Array.prototype.slice.call(arguments, 0))
  201. }
  202. };
  203. var C = function(F, G, E, D) {
  204. return function() {
  205. G.removeListener(E, D);
  206. return F.apply(D, arguments)
  207. }
  208. };
  209. var A = function(E, F, D) {
  210. return function() {
  211. var G = Array.prototype.slice.call(arguments, 0);
  212. setTimeout(function() {
  213. E.apply(D, G)
  214. }, F.delay || 10)
  215. }
  216. };
  217. Ext.util.Event = function(E, D) {
  218. this.name = D;
  219. this.obj = E;
  220. this.listeners = []
  221. };
  222. Ext.util.Event.prototype = {
  223. addListener : function(G, F, E) {
  224. F = F || this.obj;
  225. if (!this.isListening(G, F)) {
  226. var D = this.createListener(G, F, E);
  227. if (!this.firing) {
  228. this.listeners.push(D)
  229. } else {
  230. this.listeners = this.listeners.slice(0);
  231. this.listeners.push(D)
  232. }
  233. }
  234. },
  235. createListener : function(G, F, H) {
  236. H = H || {};
  237. F = F || this.obj;
  238. var D = {
  239. fn : G,
  240. scope : F,
  241. options : H
  242. };
  243. var E = G;
  244. if (H.delay) {
  245. E = A(E, H, F)
  246. }
  247. if (H.single) {
  248. E = C(E, this, G, F)
  249. }
  250. if (H.buffer) {
  251. E = B(E, H, F)
  252. }
  253. D.fireFn = E;
  254. return D
  255. },
  256. findListener : function(I, H) {
  257. H = H || this.obj;
  258. var F = this.listeners;
  259. for (var G = 0, D = F.length; G < D; G++) {
  260. var E = F[G];
  261. if (E.fn == I && E.scope == H) {
  262. return G
  263. }
  264. }
  265. return -1
  266. },
  267. isListening : function(E, D) {
  268. return this.findListener(E, D) != -1
  269. },
  270. removeListener : function(F, E) {
  271. var D;
  272. if ((D = this.findListener(F, E)) != -1) {
  273. if (!this.firing) {
  274. this.listeners.splice(D, 1)
  275. } else {
  276. this.listeners = this.listeners.slice(0);
  277. this.listeners.splice(D, 1)
  278. }
  279. return true
  280. }
  281. return false
  282. },
  283. clearListeners : function() {
  284. this.listeners = []
  285. },
  286. fire : function() {
  287. var F = this.listeners, I, D = F.length;
  288. if (D > 0) {
  289. this.firing = true;
  290. var G = Array.prototype.slice.call(arguments, 0);
  291. for (var H = 0; H < D; H++) {
  292. var E = F[H];
  293. if (E.fireFn
  294. .apply(E.scope || this.obj || window, arguments) === false) {
  295. this.firing = false;
  296. return false
  297. }
  298. }
  299. this.firing = false
  300. }
  301. return true
  302. }
  303. }
  304. })();