Last active
November 3, 2015 12:27
-
-
Save markknol/cc31b146938a1508c02c to your computer and use it in GitHub Desktop.
Custom flambe.js embed-script for JavaScript target only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Custom flambe embed for JavaScript-target only. | |
* Author: Mark Knol - http://blog.stroep.nl | |
*/ | |
var flambe = {}; | |
/** | |
* Embed a Flambe game into the page. | |
* | |
* @return True if the game was successfully embedded. | |
* False if the browser doesn't have a recent enough browser. | |
*/ | |
flambe.embed = function (urls, elementId) { | |
var container = document.getElementById(elementId); | |
if (container == null) { | |
throw new Error("Could not find element [id=" + elementId + "]"); | |
} | |
var canvas = document.createElement("canvas"); | |
if ("getContext" in canvas) { | |
canvas.id = elementId + "-canvas"; | |
container.appendChild(canvas); | |
// Expose the canvas so Haxe can use it | |
flambe.canvas = canvas; | |
var script = document.createElement("script"); | |
script.onload = function () { | |
flambe.canvas = null; | |
}; | |
script.src = urls[0]; | |
container.appendChild(script); | |
return true; | |
} | |
// Nothing was embedded! | |
return false; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- embed script looks like this: --> | |
<script src="flambe.js"></script> | |
<script> | |
flambe.embed(["targets/main-html.js"], "div_main"); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment