Full code:
var tvOS = {
/*
* RatingView
*
* create a nice RatingView (with support of objects)
*
* @todo
* @param string title the title of your RatingView
* @param string rating the default/averange rating
* @param string [callback] function to relay on (Does not work)
* @example tvOS.RatingView(title, rating, callback)
*/
RatingView: function (title, rating, callback) {
var temp = ''
temp += tvOS.TemplateRatingView.replace('tvOS_title', title)
.replace('tvOS_rating', rating)
temp = tvOS.makeDocument(temp)
temp.addEventListener('select', function (e) {
console.log(e)
var pressed = e.target.innerHTML
console.log(pressed)
})
tvOS.display(temp)
},
/*
* makeDocument
*
* make Document with resource
*
* @param string resource the resource
* @example tvOS.makeDocument(xmlString)
*/
makeDocument: function (resource) {
if (!tvOS.parser) {
tvOS.parser = new DOMParser()
}
var doc = tvOS.parser.parseFromString(resource, 'application/xml')
return doc
},
/*
* display
*
* to display a view
*
* @param mixed view the view you want to display
* @example tvOS.display(view)
*/
display: function (view) {
navigationDocument.pushDocument(view)
},
// * tvOS.TemplateRatingView
// *
// * Template for TemplateRating
// *
// * @var string TemplateRatingView
TemplateRatingView: `<?xml version="1.0" encoding="UTF-8"?>
<document>
<ratingTemplate theme="light">
<title>tvOS_title</title>
<ratingBadge value="tvOS_rating"></ratingBadge>
</ratingTemplate>
</document>`
}