1 /*
2 * Sybase Hybrid App version 2.5
3 *
4 * Callbacks.js
5 * This file will not be regenerated, so it is possible to modify it, but it
6 * is not recommended.
7 *
8 * Copyright (c) 2012 Sybase Inc. All rights reserved.
9 */
10
11 /**
12 * The namespace for the Hybrid Web Container javascript
13 * @namespace
14 */
15 hwc = (typeof hwc === "undefined" || !hwc) ? {} : hwc; // SUP 'namespace'
16
17
18 (function(hwc, window, undefined) {
19
20 /**
21 * Constructs CallbackSet object. This object is not meant for general use.
22 * @private
23 * @constructor
24 * @memberOf hwc
25 */
26 hwc.CallbackSet = function() {
27 hwc.CallbackSet.setCount++;
28 this.setId = hwc.CallbackSet.setCount;
29 };
30
31 /**
32 * @private
33 * @static
34 * @memberOf hwc.CallbackSet
35 */
36 hwc.CallbackSet.setCount = 0;
37
38 /**
39 * @private
40 * @static
41 * @memberOf hwc.CallbackSet
42 */
43 hwc.CallbackSet.callbacks = {};
44
45 /**
46 * Registers a callback to be handled from container
47 * @memberOf hwc.CallbackSet
48 * @private
49 * @param methodName The name of the callback.
50 * @param callback The function pointer to the callback
51 * @return callbackId that can be used by the container
52 */
53 hwc.CallbackSet.prototype.registerCallback = function (methodName, callback) {
54 if (!hwc.CallbackSet.callbacks[this.setId]) {
55 hwc.CallbackSet.callbacks[this.setId] = {};
56 }
57
58 hwc.CallbackSet.callbacks[this.setId][methodName] = callback;
59 return this.setId + ':' + methodName;
60 };
61
62 /**
63 * Invoked asynchronously to handle callback from container
64 * @memberOf hwc.CallbackSet
65 * @static
66 * @private
67 * @param callbackId The id of the callback. Format is "setid:methodname"
68 * @param removeSet True if the callback set should be removed
69 * @param args The arguments to be passed to the registered callback
70 */
71 hwc.CallbackSet.callbackHandler = function(callbackId, removeSet, args) {
72 var callbackSet, c, callback;
73 c = callbackId.split(':', 2);
74
75 if ( c && c.length === 2 ) {
76 callbackSet = hwc.CallbackSet.callbacks[c[0]];
77
78 if (callbackSet) {
79 callback = callbackSet[c[1]];
80
81 if (removeSet) {
82 delete hwc.CallbackSet.callbacks[c[0]];
83 }
84
85 if (callback) {
86 callback.apply(callback, args);
87 }
88 }
89 }
90 };
91
92 window.CallbackSet = [];
93 window.CallbackSet.callbackHandler = hwc.CallbackSet.callbackHandler;
94
95 })(hwc, window);
96
97
98