Skip to content
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

Closed
EwenG opened this issue Jan 24, 2013 · 7 comments
Closed

Creating templates/snippets before the DOM is loaded #41

EwenG opened this issue Jan 24, 2013 · 7 comments

Comments

@EwenG
Copy link
Contributor

EwenG commented Jan 24, 2013

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.

@ckirkendall
Copy link
Owner

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)) 

@ckirkendall
Copy link
Owner

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.

@EwenG
Copy link
Contributor Author

EwenG commented Jan 27, 2013

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.

@ckirkendall
Copy link
Owner

Can you post some code to repo or gist so i can try to reproduce the
issue. Also can i have your OS and Browser versions. I can try it out
your idea out this evening if you can get me the code.

CK
On Jan 27, 2013 1:47 PM, "Ewen0" notifications@github.com wrote:

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.


Reply to this email directly or view it on GitHubhttps://github.com//issues/41#issuecomment-12758963.

@ckirkendall
Copy link
Owner

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.

@EwenG
Copy link
Contributor Author

EwenG commented Jan 31, 2013

I uploaded my code to a repo here https://github.com/Ewen0/test-enfocus.git
It can be run with: lein ring server
It simply creates a template before the dom is loaded. I could run it on firefox 18.0.1, chromium 24 and opera 12.

It can be compared to https://github.com/Ewen0/test-enfocus-body.git which produces an error.
The only difference is line 138 in core.cljs.

@ckirkendall
Copy link
Owner

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.

@EwenG EwenG closed this as completed Feb 1, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants