diff options
Diffstat (limited to 'node_modules/montage-user/core/event/action-event-listener.js')
-rwxr-xr-x | node_modules/montage-user/core/event/action-event-listener.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/node_modules/montage-user/core/event/action-event-listener.js b/node_modules/montage-user/core/event/action-event-listener.js new file mode 100755 index 00000000..bbe5baad --- /dev/null +++ b/node_modules/montage-user/core/event/action-event-listener.js | |||
@@ -0,0 +1,76 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /** | ||
7 | @module montage/core/event/action-event-listener | ||
8 | @requires montage/core/core | ||
9 | */ | ||
10 | var Montage = require("montage").Montage; | ||
11 | |||
12 | /** | ||
13 | @class module:montage/core/event/action-event-listener.ActionEventListener | ||
14 | @extends module:montage/core/core.Montage | ||
15 | */ | ||
16 | var ActionEventListener = exports.ActionEventListener = Montage.create(Montage, /** @lends module:montage/core/event/action-event-listener.ActionEventListener# */ { | ||
17 | |||
18 | /** | ||
19 | The object to handle the event. | ||
20 | @type {Property} | ||
21 | @default {Event handler} null | ||
22 | */ | ||
23 | handler: { | ||
24 | value: null | ||
25 | }, | ||
26 | |||
27 | /** | ||
28 | The action (function) to invoke on the handler object. | ||
29 | @type {Property} | ||
30 | @default {Event handler} null | ||
31 | */ | ||
32 | action: { | ||
33 | value: null | ||
34 | }, | ||
35 | |||
36 | /** | ||
37 | Returns a new ActionEventListener instance with the specified handler and action. | ||
38 | @function | ||
39 | @param {Event} handler The event handler. | ||
40 | @param {Event} action The event handler action. | ||
41 | @returns itself | ||
42 | */ | ||
43 | initWithHandler_action_: { | ||
44 | value: function(handler, action) { | ||
45 | this.handler = handler; | ||
46 | this.action = action; | ||
47 | |||
48 | return this; | ||
49 | } | ||
50 | }, | ||
51 | |||
52 | /** | ||
53 | @private | ||
54 | */ | ||
55 | handleEvent: { | ||
56 | value: function(event) { | ||
57 | if (typeof this.action === "function") { | ||
58 | // TODO call this in what context? | ||
59 | this.action(event); | ||
60 | } else { | ||
61 | this.handler[this.action](event); | ||
62 | } | ||
63 | } | ||
64 | }, | ||
65 | |||
66 | /** | ||
67 | @private | ||
68 | */ | ||
69 | serializeSelf: { | ||
70 | value: function(serializer) { | ||
71 | serializer.setReference("handler", this.handler); | ||
72 | serializer.set("action", this.action); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | }); | ||