Skip to content

Instantly share code, notes, and snippets.

@mtso
Last active March 3, 2017 08:37
Show Gist options
  • Save mtso/37ec5ac89264cab1d2c56e61b609dd42 to your computer and use it in GitHub Desktop.
Save mtso/37ec5ac89264cab1d2c56e61b609dd42 to your computer and use it in GitHub Desktop.
sago prototype
<!doctype html>
<html>
<body>
<script>
function readSago(src) {
return new Promise(function(resolve, reject) {
var rawFile = new XMLHttpRequest();
rawFile.open('GET', src, false);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4 &&
(rawFile.status === 200 || rawFile.status === 0)) {
var text = rawFile.responseText;
resolve(text);
} else {
reject('unsuccessful request to file');
}
}
rawFile.send(null);
});
}
window.onload = function() {
var sago;
for (var i = 0; i < document.scripts.length; i++) {
if (document.scripts[i].type === 'text/sago') {
sago = document.scripts[i];
}
}
readSago(sago.src)
.then(function(content) {
console.log(content);
})
.catch(function(err) {
console.error(err);
});
}
</script>
<script type="text/sago" src="z-hello.sago"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment