-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathb.html
401 lines (360 loc) · 19.8 KB
/
b.html
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<!doctype html>
<html lang="en">
<head>
<title>Modal Message</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* { box-sizing: border-box; } body {margin: 0;}body{font-family:Arial Black, Gadget, sans-serif, 'San Francisco', 'Roboto', Helvetica, Arial, sans-serif;}.bz-cell{display:flex;width:100%;}.bz-close-btn{box-sizing:content-box;background-color:transparent;border:none;width:15px;min-width:15px;min-height:15px;height:15px;cursor:pointer;display:block;font-size:15px;line-height:0;padding:15px;text-align:center;}.bz-close-btn:active{background-color:transparent;}.bz-close-btn:focus{background-color:transparent;}.bz-close-btn:hover{background-color:transparent;}.bz-close-btn:hover svg{fill-opacity:0.8;}.bz-close-btn svg{width:100%;height:100%;transition:0.2s ease;}.bz-img{max-width:100%;display:inline-block;}.bz-text{word-break:break-all;width:100%;padding:16px;}.bz-btn{box-sizing:border-box;border-radius:5px;box-shadow:none;cursor:pointer;display:inline-block;font-size:14px;font-weight:bold;height:44px;line-height:normal;letter-spacing:normal;margin:0;max-width:100%;width:100%;padding:0 12px;position:relative;text-transform:none;border:1px solid #1B78CF;background-color:#1B78CF;color:white;transition:0.2s ease;font-family:inherit;overflow:hidden;text-overflow:ellipsis;word-wrap:normal;white-space:nowrap;}.bz-btn:after{content:'';position:absolute;width:100%;height:100%;top:0;left:0;opacity:0;transition:0.2s ease;}.bz-btn:hover{opacity:0.8;}.bz-btn:active:after{background-color:rgba(0, 0, 0, 0.08);opacity:1;}.bz-btn:focus:after{background-color:rgba(0, 0, 0, 0.15);opacity:1;}.bz-btn a{color:inherit;text-decoration:inherit;}.bz-sctn{box-sizing:border-box;line-height:1.5;overflow-y:auto;width:100%;padding:0 25px;display:flex;flex-direction:column;align-items:center;}.bz-sctn::-webkit-scrollbar{-webkit-appearance:none;width:14px;}.bz-sctn::-webkit-scrollbar-thumb{-webkit-appearance:none;border:4px solid rgba(0, 0, 0, 0);background-clip:padding-box;border-radius:7px;background-color:rgba(0, 0, 0, 0.2);}.bz-sctn::-webkit-scrollbar-button{width:0;height:0;display:none;}.bz-sctn::-webkit-scrollbar-corner{background-color:transparent;}.bz-modal{align-items:center;background-color:white;border-radius:8px;box-shadow:0 0 4px rgba(0, 0, 0, 0.3);box-sizing:border-box;display:flex;flex-direction:column;justify-content:center;min-height:100px;overflow:auto;position:relative;width:450px;max-width:450px;max-height:720px;text-align:center;}.bz-background{align-items:center;background-color:rgba(51, 51, 51, 0.75);display:flex;height:100%;justify-content:center;left:0;position:fixed;top:0;width:100%;}#io6d{height:auto;margin:0;}#i8iej{font-weight:700;font-size:20px;line-height:1.3;color:rgb(37, 37, 37);}#idmhi{padding:16px 8px 32px;}#iy3ms{background-color:rgb(255, 255, 255);border-color:#1B78CF;color:#1B78CF;height:44px;margin:0 12px;}#i1yhi{background-color:#1B78CF;border-color:#1B78CF;color:rgb(255, 255, 255);height:44px;margin:0 12px;}@media (max-height: 750px){.bz-modal{max-height:calc(100% - 30px);}}@media (max-width: 600px){.bz-modal{max-width:calc(100% - 30px);}}
</style>
<script type="text/javascript">
var stubPreloadStateForMethod = function(rootObject, rootObjectName, namespacedMethod) {
var stubLocation = rootObject;
namespacedMethod.forEach(function(namespaceChunk, i) {
if (i == namespacedMethod.length - 1) {
stubLocation[namespaceChunk] = function() {
throw new Error(
`${rootObjectName} is not yet defined. Please wait for the "ab.BridgeReady" event using window.addEventListener in order to use ${rootObjectName} directly upon showing the message.`
);
}
} else if (!stubLocation[namespaceChunk]) {
stubLocation[namespaceChunk] = {};
}
stubLocation = stubLocation[namespaceChunk];
});
};
var stubMethod = function(rootObject, rootObjectName, namespacedMethod) {
// When messages first load in the SDKs, the bridge is not yet defined, and the user must listen for the
// ab.BridgeReady event if attempting to use the bridge directly upon message load. This simulates that situation
// with improved guidance.
stubPreloadStateForMethod(rootObject, rootObjectName, namespacedMethod);
// Then next event loop define the "real" stub method as a passthrough to console.log
setTimeout(function() {
var fullName = rootObjectName;
var stubLocation = rootObject;
namespacedMethod.forEach(function(namespaceChunk, i) {
fullName += '.' + namespaceChunk;
if (i == namespacedMethod.length - 1) {
stubLocation[namespaceChunk] = function() {
console.log(fullName + '(' +
Array.prototype.slice.call(arguments).map(function(arg) {
return JSON.stringify(arg);
}).join(', ') + ')'
);
}
} else if (!stubLocation[namespaceChunk]) {
stubLocation[namespaceChunk] = {};
}
stubLocation = stubLocation[namespaceChunk];
});
});
};
appboyBridge = {};
brazeBridge = {};
[
['closeMessage'],
['logClick'],
['logCustomEvent'],
['logPurchase'],
['requestImmediateDataFlush'],
['requestPushPermission'],
['display', 'showFeed'],
['web', 'registerAppboyPushMessages'],
['web', 'trackLocation']
].forEach(function(namespacedMethod) {
stubMethod(appboyBridge, 'appboyBridge', namespacedMethod);
stubMethod(brazeBridge, 'brazeBridge', namespacedMethod);
});
var stubUser = {};
appboyBridge.getUser = function() {return stubUser};
brazeBridge.getUser = function() {return stubUser};
[
['setFirstName'],
['setLastName'],
['setEmail'],
['setGender'],
['setDateOfBirth'],
['setCountry'],
['setHomeCity'],
['setEmailNotificationSubscriptionType'],
['setPushNotificationSubscriptionType'],
['setPhoneNumber'],
['addToCustomAttributeArray'],
['removeFromCustomAttributeArray'],
['incrementCustomUserAttribute'],
['setCustomUserAttribute'],
['setLanguage'],
['setCustomLocationAttribute']
].forEach(function(namespacedUserMethod) {
stubMethod(stubUser, 'appboyBridge.getUser()', namespacedUserMethod);
stubMethod(stubUser, 'brazeBridge.getUser()', namespacedUserMethod);
});
window.addEventListener('load', function() {
setTimeout(function() {
window.dispatchEvent(new CustomEvent("ab.BridgeReady"));
});
});
</script>
</head>
<body>
<div id="i72r1o"></div><div></div><div class="bz-background"><div class="bz-modal" role="dialog" aria-modal="true" aria-label="Modal Message"><div class="close-button-container bz-cell" id="io6d"><div class="bz-cell close-button-container-child"></div><div class="bz-cell close-button-container-child"></div><button type="button" class="bz-close-btn close-button-container-child" aria-label="Close Message" id="ilwd"><svg><svg viewBox="0 0 15 15" xmlns="http://www.w3.org/2000/svg">
<path d="M15 1.5L13.5 0l-6 6-6-6L0 1.5l6 6-6 6L1.5 15l6-6 6 6 1.5-1.5-6-6 6-6z" fill="rgb(196,196,196)" />
</svg></svg></button></div><div class="bz-sctn"><img alt="Modal Image" src="" id="ie52k" class="bz-img"/><div class="bz-text" id="i8iej">Header</div><div class="bz-text">Body</div><div class="bz-text">Body</div><div class="bz-text">Body</div><div class="bz-text">Body</div><div class="bz-text">Body</div><div class="bz-text">Body</div><div class="bz-text">Body</div><div class="bz-text">Body</div><div class="bz-text">Body</div><div class="bz-cell" id="idmhi"><button type="button" id="iy3ms" bz-onclick="[{"trigger":{"type":"click"},"expression":null,"brazeEvents":[{"eventType":"REDIRECT","value":{"operator":"LITERAL_VALUE","value":"https://google.com/?abExternalOpen=false"}},{"eventType":"CLOSE_MESSAGE"}]}]" onclickContract="{"action":"REDIRECT_TO_URL","uri":"https://google.com","useWebview":false}" class="bz-btn">Button 1</button><button type="button" id="i1yhi" bz-logclick="Button 2ww" class="bz-btn">Button 2</button></div></div></div></div><script>var items = document.querySelectorAll('#i72r1o');
for (var i = 0, len = items.length; i < len; i++) {
(function(){
var triggerTypes = {
HTML_EVENT_CLICK: "click",
HTML_EVENT_MOUSEOVER: "mouseover",
HTML_EVENT_MOUSEOUT: "mouseout",
HTML_EVENT_MOUSE_FOCUS: "focus"
};
var expressionTypes = {
LITERAL_VALUE: "LITERAL_VALUE",
LIQUID_INPUT: "LIQUID_INPUT",
FETCH_HTML_VALUE: "FETCH_HTML_VALUE",
AND: "AND",
BLANK: "BLANK",
IS_NUMERIC: "IS_NUMERIC",
NOT: "NOT",
RANGE: "RANGE",
TRUTHY: "TRUTHY"
};
var brazeEventTypes = {
CLOSE_MESSAGE: "CLOSE_MESSAGE",
LOG_CLICK: "LOG_CLICK",
LOG_CUSTOM_EVENT: "LOG_CUSTOM_EVENT",
SET_COUNTRY: "SET_COUNTRY",
SET_FIRST_NAME: "SET_FIRST_NAME",
SHOW_FEED: "SHOW_FEED",
REDIRECT: "REDIRECT"
};
var addEventListenerByEventTraits = function addEventListenerByEventTraits(element, eventTraits) {
// Ensure that we never throw an exception, even if traits are not initialized for a component
if (!element || !eventTraits || eventTraits.length == 0) {
return;
}
return eventTraits.map(function (eventTrait) {
return window.htmlEventTraitHandler.addEventListenerByEventTrait(element, eventTrait);
});
};
var addEventListenerByEventTrait = function addEventListenerByEventTrait(element, eventTrait) {
switch (eventTrait.trigger.type) {
case window.htmlEventTraitHandler.triggerTypes.HTML_EVENT_CLICK:
case window.htmlEventTraitHandler.triggerTypes.HTML_EVENT_MOUSEOUT:
case window.htmlEventTraitHandler.triggerTypes.HTML_EVENT_MOUSEOVER:
case window.htmlEventTraitHandler.triggerTypes.HTML_EVENT_MOUSE_FOCUS:
element.addEventListener(eventTrait.trigger.type, function () {
window.htmlEventTraitHandler.buildHtmlEventListenerCallback(eventTrait)();
});
}
};
var buildHtmlEventListenerCallback = function buildHtmlEventListenerCallback(eventTrait) {
return function () {
var expression = true;
if (eventTrait.expression) {
expression = window.htmlEventTraitHandler.expressionHelper.evalExpression(eventTrait.expression);
}
if (expression) {
window.htmlEventTraitHandler.brazeEventHelper.evalBrazeEventCallbacks(eventTrait.brazeEvents);
}
};
};
var evalExpression = function evalExpression(expression) {
return window.htmlEventTraitHandler.expressionHelper.buildExpressionCallback(expression)();
};
var buildExpressionCallback = function buildExpressionCallback(expression) {
switch (expression.operator) {
case window.htmlEventTraitHandler.expressionTypes.FETCH_HTML_VALUE:
return window.htmlEventTraitHandler.expressionHelper.buildFetchHTMLValueExpressionCallback(expression);
case window.htmlEventTraitHandler.expressionTypes.AND:
return window.htmlEventTraitHandler.expressionHelper.buildAndExpressionCallback(expression);
case window.htmlEventTraitHandler.expressionTypes.BLANK:
return window.htmlEventTraitHandler.expressionHelper.buildBlankExpressionCallback(expression);
case window.htmlEventTraitHandler.expressionTypes.LITERAL_VALUE:
case window.htmlEventTraitHandler.expressionTypes.LIQUID_INPUT:
return window.htmlEventTraitHandler.expressionHelper.buildLiteralValueExpressionCallback(expression);
case window.htmlEventTraitHandler.expressionTypes.TRUTHY:
return window.htmlEventTraitHandler.expressionHelper.buildTruthyValueExpressionCallback(expression);
case window.htmlEventTraitHandler.expressionTypes.IS_NUMERIC:
case window.htmlEventTraitHandler.expressionTypes.NOT:
case window.htmlEventTraitHandler.expressionTypes.RANGE:
return function () {
return null;
};
}
};
var buildLiteralValueExpressionCallback = function buildLiteralValueExpressionCallback(expression) {
return function () {
return expression.value;
};
};
var buildFetchHTMLValueExpressionCallback = function buildFetchHTMLValueExpressionCallback(expression) {
return function () {
var collection = document.getElementsByClassName(expression.value);
if (collection.length > 0) {
return collection[0].innerHTML;
} else {
return null;
}
};
};
var buildAndExpressionCallback = function buildAndExpressionCallback(expression) {
return function () {
return expression.args.every(function (expression) {
return window.htmlEventTraitHandler.expressionHelper.evalExpression(expression);
});
};
};
var buildBlankExpressionCallback = function buildBlankExpressionCallback(expression) {
return function () {
var value = window.htmlEventTraitHandler.expressionHelper.evalExpression(expression.value);
return !value;
};
};
var buildTruthyValueExpressionCallback = function buildTruthyValueExpressionCallback(expression) {
return function () {
var value = window.htmlEventTraitHandler.expressionHelper.evalExpression(expression.value);
return !!value;
};
};
var evalBrazeEventCallbacks = function evalBrazeEventCallbacks(brazeEvents) {
window.htmlEventTraitHandler.brazeEventHelper.buildBrazeEventsCallbacks(brazeEvents).forEach(function (callback) {
callback();
});
};
var buildBrazeEventsCallbacks = function buildBrazeEventsCallbacks(brazeEvents) {
return brazeEvents.map(function (brazeEvent) {
return window.htmlEventTraitHandler.brazeEventHelper.buildBrazeEventCallBack(brazeEvent);
});
};
var buildBrazeEventCallBack = function buildBrazeEventCallBack(brazeEvent) {
switch (brazeEvent.eventType) {
case window.htmlEventTraitHandler.brazeEventTypes.SET_FIRST_NAME:
return window.htmlEventTraitHandler.brazeEventHelper.buildSetFirstNameCallback(brazeEvent);
case window.htmlEventTraitHandler.brazeEventTypes.CLOSE_MESSAGE:
return window.htmlEventTraitHandler.brazeEventHelper.buildCloseMessageCallback();
case window.htmlEventTraitHandler.brazeEventTypes.LOG_CUSTOM_EVENT:
return window.htmlEventTraitHandler.brazeEventHelper.buildLogCustomEventCallback(brazeEvent);
case window.htmlEventTraitHandler.brazeEventTypes.REDIRECT:
return window.htmlEventTraitHandler.brazeEventHelper.buildRedirectCallback(brazeEvent);
case window.htmlEventTraitHandler.brazeEventTypes.LOG_CLICK:
return window.htmlEventTraitHandler.brazeEventHelper.buildLogClickCallback(brazeEvent);
case window.htmlEventTraitHandler.brazeEventTypes.SET_COUNTRY:
case window.htmlEventTraitHandler.brazeEventTypes.SHOW_FEED:
default:
return function () {
return null;
};
}
};
var buildSetFirstNameCallback = function buildSetFirstNameCallback(brazeEvent) {
return function () {
var firstName = window.htmlEventTraitHandler.expressionHelper.evalExpression(brazeEvent.value);
window.appboyBridge.getUser().setFirstName(firstName);
};
};
var buildCloseMessageCallback = function buildCloseMessageCallback() {
return function () {
window.appboyBridge.closeMessage();
};
};
var buildLogCustomEventCallback = function buildLogCustomEventCallback(brazeEvent) {
return function () {
var customEventName = window.htmlEventTraitHandler.expressionHelper.evalExpression(brazeEvent.value);
window.appboyBridge.logCustomEvent(customEventName);
};
};
var buildRedirectCallback = function buildRedirectCallback(brazeEvent) {
return function () {
window.top.location.href = window.htmlEventTraitHandler.expressionHelper.evalExpression(brazeEvent.value);
};
};
var buildLogClickCallback = function buildLogClickCallback(brazeEvent) {
return function () {
var clickIdentifier = window.htmlEventTraitHandler.expressionHelper.evalExpression(brazeEvent.value);
window.appboyBridge.logClick(clickIdentifier);
};
};
window.htmlEventTraitHandler = {
addEventListenerByEventTrait: addEventListenerByEventTrait,
addEventListenerByEventTraits: addEventListenerByEventTraits,
brazeEventTypes: brazeEventTypes,
buildHtmlEventListenerCallback: buildHtmlEventListenerCallback,
expressionTypes: expressionTypes,
triggerTypes: triggerTypes,
brazeEventHelper: {
evalBrazeEventCallbacks: evalBrazeEventCallbacks,
buildBrazeEventsCallbacks: buildBrazeEventsCallbacks,
buildBrazeEventCallBack: buildBrazeEventCallBack,
buildCloseMessageCallback: buildCloseMessageCallback,
buildLogCustomEventCallback: buildLogCustomEventCallback,
buildSetFirstNameCallback: buildSetFirstNameCallback,
buildRedirectCallback: buildRedirectCallback,
buildLogClickCallback: buildLogClickCallback
},
expressionHelper: {
evalExpression: evalExpression,
buildExpressionCallback: buildExpressionCallback,
buildFetchHTMLValueExpressionCallback: buildFetchHTMLValueExpressionCallback,
buildAndExpressionCallback: buildAndExpressionCallback,
buildBlankExpressionCallback: buildBlankExpressionCallback,
buildLiteralValueExpressionCallback: buildLiteralValueExpressionCallback,
buildTruthyValueExpressionCallback: buildTruthyValueExpressionCallback
}
};
}.bind(items[i]))();
}
var items = document.querySelectorAll('#ilwd');
for (var i = 0, len = items.length; i < len; i++) {
(function(){
this.onclick = function () {
window.appboyBridge.requestImmediateDataFlush();
window.appboyBridge.closeMessage();
};
}.bind(items[i]))();
}
var items = document.querySelectorAll('#iy3ms, #i1yhi');
for (var i = 0, len = items.length; i < len; i++) {
(function(){
var finalContract = [];
var onClickContract = this.getAttribute("bz-onclick");
var parsedOnClickContract = JSON.parse(onClickContract);
var logClickIdentifierValue = this.getAttribute("bz-logclick");
if (!parsedOnClickContract) {
// The 'bz-onclick' attribute is only added if the trait section is opened (ie, the component is selected).
// This ensures that the button closes the message at a minimum, even if we never render the trait section
finalContract = [{
trigger: {
type: "click"
},
expression: null,
brazeEvents: [{
eventType: "CLOSE_MESSAGE"
}]
}];
} else {
finalContract = parsedOnClickContract;
}
if (!logClickIdentifierValue) {
// Likewise, we need to be able to retrieve the text content of the button, even if it was never opened
// and in that case we also need to sanitize it and trim it if needed
var invalidCharacterRegex = new RegExp(/[^\w\d -]/g);
var sanitizedInput = this.textContent.replace(invalidCharacterRegex, "");
if (sanitizedInput.length > 250) {
sanitizedInput = sanitizedInput.substr(0, 250);
}
logClickIdentifierValue = sanitizedInput;
} // As a business rule, always log a click - either the button text or the saved value from the trait
finalContract[0].brazeEvents.unshift({
eventType: "LOG_CLICK",
value: {
operator: "LITERAL_VALUE",
value: logClickIdentifierValue
}
});
var element = this;
window.htmlEventTraitHandler.addEventListenerByEventTraits(element, finalContract);
}.bind(items[i]))();
}</script>
</body>
</html>