REVIEW ONLY: Basic DOM manipulation via RemoteAgent#4237
Conversation
…teAgent.remoteElement(data-brackets-id).
…ch-dom-edit-mapping
|
Just one general thought...I think it might be better if we used ordinary DOM APIs instead of jQuery, to avoid problems with injecting incompatible versions of jQuery, etc. Have you thought about whether that would be significantly harder? For the kinds of things we're trying to do (individual node addition/deletion), it seems like it might not be that hard to just use ordinary DOM APIs. (I'm not sure if there's an easy DOM API to search for a given data attribute value, but that also doesn't seem hard to roll our own.) |
|
You can use |
|
Yep, @gruehle is right that @njx to avoid jQuery collisions I'm using http://api.jquery.com/jQuery.noConflict/. The docs don't recommend loading multiple versions of jQuery, but so far it works as advertised. Would using a custom jQuery build that only pulls in the DOM manipulation APIs that we need be a better alternative? I also wanted to avoid reinventing the wheel for parsing an So far, this solution assumes that elements are the only nodes that have IDs. In the thread late last Friday we started talking about giving IDs to non element nodes like text and comments. Guess I need to think about that more. |
|
I think @dangoor was right that we don't actually have to worry about it for text and comments, since those nodes don't have behavior that we need to worry about clobbering (i.e., it's fine for us to completely replace a text node instead of preserving it and changing its text). |
|
Closing. Merged into https://github.com/adobe/brackets/tree/ResearchLiveHTML branch |
Injects jQuery via RemoteAgent. Exposes basic DOM manipulation via
RemoteAgent.remoteElement(data-brackets-id). I used jQuery instead of the Inspector DOM APIs (https://developers.google.com/chrome-developer-tools/docs/protocol/tot/dom) for a few reasons:$("[data-brackets-id=n]")to modify DOM in-browser is easier than maintaining our own DOM tree (seeDOMAgentandDOMNodemodules), calling the DOM API, resolving theRemoteObject, and modifying theRemoteObjectand requires less async calls :)Use
HTMLInstrumentation._getTagIDAtDocumentPos(editor, cursor)to get thedata-brackets-idfor the given cursor position.The jQuery methods currently exposed on a
RemoteElementare the following: attr, removeAttr, before, after, append, prepend, text, detach (in case we want try getting undo to work re-insert a node), remove and finally html in case we want to blow up the entire content of an element for difficult use cases like mixed content.