|
5 | 5 | var networkListeners = []; |
6 | 6 | var rulesListeners = []; |
7 | 7 | var valuesListeners = []; |
| 8 | + var pluginsListeners = []; |
8 | 9 | var handleOnLoad = function() { |
9 | 10 | timer = null; |
10 | 11 | list.forEach(emit); |
|
30 | 31 | case 'values': |
31 | 32 | execListeners(valuesListeners, options); |
32 | 33 | break; |
| 34 | + case 'plugins': |
| 35 | + execListeners(pluginsListeners, options); |
| 36 | + break; |
33 | 37 | default: |
34 | 38 | execListeners(networkListeners, options); |
35 | 39 | } |
|
95 | 99 | var removeAllValuesListeners = function() { |
96 | 100 | valuesListeners = []; |
97 | 101 | }; |
| 102 | + var addPluginsListener = function(l) { |
| 103 | + if (typeof l === 'function' && pluginsListeners.indexOf(l) === -1) { |
| 104 | + pluginsListeners.push(l); |
| 105 | + } |
| 106 | + }; |
| 107 | + var removePluginsListener = function(l) { |
| 108 | + l = pluginsListeners.indexOf(l); |
| 109 | + if (l !== -1) { |
| 110 | + pluginsListeners.splice(l, 1); |
| 111 | + } |
| 112 | + }; |
| 113 | + var removeAllPluginsListeners = function(l) { |
| 114 | + pluginsListeners = []; |
| 115 | + }; |
98 | 116 |
|
99 | 117 | function on(type, l) { |
100 | 118 | if (typeof l !== 'function') { |
|
107 | 125 | return addRulesListener(l); |
108 | 126 | case 'values': |
109 | 127 | return addValuesListener(l); |
| 128 | + case 'plugins': |
| 129 | + return addPluginsListener(l); |
110 | 130 | } |
111 | 131 | } |
112 | 132 |
|
|
133 | 153 | removeAllValuesListeners(); |
134 | 154 | } |
135 | 155 | return; |
| 156 | + case 'plugins': |
| 157 | + if (l) { |
| 158 | + removePluginsListener(l); |
| 159 | + } else { |
| 160 | + removeAllPluginsListeners(); |
| 161 | + } |
| 162 | + return; |
136 | 163 | } |
137 | 164 | } |
138 | 165 |
|
|
149 | 176 | removeAllRulesListeners: removeAllRulesListeners, |
150 | 177 | addValuesListener: addValuesListener, |
151 | 178 | removeValuesListener: removeValuesListener, |
152 | | - removeAllValuesListeners: removeAllValuesListeners |
| 179 | + removeAllValuesListeners: removeAllValuesListeners, |
| 180 | + addPluginsListener: addPluginsListener, |
| 181 | + removePluginsListener: removePluginsListener, |
| 182 | + removeAllPluginsListeners: removeAllPluginsListeners |
153 | 183 | }; |
154 | 184 | try { |
155 | 185 | window.initWhistleBridge = function(options) { |
156 | 186 | window.initWhistleBridge = function() {}; |
157 | 187 | Object.keys(options.msgBox).forEach(function(name) { |
158 | 188 | toast[name] = options.msgBox[name]; |
159 | 189 | }); |
| 190 | + whistleBridge.getSelectedSessionList = options.getSelectedSessionList; |
| 191 | + whistleBridge.getActiveSession = whistleBridge.getSession = whistleBridge.getSelectedSession = options.getActiveSession; |
| 192 | + whistleBridge.showOption = options.showOption; |
| 193 | + whistleBridge.hideOption = options.hideOption; |
160 | 194 | whistleBridge.updateUI = options.updateUI; |
161 | 195 | whistleBridge.copyText = options.copyText; |
162 | 196 | whistleBridge.pageId = options.pageId; |
163 | 197 | whistleBridge.compose = options.compose; |
164 | 198 | whistleBridge.decodeBase64 = options.decodeBase64; |
165 | 199 | whistleBridge.importSessions = options.importSessions; |
166 | 200 | whistleBridge.exportSessions = options.exportSessions; |
| 201 | + whistleBridge.importMockData = options.importMockData; |
| 202 | + whistleBridge.download = options.download; |
| 203 | + whistleBridge.setNetworkSettings = options.setNetworkSettings; |
| 204 | + whistleBridge.setComposerData = options.setComposerData; |
167 | 205 | whistleBridge.request = options.request; |
168 | 206 | whistleBridge.createRequest = options.createRequest; |
169 | 207 | whistleBridge.showModal = options.showModal; |
|
0 commit comments