|
Revision 38, 1.1 kB
(checked in by mischa, 4 years ago)
|
|
Move some of my nifty javascript libraries into wcmtools to share between lj and fb
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 1 | Controller = new Class(Object, { |
|---|
| 2 | |
|---|
| 3 | init: function () { |
|---|
| 4 | Controller.superClass.init.apply(this, arguments); |
|---|
| 5 | |
|---|
| 6 | this.handlers = {}; |
|---|
| 7 | }, |
|---|
| 8 | |
|---|
| 9 | registerActionHandler: function (action, handler) { |
|---|
| 10 | if (!this.handlers[action]) |
|---|
| 11 | this.handlers[action] = []; |
|---|
| 12 | |
|---|
| 13 | // make sure this is an array |
|---|
| 14 | if (!this.handlers[action].push) |
|---|
| 15 | return; |
|---|
| 16 | |
|---|
| 17 | this.handlers[action].push(handler); |
|---|
| 18 | }, |
|---|
| 19 | |
|---|
| 20 | // accepts a hash of action => handler pairs |
|---|
| 21 | registerActionHandlers: function (handlers) { |
|---|
| 22 | for (var action in handlers) { |
|---|
| 23 | var handler = handlers[action]; |
|---|
| 24 | |
|---|
| 25 | if (!handler || !action || action == 'hasOwnMethod') |
|---|
| 26 | continue; |
|---|
| 27 | |
|---|
| 28 | this.registerActionHandler(action, handler); |
|---|
| 29 | } |
|---|
| 30 | }, |
|---|
| 31 | |
|---|
| 32 | removeActionHandler: function (action, handler) { |
|---|
| 33 | if (!this.handlers[action]) |
|---|
| 34 | return; |
|---|
| 35 | |
|---|
| 36 | this.handlers[action].remove(handler); |
|---|
| 37 | }, |
|---|
| 38 | |
|---|
| 39 | dispatchAction: function (action, data) { |
|---|
| 40 | var handlers = this.handlers[action]; |
|---|
| 41 | |
|---|
| 42 | if (!handlers) |
|---|
| 43 | return; |
|---|
| 44 | |
|---|
| 45 | for (i=0; i<handlers.length; i++) { |
|---|
| 46 | if (handlers[i]) |
|---|
| 47 | handlers[i].apply(this, [data]); |
|---|
| 48 | } |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | }); |
|---|