Skip to content

Commit a88cae1

Browse files
committed
Make sure to return focus to current element after ad is closed
1 parent edcdbf8 commit a88cae1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

gamedistribution/lib/web/library_gamedistribution.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33
var GameDistributionLibrary = {
44

55
$Context: {
6-
listener: null
6+
listener: null,
7+
activeElementId: null,
78
},
89

910
GameDistribution_PlatformInit: function(gameId, debug) {
1011
window["GD_DEFOLD"] = {
1112
"onEvent": function(event) {
13+
if (event.name == "SDK_GAME_START" && Context.activeElementId) {
14+
var element = document.getElementById(activeElementId);
15+
if (element) {
16+
element.focus();
17+
}
18+
}
1219
var listener = Context.listener;
1320
if (!listener) {
1421
console.log("No listener set");
@@ -53,6 +60,10 @@ var GameDistributionLibrary = {
5360

5461
GameDistribution_PlatformShowInterstitialAd: function() {
5562
if (typeof gdsdk !== 'undefined' && gdsdk.showAd !== 'undefined') {
63+
var activeElement = document.activeElement;
64+
if (activeElement) {
65+
Context.activeElementId = document.activeElement.id;
66+
}
5667
gdsdk.showAd(gdsdk.AdType.Interstitial)
5768
.then(() => console.info('showAd(AdType.Interstitial) resolved.'))
5869
.catch(error => console.error(error));
@@ -61,6 +72,10 @@ var GameDistributionLibrary = {
6172

6273
GameDistribution_PlatformShowRewardedAd: function() {
6374
if (typeof gdsdk !== 'undefined' && gdsdk.showAd !== 'undefined') {
75+
var activeElement = document.activeElement;
76+
if (activeElement) {
77+
Context.activeElementId = document.activeElement.id;
78+
}
6479
gdsdk.showAd(gdsdk.AdType.Rewarded)
6580
.then(() => console.info('showAd(AdType.Rewarded) resolved.'))
6681
.catch(error => console.error(error));

0 commit comments

Comments
 (0)