Skip to content

Commit 91f8c07

Browse files
committed
Add auto-embed using data tags
1 parent 1ea0e77 commit 91f8c07

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

js/puzzlescript-embed.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
(function()
22
{
3-
window.PuzzleScript = window.PuzzleScript || { };
4-
5-
window.PuzzleScript.embed = function(element, id, config)
3+
function embed(element, id, config)
64
{
75
var canvas,
86
settings =
@@ -36,7 +34,7 @@
3634
load_game(element, id, settings);
3735
}
3836
});
39-
};
37+
}
4038

4139
function clear_children(element)
4240
{
@@ -100,4 +98,25 @@
10098
return target;
10199
}
102100

101+
function auto_embed()
102+
{
103+
var element = document.querySelector("*[data-puzzlescript]");
104+
105+
if (element != null)
106+
{
107+
var config = { };
108+
109+
if (element.dataset.puzzlescriptJs != undefined)
110+
{
111+
config.engine = element.dataset.puzzlescriptJs;
112+
}
113+
114+
embed(element, element.dataset.puzzlescript, config);
115+
}
116+
}
117+
118+
window.PuzzleScript = window.PuzzleScript || { embed: embed };
119+
120+
window.addEventListener("load", auto_embed);
121+
103122
})();

0 commit comments

Comments
 (0)