Reputation: 3046
I have a forum, and on every persons post theres a button that allows a moderator to mute someone after reviewing the post/entering hours to mute for in a window using simplemodal. In the code that shows the window, I have long code like
var output = "<div id='msginfo'>...</div>";
and so on. I would like my code to be able to be 'minified' when I'm done with it and a lot of packers/shrinkers crap out when it comes to the html (usually the < and "> stuff.).
How do other web applications manage no HTML in javascript files? are the divs that will be shown just hidden until they're needed or what?
Upvotes: 2
Views: 313
Reputation: 154685
At work, I use ICanHaz for this. It lets you generate DOM elements on the fly from HTML templates (which you can include in the <head>
of your HTML file) without having to inline any HTML whatsoever in your Javascript where it's ugly and harder to read.
For a purpose like yours - displaying a modal with a fixed layout - this is probably cleaner than having the modal included and hidden on the page the moment it loads, although there's probably nothing horribly wrong with the latter solution either in this case.
Incidentally, ICanHaz is also a nice solution when you want to asynchronously add content to the page after it has loaded, which may be relevant in a forum context (for e.g. loading new posts without a new page load).
Upvotes: 4
Reputation: 5961
I usually put on divs: display:none
property for hide it then change that with Javascript when needed, so they will be shown.
On the other hand you can make an Ajax call and get the html you need and display appending it to an element.
Upvotes: 1