Skip to content

Instantly share code, notes, and snippets.

@rayh
Last active March 2, 2016 03:26
Show Gist options
  • Save rayh/d023aeba28a25ed7f7f2 to your computer and use it in GitHub Desktop.
Save rayh/d023aeba28a25ed7f7f2 to your computer and use it in GitHub Desktop.
Example page loader for TVJS/TVML
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;
}
@emadalam
Copy link

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