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

let's tame jQuery imports #1592

Merged
merged 4 commits into from Jan 17, 2013
Merged

Conversation

evildmp
Copy link
Contributor

@evildmp evildmp commented Jan 16, 2013

These two tiny changes have saved me from a world of pain and misery. I actually cried because of the problems that this pull request addresses.

The changes do two things:

PlaceholderAdmin(ModelAdmin).Media

Summary: stop importing jquery.js.min in PlaceholderAdmin(ModelAdmin).Media.

Django's own ModelAdmin already calls in jQuery; so we shouldn't try to import the same thing. (I say 'try' because actually we don't even do that correctly - see the second paragraph at #1584.)

Importing jquery.js.min breaks attempts to make one's own admin/base_site.html provide a newer jQuery where it's needed.

cms/templates/admin/cms/page/plugin_change_form.html

Summary: create a {% block jquery %} around <script type="text/javascript" src="{% admin_static_url %}js/jquery.min.js"></script> in cms/templates/admin/cms/page/plugin_change_form.html.

A similar issue. The plugin_change_form.html extends admin/base_site.html, and loads jQuery. Now suppose your plugin needs a newer jQuery - there is no way to make that work without removing the jQuery here.

By putting it in a {% block jquery %}, it's now possible for your plugin's form to point at a template that extends plugin_change_form.html and overrides that block with the jQuery you want. Or, if your own admin/base_site.html already imports the jQuery you need, a simple {% block jquery %}{% endblock %} will prevent the undesired one from being loaded.

Breaks no tests, though I'm not sure how to test for this exactly. Works in practice as described above, on both a PlaceholderAdmin-based admin, and on a plugin.

Saved me from tears.

@FinalAngel
Copy link
Member

looks good to me!

@evildmp
Copy link
Contributor Author

evildmp commented Jan 16, 2013

OK, don't merge this just yet, I'll add something for the documentation.

@FinalAngel
Copy link
Member

docs also look fine to me :)

evildmp added a commit that referenced this pull request Jan 17, 2013
No more tears! Let's tame jQuery imports.
@evildmp evildmp merged commit e1bd3ee into django-cms:develop Jan 17, 2013
@evildmp evildmp deleted the save-me-from-jquery-hell branch July 10, 2014 07:38
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

Successfully merging this pull request may close these issues.

None yet

2 participants