|
1 |
| -var Channel = require("./Channel"), |
2 |
| - /** |
3 |
| - * onDOMContentLoaded channel is fired when the DOM content |
4 |
| - * of the page has been parsed. |
5 |
| - */ |
6 |
| - onDOMContentLoaded = new Channel('onDOMContentLoaded'), |
7 |
| - /** |
8 |
| - * onNativeReady channel is fired when the PhoneGap native code |
9 |
| - * has been initialized. |
10 |
| - */ |
11 |
| - onNativeReady = new Channel('onNativeReady'), |
12 |
| - /** |
13 |
| - * onPhoneGapInit channel is fired when the web page is fully loaded and |
14 |
| - * PhoneGap native code has been initialized. |
15 |
| - */ |
16 |
| - onPhoneGapInit = new Channel('onPhoneGapInit'), |
17 |
| - /** |
18 |
| - * onPhoneGapReady channel is fired when the JS PhoneGap objects have been created. |
19 |
| - */ |
20 |
| - onPhoneGapReady = new Channel('onPhoneGapReady'), |
21 |
| - /** |
22 |
| - * onPhoneGapInfoReady channel is fired when the PhoneGap device properties |
23 |
| - * has been set. |
24 |
| - */ |
25 |
| - onPhoneGapInfoReady = new Channel('onPhoneGapInfoReady'), |
26 |
| - /** |
27 |
| - * onPhoneGapConnectionReady channel is fired when the PhoneGap connection properties |
28 |
| - * has been set. |
29 |
| - */ |
30 |
| - onPhoneGapConnectionReady = new Channel('onPhoneGapConnectionReady'), |
31 |
| - /** |
32 |
| - * onResume channel is fired when the PhoneGap native code |
33 |
| - * resumes. |
34 |
| - */ |
35 |
| - onResume = new Channel('onResume'), |
36 |
| - /** |
37 |
| - * onPause channel is fired when the PhoneGap native code |
38 |
| - * pauses. |
39 |
| - */ |
40 |
| - onPause = new Channel('onPause'), |
41 |
| - /** |
42 |
| - * onDeviceReady is fired only after all PhoneGap objects are created and |
43 |
| - * the device properties are set. |
44 |
| - */ |
45 |
| - onDeviceReady = new Channel('onDeviceReady'), |
46 |
| - /** |
47 |
| - * PhoneGap Channels that must fire before "deviceready" is fired. |
48 |
| - */ |
49 |
| - deviceReadyChannelsArray = [onPhoneGapReady, onPhoneGapInfoReady, onPhoneGapConnectionReady], |
50 |
| - deviceReadyChannelsMap = {}, |
51 |
| - _self = { |
| 1 | +(function (context) { |
| 2 | + var Channel = require("./Channel"), |
| 3 | + /** |
| 4 | + * onDOMContentLoaded channel is fired when the DOM content |
| 5 | + * of the page has been parsed. |
| 6 | + */ |
| 7 | + onDOMContentLoaded = new Channel('onDOMContentLoaded'), |
| 8 | + /** |
| 9 | + * onNativeReady channel is fired when the PhoneGap native code |
| 10 | + * has been initialized. |
| 11 | + */ |
| 12 | + onNativeReady = new Channel('onNativeReady'), |
| 13 | + /** |
| 14 | + * onPhoneGapInit channel is fired when the web page is fully loaded and |
| 15 | + * PhoneGap native code has been initialized. |
| 16 | + */ |
| 17 | + onPhoneGapInit = new Channel('onPhoneGapInit'), |
| 18 | + /** |
| 19 | + * onPhoneGapReady channel is fired when the JS PhoneGap objects have been created. |
| 20 | + */ |
| 21 | + onPhoneGapReady = new Channel('onPhoneGapReady'), |
| 22 | + /** |
| 23 | + * onPhoneGapInfoReady channel is fired when the PhoneGap device properties |
| 24 | + * has been set. |
| 25 | + */ |
| 26 | + onPhoneGapInfoReady = new Channel('onPhoneGapInfoReady'), |
| 27 | + /** |
| 28 | + * onPhoneGapConnectionReady channel is fired when the PhoneGap connection properties |
| 29 | + * has been set. |
| 30 | + */ |
| 31 | + onPhoneGapConnectionReady = new Channel('onPhoneGapConnectionReady'), |
| 32 | + /** |
| 33 | + * onResume channel is fired when the PhoneGap native code |
| 34 | + * resumes. |
| 35 | + */ |
| 36 | + onResume = new Channel('onResume'), |
| 37 | + /** |
| 38 | + * onPause channel is fired when the PhoneGap native code |
| 39 | + * pauses. |
| 40 | + */ |
| 41 | + onPause = new Channel('onPause'), |
| 42 | + /** |
| 43 | + * onDeviceReady is fired only after all PhoneGap objects are created and |
| 44 | + * the device properties are set. |
| 45 | + */ |
| 46 | + onDeviceReady = new Channel('onDeviceReady'), |
| 47 | + /** |
| 48 | + * PhoneGap Channels that must fire before "deviceready" is fired. |
| 49 | + */ |
| 50 | + deviceReadyChannelsArray = [onPhoneGapReady, onPhoneGapInfoReady, onPhoneGapConnectionReady], |
| 51 | + deviceReadyChannelsMap = {}, |
| 52 | + _self = { |
52 | 53 |
|
53 |
| - boot: function () { |
54 |
| - //--------------- |
55 |
| - // Event handling |
56 |
| - //--------------- |
| 54 | + boot: function () { |
| 55 | + //--------------- |
| 56 | + // Event handling |
| 57 | + //--------------- |
57 | 58 |
|
58 |
| - /** |
59 |
| - * Listen for DOMContentLoaded and notify our channel subscribers. |
60 |
| - */ |
61 |
| - document.addEventListener('DOMContentLoaded', function() { |
62 |
| - PhoneGap.onDOMContentLoaded.fire(); |
63 |
| - }, false); |
| 59 | + /** |
| 60 | + * Listen for DOMContentLoaded and notify our channel subscribers. |
| 61 | + */ |
| 62 | + document.addEventListener('DOMContentLoaded', function() { |
| 63 | + PhoneGap.onDOMContentLoaded.fire(); |
| 64 | + }, false); |
64 | 65 |
|
65 |
| - /** |
66 |
| - * Intercept calls to document.addEventListener and handle deviceready, |
67 |
| - * resume, and pause events. |
68 |
| - */ |
69 |
| - PhoneGap.m_document_addEventListener = document.addEventListener; |
| 66 | + /** |
| 67 | + * Intercept calls to document.addEventListener and handle deviceready, |
| 68 | + * resume, and pause events. |
| 69 | + */ |
| 70 | + PhoneGap.m_document_addEventListener = document.addEventListener; |
70 | 71 |
|
71 |
| - document.addEventListener = function(evt, handler, capture) { |
72 |
| - var e = evt.toLowerCase(); |
73 |
| - if (e == 'deviceready') { |
74 |
| - PhoneGap.onDeviceReady.subscribeOnce(handler); |
75 |
| - } else if (e == 'resume') { |
76 |
| - PhoneGap.onResume.subscribe(handler); |
77 |
| - // if subscribing listener after event has already fired, invoke the handler |
78 |
| - if (PhoneGap.onResume.fired && handler instanceof Function) { |
79 |
| - handler(); |
| 72 | + document.addEventListener = function(evt, handler, capture) { |
| 73 | + var e = evt.toLowerCase(); |
| 74 | + if (e == 'deviceready') { |
| 75 | + PhoneGap.onDeviceReady.subscribeOnce(handler); |
| 76 | + } else if (e == 'resume') { |
| 77 | + PhoneGap.onResume.subscribe(handler); |
| 78 | + // if subscribing listener after event has already fired, invoke the handler |
| 79 | + if (PhoneGap.onResume.fired && handler instanceof Function) { |
| 80 | + handler(); |
| 81 | + } |
| 82 | + } else if (e == 'pause') { |
| 83 | + PhoneGap.onPause.subscribe(handler); |
| 84 | + } else { |
| 85 | + PhoneGap.m_document_addEventListener.call(document, evt, handler, capture); |
80 | 86 | }
|
81 |
| - } else if (e == 'pause') { |
82 |
| - PhoneGap.onPause.subscribe(handler); |
83 |
| - } else { |
84 |
| - PhoneGap.m_document_addEventListener.call(document, evt, handler, capture); |
85 |
| - } |
86 |
| - }; |
| 87 | + }; |
87 | 88 |
|
88 |
| - /** |
89 |
| - * Create all PhoneGap objects once page has fully loaded and native side is ready. |
90 |
| - */ |
91 |
| - Channel.join(function() { |
| 89 | + /** |
| 90 | + * Create all PhoneGap objects once page has fully loaded and native side is ready. |
| 91 | + */ |
| 92 | + Channel.join(function() { |
92 | 93 |
|
93 |
| - // Run PhoneGap constructors |
94 |
| - onPhoneGapInit.fire(); |
| 94 | + // Run PhoneGap constructors |
| 95 | + onPhoneGapInit.fire(); |
95 | 96 |
|
96 |
| - // Fire event to notify that all objects are created |
97 |
| - onPhoneGapReady.fire(); |
| 97 | + // Fire event to notify that all objects are created |
| 98 | + onPhoneGapReady.fire(); |
98 | 99 |
|
99 |
| - // Fire onDeviceReady event once all constructors have run and |
100 |
| - // PhoneGap info has been received from native side. |
101 |
| - Channel.join(function() { |
102 |
| - onDeviceReady.fire(); |
| 100 | + // Fire onDeviceReady event once all constructors have run and |
| 101 | + // PhoneGap info has been received from native side. |
| 102 | + Channel.join(function() { |
| 103 | + onDeviceReady.fire(); |
| 104 | + |
| 105 | + // Fire the onresume event, since first one happens before JavaScript is loaded |
| 106 | + onResume.fire(); |
| 107 | + }, deviceReadyChannelsArray); |
103 | 108 |
|
104 |
| - // Fire the onresume event, since first one happens before JavaScript is loaded |
105 |
| - onResume.fire(); |
106 |
| - }, deviceReadyChannelsArray); |
107 |
| - |
108 |
| - }, [ onDOMContentLoaded, onNativeReady ]); |
109 |
| - }, |
| 109 | + }, [ onDOMContentLoaded, onNativeReady ]); |
| 110 | + }, |
110 | 111 |
|
111 |
| - /** |
112 |
| - * User-defined channels that must also fire before "deviceready" is fired. |
113 |
| - */ |
114 |
| - waitForInitialization: function(feature) { |
115 |
| - var channel; |
116 |
| - if (feature) { |
117 |
| - channel = new Channel(feature); |
118 |
| - deviceReadyChannelsMap[feature] = channel; |
119 |
| - deviceReadyChannelsArray.push(channel); |
120 |
| - } |
121 |
| - }, |
122 |
| - /** |
123 |
| - * Indicate that initialization code has completed and the feature is ready to |
124 |
| - * be used. |
125 |
| - * |
126 |
| - * @param feature {String} The unique feature name |
127 |
| - */ |
128 |
| - initializationComplete: function(feature) { |
129 |
| - var channel = deviceReadyChannelsMap[feature]; |
130 |
| - if (channel) { |
131 |
| - channel.fire(); |
132 |
| - } |
| 112 | + /** |
| 113 | + * User-defined channels that must also fire before "deviceready" is fired. |
| 114 | + */ |
| 115 | + waitForInitialization: function(feature) { |
| 116 | + var channel; |
| 117 | + if (feature) { |
| 118 | + channel = new Channel(feature); |
| 119 | + deviceReadyChannelsMap[feature] = channel; |
| 120 | + deviceReadyChannelsArray.push(channel); |
| 121 | + } |
| 122 | + }, |
| 123 | + /** |
| 124 | + * Indicate that initialization code has completed and the feature is ready to |
| 125 | + * be used. |
| 126 | + * |
| 127 | + * @param feature {String} The unique feature name |
| 128 | + */ |
| 129 | + initializationComplete: function(feature) { |
| 130 | + var channel = deviceReadyChannelsMap[feature]; |
| 131 | + if (channel) { |
| 132 | + channel.fire(); |
| 133 | + } |
| 134 | + }; |
133 | 135 | };
|
134 |
| - }; |
135 |
| - |
136 |
| -module.exports = _self; |
137 | 136 |
|
138 |
| -// _nativeReady is global variable that the native side can set |
139 |
| -// to signify that the native code is ready. It is a global since |
140 |
| -// it may be called before any PhoneGap JS is ready. |
141 |
| -if (typeof _nativeReady !== 'undefined') { PhoneGap.onNativeReady.fire(); } |
| 137 | + // _nativeReady is global variable that the native side can set |
| 138 | + // to signify that the native code is ready. It is a global since |
| 139 | + // it may be called before any PhoneGap JS is ready. |
| 140 | + if (typeof _nativeReady !== 'undefined') { PhoneGap.onNativeReady.fire(); } |
| 141 | +}(global || window)); |
0 commit comments