- Author:
- jcushman
- Posted:
- January 7, 2010
- Language:
- JavaScript
- Version:
- Not specified
- Score:
- 2 (after 2 ratings)
This snippet is helpful if you do a lot of editing on a single large admin form (for example, in a rich text field), and want to frequently save your progress. If you press control-S, or command-S on a Mac, the admin change form will save and reload, and the page will scroll back down to where you last were.
This snippet relies on jquery, jquery.cookie, and the shortcut.js keyboard library (which doesn't use jquery, but seemed more robust than the jquery keyboard plugins I saw). It uses a temporary cookie to remember where the page was scrolled to, to avoid having to override the admin behavior.
Note: don't put this in templates/admin/change_form.html -- the circular import causes a Django crash.
Edit: Had forgotten to include jquery.cookie, which I was already including elsewhere.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | In a change_form template, such as templates/admin/myapp/change_form.html:
{% extends "admin/change_form.html" %}
{% block extrahead %}
{{ block.super }}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script src="{{MEDIA_URL}}js/jquery.cookie.js" type="text/javascript"></script>
<script src="{{MEDIA_URL}}js/shortcut.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
setTimeout(function(){
$(window).scrollTop($.cookie('django_admin_scroll'));
$.cookie('django_admin_scroll', 0);
}, 100);
});
function save_and_continue(){
$.cookie('django_admin_scroll',$(window).scrollTop());
$('input[name="_continue"]').click()
}
shortcut.add("Meta+S", save_and_continue);
shortcut.add("Ctrl+S", save_and_continue);
</script>
{% endblock %}
|
More like this
- Django Collapsed Stacked Inlines by applecat 1 year, 7 months ago
- Django Collapsed Stacked Inlines by mkarajohn 3 years, 8 months ago
- Dynamically adding forms to a formset. OOP version. by halfnibble 9 years, 4 months ago
- Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 11 years, 5 months ago
- Django admin inline ordering - javascript only implementation by ojhilt 11 years, 10 months ago
Comments
Please login first before commenting.