-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhello.html
More file actions
371 lines (312 loc) · 16.5 KB
/
hello.html
File metadata and controls
371 lines (312 loc) · 16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Pulsar JS Hello World</title>
<!-- ----------------------------------------------------------------
- The following script element contains the required code to setup
- the Pulsar JS Bridge from any valid context. Implement your own
- startPulsarApp method in another script
- ------------------------------------------------------------------>
<script type="text/javascript">
/* ******************************
* BEGIN Pulsar bridge boilerplate
* ******************************/
var BRIDGE_ON = true; // set to false to test file in desktop browser
var bridge = function() {
var jsbridge;
var _bridge = {};
/** **************************************************************
* Sends a request (object containing type,
* object, and data properties) across the JS Bridge,
* and results are delivered to the callback function
* @param {object} request data
* @param {function} callback result function (called asynchronously)
* ***************************************************************/
_bridge.sendRequest = function(request, callbackFn) {
try {
if (BRIDGE_ON) {
jsbridge.send(request, callbackFn);
} else {
callbackFn({});
}
} catch (err) {
alert('Javascript-App bridge error: ' + err);
}
};
/** **************************************************************
* Add a handler for a particular notification
* @param {string} handlerName name of notification
* @param {function} handlerFn function called for notification
* ***************************************************************/
_bridge.addHandler = function(handlerName, handlerFn) {
jsbridge.registerHandler(handlerName, handlerFn);
};
/** **************************************************************
* Remove handler for a particular notification
* @param {string} handlerName name of notification
* ***************************************************************/
_bridge.removeHandler = function(handlerName) {
jsbridge.deregisterHandler(handlerName);
};
/** **************************************************************
* Initializes the JS Bridge.
* This should only be called once.
* @param {WebViewJavascriptBridge} _jsbridge the bridge
* ***************************************************************/
_bridge.init = function(_jsbridge) {
if (BRIDGE_ON) {
// prior to Pulsar 12.0, we need to call the init method
// version is only defined on Pulsar 12.0 and later
if (typeof _jsbridge.version === 'undefined') {
_jsbridge.init(function(message, responseCallback) {
console.log('Received message: ' + message);
});
}
jsbridge = _jsbridge;
}
};
/** **************************************************************
* Sets up JS Bridge without reinitializing.
* @param {WebViewJavascriptBridge} _jsbridge the bridge
* ***************************************************************/
_bridge.setup = function(_jsbridge) {
jsbridge = _jsbridge;
}
return _bridge;
}();
/* ******************************
* END Pulsar bridge boilerplate
* ******************************/
/* ******************************
* BEGIN Pulsar bootstrap boilerplate
* ******************************/
const runningEmbeddedInFSL =
typeof window.parent.pulsar !== 'undefined'; // are we running embedded in FSL
const runningStandAlone = !runningEmbeddedInFSL; // are we running in a stand-alone state in our own webview context?
var refObjectId = undefined; // if launched from a record, this is the object Id in question
/* ************************************************************************
* This is the entry point when running your app stand-alone (directly from
* Pulsar, not embedded in an iframe).
* ************************************************************************/
document.addEventListener('WebViewJavascriptBridgeReady', standAloneBootstrap, false);
function standAloneBootstrap(event) {
bridge.init(event.bridge);
// if we are receiving this event, window.pulsar should be undefined
console.assert(window.pulsar === undefined);
window.pulsar = {};
window.pulsar.bridge = event.bridge; // save initial bridge (for propagation to other pages)
commonBootstrap();
}
/* ************************************************************************
* This is the entry point when running your app embedded in another web
* view in Pulsar.
* ************************************************************************/
window.onload = embeddedBootstrap;
function embeddedBootstrap() {
if (runningEmbeddedInFSL && window.parent.pulsar && window.parent.pulsar.bridge) {
window.pulsar = window.parent.pulsar; // ensure we will pass down the embedded window.pulsar
bridge.setup(window.pulsar.bridge); // ensure we are setup properly for this embedded context
// FSL toplevel app sets additional methods you can use
runningEmbeddedInFSL = (window.pulsar['displayContentDocument'] !== undefined);
commonBootstrap();
} else {
if (runningEmbeddedInFSL) {
/* ************************************************************
* Something has gone wrong if we are running embedded and find
* ourselves without window.parent.pulsar.bridge or
* window.parent.pulsar objects.
* ************************************************************/
console.log('OOPS, running embedded, but no window.parent.pulsar.bridge!');
throw 'embedded misconfiguration!';
} else {
/* ************************************************************
* 2021/02/04 NOTE: on iOS platform, windows.onload is called
* after `WebViewJavascriptBridgeReady` is sent, but on Windows
* and Android it is called before. So, because we may not have
* the initial bridge setup at this point, do nothing here.
* ************************************************************/
console.assert(runningStandAlone);
}
}
}
/* ************************************************************************
* This is the common secondary-stage bootstrap where we perform sanity-
* checks and basic logging before launching your custom code.
* ************************************************************************/
function commonBootstrap() {
/* ************************************************************
* At this point we should have the Pulsar JS Bridge either from
* `WebViewJavascriptBridgeReady` event (stand-alone) or via the
* parent context (running embedded).
* ************************************************************/
console.assert(window.pulsar.bridge !== undefined);
console.assert(!(runningEmbeddedInFSL && runningStandAlone));
console.assert(runningEmbeddedInFSL || runningStandAlone);
refObjectId = getQueryVariable('ref_id');
// log the launch context
console.log('Starting Custom Pulsar App' + (runningEmbeddedInFSL ? ' embedded in FSL' : ' stand alone') + (refObjectId ? ' launched from record: ' + refObjectId : ''));
// log any query variables
console.log('query variables ' + stringify(getQueryVariables()));
/* !!!! IMPORTANT !!!!
* The bridge has been initialized and your app is ready for launch.
* startPulsarApp() is any arbitrary method that a developer may (re-)define
* to start their application using the Pulsar JS bridge.
*/
startPulsarApp();
};
/* ******************************
* END Pulsar bootstrap boilerplate
* ******************************/
</script>
<!-- ----------------------------------------------------------------
- The following script element contains generic helper methods.
- ------------------------------------------------------------------>
<script type="text/javascript">
/**
* Helper function to extract URL query variables
* @param {string} variable name
*/
function getQueryVariable(variable) {
const varDict = getQueryVariables();
return varDict[variable];
}
/**
* Helper function to extra all URL query variables into dict
* @returns {dict} Dictionary of query variables
*/
function getQueryVariables() {
const query = window.location.search.substring(1);
const vars = query.split("&");
let varDict = {};
for (var i = 0; i < vars.length; i++) {
const pair = vars[i].split("=");
const key = pair[0];
const val = pair[1];
varDict[key] = val;
}
return varDict;
}
/**
* Helper function to pretty-print data as JSON
* @param {any} obj
* @returns {string} stringified object
*/
function stringify(obj) {
return JSON.stringify(obj, null, 4);
}
</script>
<!-- ----------------------------------------------------------------
- The following script element contains example code that a developer
- might write.
- ------------------------------------------------------------------>
<script type="text/javascript">
/* !!!! IMPORTANT !!!!
* Here we define a custom starting point for the app. This function is
* called above once we are certain that we have established a functional
* Pulsar JS Bridge.
*/
function startPulsarApp() {
// what environment are we running on?
getPlatform();
// what user are we running on behalf of?
getUserInfo();
// populate inital sync status
getSyncInfo();
// this duplicates the console log from the bootstrap boilerplate above
const messageString = 'Started Custom Pulsar App' + (runningEmbeddedInFSL ? ' embedded in FSL' : ' stand alone') + (refObjectId ? ' launched from record: ' + refObjectId : '');
const textElement = document.getElementById("AppStatus");
textElement.innerHTML = messageString;
}
function getPlatform() {
var request = {};
var obj = {};
request["type"] = 'getPlatform';
request["data"] = obj;
bridge.sendRequest(request, function(responseData) {
console.log('platformInfo: ' + stringify(responseData));
const userInfoBody = document.getElementById("PlatformInfoBody");
if (responseData.type === "getplatformResponse" || responseData.type === "platformResponse") {
var platform = responseData.data;
platformStr = 'Running on the ' + platform + ' platform';
if (refObjectId) {
platformStr += ', launched from record: ' + refObjectId;
}
console.log(platformStr);
userInfoBody.innerHTML = platformStr;
} else {
console.assert(responseData.type == 'error');
var errStr = responseData.data;
console.log('A problem occurred:\n' + errStr);
console.log('Couldnt get platform!');
userInfoBody.innerHTML = stringify(responseData.data);
}
});
}
function getUserInfo() {
var request = {};
var obj = {};
request["type"] = 'userInfo';
request["data"] = obj;
bridge.sendRequest(request, function(responseData) {
console.log('userInfo: ' + stringify(responseData));
const userInfoBody = document.getElementById("UserInfoBody");
if (responseData.type === "userInfoResponse") {
userInfoBody.innerHTML = stringify(responseData.data);
} else {
console.assert(responseData.type == 'error');
const errStr = responseData.data;
console.log('A problem occurred:\n' + errStr);
userInfoBody.innerHTML = stringify(responseData.data);
}
});
}
function getSyncInfo() {
var request = {};
var obj = {};
request["type"] = 'syncInfo';
request["data"] = obj;
bridge.sendRequest(request, function(responseData) {
console.log('syncInfo: ' + stringify(responseData));
const syncInfoBody = document.getElementById("SyncInfoBody");
if (responseData.type === "syncinfoResponse") {
syncInfoBody.innerHTML = stringify(responseData.data);
} else {
console.assert(responseData.type == 'error');
const errStr = responseData.data;
console.log('A problem occurred:\n' + errStr);
syncInfoBody.innerHTML = stringify(responseData.data);
}
});
}
</script>
</head>
<body>
<div class="container">
<div>
<p>Hello World!</p>
</div>
<div class="panel-heading">
App Status<br/>
</div>
<div class="panel-body" id="AppStatus">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin accumsan velit ligula, vitae vestibulum orci ultricies in. Quisque pharetra ante ante. Pellentesque velit velit, pellentesque non sapien ut, varius auctor lorem. Quisque sagittis elit et magna suscipit commodo. Quisque pharetra, eros eu eleifend aliquam, mi lectus tincidunt mi, nec ultrices orci massa gravida mi. Fusce nec semper nisl. Nulla finibus sit amet felis eu condimentum. Integer turpis ipsum, elementum eget rutrum a, efficitur eu turpis. Mauris arcu turpis, lacinia ac mi pharetra, posuere feugiat risus. Morbi ligula leo, luctus nec ullamcorper quis, tempor nec mi. Nunc libero leo, posuere tristique vulputate sed, consequat vel mauris. Vestibulum consequat risus mi, non porta justo sagittis sit amet. Sed a ultrices eros. Etiam accumsan justo eros, vel blandit magna facilisis sed.</div>
<hr/>
<div class="panel-heading">
Platform Info<br/>
</div>
<div class="panel-body" id="PlatformInfoBody">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin accumsan velit ligula, vitae vestibulum orci ultricies in. Quisque pharetra ante ante. Pellentesque velit velit, pellentesque non sapien ut, varius auctor lorem. Quisque sagittis elit et magna suscipit commodo. Quisque pharetra, eros eu eleifend aliquam, mi lectus tincidunt mi, nec ultrices orci massa gravida mi. Fusce nec semper nisl. Nulla finibus sit amet felis eu condimentum. Integer turpis ipsum, elementum eget rutrum a, efficitur eu turpis. Mauris arcu turpis, lacinia ac mi pharetra, posuere feugiat risus. Morbi ligula leo, luctus nec ullamcorper quis, tempor nec mi. Nunc libero leo, posuere tristique vulputate sed, consequat vel mauris. Vestibulum consequat risus mi, non porta justo sagittis sit amet. Sed a ultrices eros. Etiam accumsan justo eros, vel blandit magna facilisis sed.</div>
<hr/>
<div class="panel-heading">
User Info<br/>
</div>
<div class="panel-body" id="UserInfoBody">Nam condimentum metus a cursus pharetra. Cras posuere libero mi, id tempus leo ullamcorper ut. Curabitur sed dui vel urna pulvinar semper. Sed rutrum elementum mauris fermentum fermentum. Aenean gravida dictum nunc, sit amet euismod dolor maximus nec. Vestibulum a enim purus. In condimentum mauris sit amet lectus efficitur placerat. Sed sem massa, convallis a sem sit amet, interdum placerat elit. Sed vel lorem ligula. Sed imperdiet ligula elit, in tincidunt leo pellentesque vel. Cras at augue justo. Morbi feugiat commodo ex a lacinia.</div>
<hr/>
<div class="panel-heading">
Sync Info<br/>
</div>
<div class="panel-body" id="SyncInfoBody">Suspendisse nec mauris lobortis, sollicitudin mi eget, cursus metus. Donec aliquet pharetra dolor. Phasellus varius, tellus eu suscipit auctor, lacus ipsum lacinia leo, ut faucibus diam eros vel libero. Etiam ultrices vulputate auctor. Maecenas consectetur sagittis ligula a sodales. Proin ut dapibus lectus. Cras fringilla tempus ante, quis sollicitudin mi. Nulla id tellus a nisl sagittis feugiat sollicitudin non augue. Morbi pellentesque vehicula eros nec mattis. Nulla ultricies, dui et convallis feugiat, arcu lacus aliquet lorem, sed fringilla sapien tellus quis orci. Donec in sollicitudin lectus, a dapibus odio. Nam justo mauris, bibendum sed suscipit a, porta lacinia risus. Mauris sapien dolor, fringilla vitae condimentum sit amet, laoreet eu dolor. Duis porta at eros nec rhoncus. Integer iaculis erat vel neque tincidunt, a lobortis dolor congue.</div>
<hr/>
</div>
</body>
</html>