looking at the new docs it isn't clear if you can use tvml and the JS framework to manipulate the dom or if you can only pass back static markup from the server and limit the JS code to responding to events and loading new content from the server
Can tvml Dom be manipulated in js
Yes, you can. You can either schedule it with a timer, or add to it by calling a JS function and running the DOM modification. I can attempt to send you a link of what I did for an older version of the aTV, however the moderators hold links like forever.
Yes, you can use TVJS to update and manipulate TVML documents.
The TVML JavaScript framework incorporates the following standard Document Object Module classes.
CharacterData, Comment, CustomEvent, Document, DocumentFragment, DOMException, DOMImplementation, DOMImplementationLS, DOMImplementationRegistry, DOMParser, Element, Event, EventException, EventTarget, HTMLCollection, LSException, LSInput, LSParser, LSSerializer, Node, NodeList, ParentNode, ParsingElement, Text, XMLSerializer, XPathEvaluator, XPathException, XPathExpression, XPathResult
For information on the classes, see World Wide Web Consortium.
For information on TVML:
For information on TVJS:
You can create DOM documents using string or create entire tree in memory using DOM APIs. You can modify DOM i.e. insert new elements or remove elements at any point, and if this document was pushed on stack using navigationDocument.pushDocument(), your updates to DOM tree will get reflected in UI automatically.
I have a case which crashes the app (trying to duplicate in a smaller example) where calling removeChild of a node that is in a currently displayed document (specifically results in a search template) don't actually seem to remove them and in fact cause the app to crash.
Hi there, I am trying to getElementsByTagName for my buttons defined in alertTemplate, I checked the length of return object has 2 elements, however when I try the DOM Element API on any of those (eg: getAttribute), it doesn't work. Wonder if this is only smulator problem?
Can you please file bug report with reduced test case attached. Thanks.
I'm trying to update the background image in a stackTemplate using TVJS and nothing I do seems to work. Whether starting without a background element and adding one or starting with a background element and replacing it, nothing seems to work. Should this be possible?
var newBg = ele.ownerDocument.createElement("background");
newBg.innerHTML = "<img src='http://localhost:9001/resources/images/my_image.jpg' width='1920' height='1080' />";
var parent = ele.ownerDocument.getElementsByTagName("stackTemplate").item(0);
var child = ele.ownerDocument.getElementsByTagName("background").item(0);
parent.replaceChild(newBg, child);When I check the DOM using the console, the JS changes do affect the DOM but those changes don't seem to trigger an update of the interface.
FWIW, in this case I'm trying to change the background of the page as the user highlights different lockups.
I'm also having trouble attempting to remove `overlay` elements. The only ones that seem to actually get redrawn are those offscreen. Is there a trick to getting onscreen elements to redraw? This occurs even if the overlays I'm removing are behind a modal while I'm trying to remove them.
The crash has gone away in beta 2. I am still getting funky behavior and trying to build a reduced test case.
I'm having similar problems and trying to find a reduced test case that i can enter as a bug. If you have one, I suggest you enter a bug.
Nurinder M: You stated "if this document was pushed on stack using navigationDocument.pushDocument(), your updates to DOM tree will get reflected in UI automatically." -- Why is it limited to only the documents pushed with navigationDocument.pushDocument()? What if we need the very first document/page, which is a menuItem, to update automatically? Right now, the first page (and any menuItem documents) are being presented with .getFeature("MenuBarDocument") and .setDocument(xml, ele). Are you saying that these documents don't process DOM updates automatically? And if so, what's the best workaround?
Have you submitted a bug for this?
background image should be specified on initial push, and can't be updated after that. Please file enhancement request with use case.
Thanks for the clarification on backgrounds, Nurinder. Does my post about removing overlay elements and not having those on screen redraw sound like a bug or expected behavior?
Are you specifying overlay on the lockup, and when you remove them lockups don't update rendering? If that is the case yes that would be a bug, please file bug report at https://bugreport.apple.com