Skip to content

Commit ce29c33

Browse files
committed
add an iframe
1 parent 8fb780d commit ce29c33

File tree

3 files changed

+101
-90
lines changed

3 files changed

+101
-90
lines changed

examples/example.template.html

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -213,72 +213,72 @@
213213
<div style="display: flex; flex-direction: column; align-items: center; width: 100%">
214214
<h2>Branch Metrics Web SDK Example</h2>
215215
<hr class="lineBreak horizontalLine">
216-
<!-- <div class="split-container">-->
217-
<!-- <div class="container api-methods">-->
218-
<!-- <section>-->
219-
<!-- <h3>Methods</h3>-->
220-
<!-- <a href="https://help.branch.io/developers-hub/docs/web-full-reference" target="_blank">https://help.branch.io/developers-hub/docs/web-full-reference</a>-->
221-
<!-- <hr class="lineBreak horizontalLine">-->
222-
223-
<!-- <h4>Session</h4>-->
224-
<!-- <div class="group">-->
225-
<!-- <button class="btn btn-info" onclick="callData()">.data()</button>-->
226-
<!-- <button class="btn btn-info" onclick="callLogout()">Logout</button>-->
227-
<!-- <button class="btn btn-info" onclick="callFirst()">.first()</button>-->
228-
<!-- </div>-->
229-
<!-- <h4>Identity</h4>-->
230-
<!-- <div class="group">-->
231-
<!-- <input class="example-input" type="text" id="identityID" placeholder="[email protected]">-->
232-
<!-- <button id="setIdentity" class="btn btn-info" onclick="callSetIdentity()">Set Identity</button>-->
233-
<!-- </div>-->
234-
<!-- <h4>Events</h4>-->
235-
<!-- <div class="group">-->
236-
<!-- <button class="btn btn-info" onclick="callLogEvent('PURCHASE')">Create Standard Event</button>-->
237-
<!-- <button class="btn btn-info" onclick="callLogEvent('testedCustomEvent')">Create Custom Event</button>-->
238-
<!-- </div>-->
239-
<!-- <h4>Sharing</h4>-->
240-
<!-- <div class="group">-->
241-
<!-- <button class="btn btn-info" onclick="callLink()">Create Link</button>-->
242-
<!-- <button class="btn btn-info" onclick="callQrCode()">Create QrCode</button>-->
243-
<!-- <button class="btn btn-info" onclick="callBanner()">.banner()</button>-->
244-
<!-- </div>-->
245-
<!-- <h4>Tracking</h4>-->
246-
<!-- <div class="group">-->
247-
<!-- <button class="btn btn-info" onclick="callDisableTracking()">Disable Tracking</button>-->
248-
<!-- <button class="btn btn-info" onclick="callEnableTracking()">Enable Tracking</button>-->
249-
<!-- </div>-->
250-
<!-- <h3>Api Settings</h3>-->
251-
<!-- <hr class="lineBreak horizontalLine">-->
252-
<!-- <div class="group" id="configButtons"></div>-->
253-
<!-- <label id="branchKeyLabel" for="branchKeyInput">Branch Key:</label>-->
254-
<!-- <input type="text" id="branchKeyInput" class="apiInput">-->
255-
<!-- <br>-->
256-
<!-- <label id="apiUrlLabel" for="apiUrlInput">Api Url:</label>-->
257-
<!-- <input type="text" id="apiUrlInput" class="apiInput">-->
258-
<!-- <br>-->
259-
<!-- <button class="btn btn-info" onclick="updateQueryParams()">-->
260-
<!-- Update Api Settings-->
261-
<!-- </button>-->
262-
<!-- </section>-->
263-
<!-- </div>-->
264-
<!-- <div class="lineBreak verticalLine"></div>-->
265-
<!-- <div class="container api-info">-->
266-
<!-- <section>-->
267-
<!-- <h3>Api Requests</h3>-->
268-
<!-- <hr class="lineBreak horizontalLine">-->
269-
<!-- <h4>Session Info-->
270-
<!-- <button class="btn btn-info" onclick="copySessionInfo()" style="margin-left: 10px; font-size: 12px; padding: 2px 8px; cursor: pointer;">-->
271-
<!-- Copy-->
272-
<!-- </button>-->
273-
<!-- </h4>-->
274-
<!-- <pre id="session-info">Reading session from .init()...</pre>-->
275-
<!-- <h4>Request</h4>-->
276-
<!-- <pre id="request">Click a button!</pre>-->
277-
<!-- <h4>Response</h4>-->
278-
<!-- <pre id="response">Click a button!</pre>-->
279-
<!-- </section>-->
280-
<!-- </div>-->
281-
<!-- </div>-->
216+
<div class="split-container">
217+
<div class="container api-methods">
218+
<section>
219+
<h3>Methods</h3>
220+
<a href="https://help.branch.io/developers-hub/docs/web-full-reference" target="_blank">https://help.branch.io/developers-hub/docs/web-full-reference</a>
221+
<hr class="lineBreak horizontalLine">
222+
223+
<h4>Session</h4>
224+
<div class="group">
225+
<button class="btn btn-info" onclick="callData()">.data()</button>
226+
<button class="btn btn-info" onclick="callLogout()">Logout</button>
227+
<button class="btn btn-info" onclick="callFirst()">.first()</button>
228+
</div>
229+
<h4>Identity</h4>
230+
<div class="group">
231+
<input class="example-input" type="text" id="identityID" placeholder="[email protected]">
232+
<button id="setIdentity" class="btn btn-info" onclick="callSetIdentity()">Set Identity</button>
233+
</div>
234+
<h4>Events</h4>
235+
<div class="group">
236+
<button class="btn btn-info" onclick="callLogEvent('PURCHASE')">Create Standard Event</button>
237+
<button class="btn btn-info" onclick="callLogEvent('testedCustomEvent')">Create Custom Event</button>
238+
</div>
239+
<h4>Sharing</h4>
240+
<div class="group">
241+
<button class="btn btn-info" onclick="callLink()">Create Link</button>
242+
<button class="btn btn-info" onclick="callQrCode()">Create QrCode</button>
243+
<button class="btn btn-info" onclick="callBanner()">.banner()</button>
244+
</div>
245+
<h4>Tracking</h4>
246+
<div class="group">
247+
<button class="btn btn-info" onclick="callDisableTracking()">Disable Tracking</button>
248+
<button class="btn btn-info" onclick="callEnableTracking()">Enable Tracking</button>
249+
</div>
250+
<h3>Api Settings</h3>
251+
<hr class="lineBreak horizontalLine">
252+
<div class="group" id="configButtons"></div>
253+
<label id="branchKeyLabel" for="branchKeyInput">Branch Key:</label>
254+
<input type="text" id="branchKeyInput" class="apiInput">
255+
<br>
256+
<label id="apiUrlLabel" for="apiUrlInput">Api Url:</label>
257+
<input type="text" id="apiUrlInput" class="apiInput">
258+
<br>
259+
<button class="btn btn-info" onclick="updateQueryParams()">
260+
Update Api Settings
261+
</button>
262+
</section>
263+
</div>
264+
<div class="lineBreak verticalLine"></div>
265+
<div class="container api-info">
266+
<section>
267+
<h3>Api Requests</h3>
268+
<hr class="lineBreak horizontalLine">
269+
<h4>Session Info
270+
<button class="btn btn-info" onclick="copySessionInfo()" style="margin-left: 10px; font-size: 12px; padding: 2px 8px; cursor: pointer;">
271+
Copy
272+
</button>
273+
</h4>
274+
<pre id="session-info">Reading session from .init()...</pre>
275+
<h4>Request</h4>
276+
<pre id="request">Click a button!</pre>
277+
<h4>Response</h4>
278+
<pre id="response">Click a button!</pre>
279+
</section>
280+
</div>
281+
</div>
282282
</div>
283283
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
284284
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

src/branch_view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ branch_view._getPageviewRequestData = function(metadata, options, branch, isDism
245245
obj = utils.addPropertyIfNotNull(obj, 'branch_view_id', branchViewId);
246246
obj = utils.addPropertyIfNotNull(obj, 'no_journeys', options['no_journeys']);
247247
obj = utils.addPropertyIfNotNull(obj, 'is_iframe', utils.isIframe());
248-
// obj = utils.addPropertyIfNotNull(obj, 'journey_dismissals', journeyDismissals);
248+
obj = utils.addPropertyIfNotNull(obj, 'journey_dismissals', journeyDismissals);
249249
obj = utils.addPropertyIfNotNull(obj, 'identity', identity);
250250
obj = utils.addPropertyIfNotNull(obj, 'session_link_click_id', SessionlinkClickId);
251251
obj['user_language'] = userLanguage;

src/journeys_utils.js

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,6 @@ journeys_utils.createIframe = function() {
248248
iframe.scrolling = 'no';
249249
iframe.id = 'branch-banner-iframe';
250250
iframe.className = 'branch-animation';
251-
iframe.setAttribute('tabindex', '0');
252-
iframe.setAttribute('aria-label', 'Branch Banner Frame');
253-
iframe.title = 'Branch Banner Frame';
254251
utils.addNonceAttribute(iframe);
255252

256253
return iframe;
@@ -288,38 +285,52 @@ journeys_utils.addHtmlToIframe = function(iframe, html, userAgent) {
288285
var focusableContent = modal.querySelectorAll(focusableElements);
289286
var focusElementIdx = 0;
290287
291-
function handleTabKey(e) {
288+
function handleKeyboardNavigation(e) {
292289
var isTabPressed = e.key === 'Tab' || e.keyCode === 9;
293-
294-
if (!isTabPressed) {
295-
return;
296-
}
290+
var isEnterPressed = e.key === 'Enter' || e.keyCode === 13;
297291
298-
console.log('tab pressed');
299-
300-
if (e.shiftKey) {
301-
if (focusElementIdx <= 0) {
302-
focusElementIdx = focusableContent.length - 1;
292+
// Handle Tab key for focus navigation
293+
if (isTabPressed) {
294+
if (e.shiftKey) {
295+
if (focusElementIdx <= 0) {
296+
focusElementIdx = focusableContent.length - 1;
297+
} else {
298+
focusElementIdx = focusElementIdx - 1;
299+
}
303300
} else {
304-
focusElementIdx = focusElementIdx - 1;
301+
if (focusElementIdx >= focusableContent.length - 1) {
302+
focusElementIdx = 0;
303+
} else {
304+
focusElementIdx = focusElementIdx + 1;
305+
}
305306
}
306-
} else {
307-
if (focusElementIdx >= focusableContent.length - 1) {
308-
focusElementIdx = 0;
309-
} else {
310-
focusElementIdx = focusElementIdx + 1;
307+
308+
focusableContent[focusElementIdx].focus();
309+
e.preventDefault();
310+
return;
311+
}
312+
313+
// Handle Enter key for activation
314+
if (isEnterPressed) {
315+
// Get the currently focused element
316+
var focusedElement = document.activeElement;
317+
if (focusedElement && (
318+
focusedElement.tagName === 'BUTTON' ||
319+
focusedElement.getAttribute('role') === 'button' ||
320+
focusedElement.tagName === 'A'
321+
)) {
322+
// Simulate a click on the element
323+
focusedElement.click();
324+
e.preventDefault();
311325
}
312326
}
313-
314-
focusableContent[focusElementIdx].focus();
315-
e.preventDefault();
316327
}
317328
318329
function autoFocus(delay) {
319330
setTimeout(function() { focusableContent[focusElementIdx].focus() }, delay);
320331
}
321332
322-
document.addEventListener('keydown', handleTabKey);
333+
document.addEventListener('keydown', handleKeyboardNavigation);
323334
autoFocus(100);
324335
325336
`;

0 commit comments

Comments
 (0)