var resourceLoader;
// app starting point
App.onLaunch = function(options) {
// JS files included in our app (besides bootstrap)
var javascriptFiles = [
`${options.BASEURL}atv/js/ResourceLoader.js`,
`${options.BASEURL}atv/js/Presenter.js`,
];
// see if scripts are broken; load menu if not, else display an error
evaluateScripts(javascriptFiles, function(success) {
if(success) {
resourceLoader = new ResourceLoader(options.BASEURL);
// load our main menu
resourceLoader.fetch({
url: `${options.BASEURL}atv/templates/MainMenu.xml`,
success: function(document) {
document.addEventListener('select', Presenter.load.bind(Presenter));
Presenter.pushDocument(document);
},
error: function(xhr) {
var errorDoc = createAlert("XML Parsing Error", `${options.BASEURL}appletv/templates/MainMenu.xml`);
navigationDocument.presentModal(errorDoc);
}
});
// resourceLoader.loadResource(`${options.BASEURL}appletv/templates/MainMenu.xml.js`, function(resource) {
// // create DOM from template information
// var doc = Presenter.makeDocument(resource);
// doc.addEventListener("select", Presenter.load.bind(Presenter));
// Presenter.pushDocument(doc);
// });
} else {
var errorDoc = createAlert("Evaluate Scripts Error", "Error attempting to evaluate external JavaScript files.");
navigationDocument.presentModal(errorDoc);
}
});
};
// simple function to create a templatized alert
var createAlert = function(title, description) {
var alertString = `
${title}${description}`
var parser = new DOMParser();
var alertDoc = parser.parseFromString(alertString, "application/xml");
return alertDoc;
};
/**
* Convenience function to create a TVML alert document with a title and description.
*/
function createAlertDocument(title, description, isModal) {
// Ensure the text color is appropriate if the alert isn't going to be shown modally.
const textStyle = (isModal) ? "" : "color: rgb(0,0,0)";
const template = `
${title}${description}
`;
return new DOMParser().parseFromString(template, "application/xml");
}
/**
* Convenience function to create a TVML alert for a failed XMLHttpRequest.
*/
function createLoadErrorAlertDocument(url, xhr, isModal) {
const title = (xhr.status) ? `Fetch Error ${xhr.status}` : "Fetch Error";
const description = `Could not load document:\n${url}\n(${xhr.statusText})`;
return createAlertDocument(title, description, isModal);
}