yourcelf / olwidget

Javascript library to replace textareas that contain WKT data with editable OpenLayers maps, and a django app using it for django forms and admin.
Other
91 stars 44 forks source link

Javascript just before </body>? #38

Closed skyl closed 13 years ago

skyl commented 14 years ago

This is how I like to do it. Seems like a fairly difficult change the way things work right now with olwidget.js in and the dynamic bits just after the txtarea that the js modifies. What say you?

yourcelf commented 14 years ago

Yeah, word on the street is scripts just before body is slightly faster. The only part of olwidget's implementation that couldn't be shoved down next to the body closing tag is the textarea/div declaration. There's no particular reason why the script bits have to be part of {{ map }} or {{ form }}, but some thought should go into moving it to ensure it doesn't break other use cases.

If the scripts were placed into {{ map.media }} or {{ form.media }}, one of the following would have to happen:

Alternatively, a third/fourth part could be split out, e.g. {{ map.div }} / {{ map.script }}. It's less obvious how this would relate to the Django {{ form }} classes, though.

In the meantime, you could do this yourself by editing the map rendering template and removing the div/textarea part, and defining a specific DOM ID. You could then include the DOM element in the main template, and put {{ map.media }} and {{ map }} (which is just the script call now) down to just before .

yourcelf commented 13 years ago

I'm going to close this as "won't fix for now" -- I agree with the principle and desire, but there's an important order-of-operations difficulty in the templates to be overcome, and I can't think of any way to do this without imposing naming conventions on form elements. If you can think of a better way to do this please open a new issue.