Last active
March 2, 2016 03:26
-
-
Save rayh/d023aeba28a25ed7f7f2 to your computer and use it in GitHub Desktop.
Example page loader for TVJS/TVML
This file contains hidden or 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
var SimplePage = function(url) { | |
var self = this; | |
function onSelect(event) { | |
var ele = event.target | |
var href = ele.getAttribute("href") | |
if(href) { | |
new SimplePage(href).load(); | |
} | |
} | |
function pushDoc(document) { | |
var parser = new DOMParser(); | |
var doc = parser.parseFromString(document, "application/xml"); | |
doc.addEventListener("select", onSelect.bind(self)); | |
navigationDocument.pushDocument(doc); | |
} | |
self.load = function() { | |
var templateXHR = new XMLHttpRequest(); | |
templateXHR.responseType = "document"; | |
templateXHR.addEventListener("load", function() { | |
pushDoc(templateXHR.responseText); | |
}, false); | |
templateXHR.open("GET", url, true); | |
templateXHR.send(); | |
return templateXHR; | |
} | |
return self; | |
} |
You might want to check out atvjs framework if you are planning to build an Apple TV application using TVML and TVJS. It will save tons of your time and will let you concentrate on your application logic. It's also available as an npm package so you can use it with your favourite build system :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any license on the above code? Also, any interest in discussing some extensions to it? (If the answer to both questions is "no", I'll just go off and do my own thing while giving you full credit for my starting point.)