-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating templates/snippets before the DOM is loaded #41
Comments
I think you are dealing with the incoming ajax content not loading before you make the call not the local dom not existing. Snippets and/or templates are loaded via AJAX and it is important to make sure the content has been loaded before calling the template or snippit function. Enfocus provides a convient function that works like an onload callback but for AJAX driven snippets and templates. (em/wait-for-load (render-page)) |
On the attaching to the live dom, unfortunately, this is unavoidable because DocumentFragment has very few features for selection and manipulation. Most of the CSS3 selectors would not work on a DocumentFragment, so we temporarily add it to the live dom so it can be transformed and then pull it out into a DocumentFragmnt and pass it back. |
I forgot to mention I am using :compiled templates so I think there is no ajax involved. I understand the DocumentFragment must be added to the DOM in order to be manipulated. When creating a template with the :compiled argument, it seems that DocumentFragment are added to the body property of the document element ( "(.-body (dom/getDocument))" ). This is an issue when trying to create templates before the DOM is loaded because the body property is not defined at that time. I have been wondering what would be your opinion about changing "(.-body (dom/getDocument))" to something like "(.-documentElement (dom/getDocument))", since the documentElement property seems to be defined even before the DOM is loaded. |
Can you post some code to repo or gist so i can try to reproduce the CK
|
Unfortunately, I am not able to append to the Document directly without causing errors. If you try to append directly to the document you get the following error: HIERARCHY_REQUEST_ERR: DOM Exception 3. It would be great if you could put together a repo with your code in it so I can experiment with possible solutions. |
I uploaded my code to a repo here https://github.com/Ewen0/test-enfocus.git It can be compared to https://github.com/Ewen0/test-enfocus-body.git which produces an error. |
ok, that makes perfect sense now. Sorry brain not working on the last attempt. I did some preliminary testing and all looks good. I want to do more testing but I would love a pull request for the change. |
Hello,
I am getting an error when I try to build templates or snippets before the DOM is loaded. This error is due to the document fragment under construction being attached to the "body" tag of the live DOM which does not exist at that time.
(see the function create-hidden-dom of core.cljs).
I wonder if it would be better (or not?) to attach the document fragment to the "html" tag of the live DOM instead of the "body" tag in order to fix this issue.
Also, what are the reasons for the document fragment being attached to the live DOM instead of being attached to a non-live node.
Thank you.
Ewen.
The text was updated successfully, but these errors were encountered: