Autofocus the textfield for a new snippet.

This commit is contained in:
Martin Mahner 2013-03-22 19:40:31 +01:00
parent 9321195ff4
commit e9770293bb
5 changed files with 11 additions and 5 deletions

View file

@ -19,6 +19,11 @@ EXPIRE_DEFAULT = 3600 * 24 * 30
class SnippetForm(forms.ModelForm): class SnippetForm(forms.ModelForm):
content = forms.CharField(
label=_('Content'),
widget=forms.Textarea(attrs={'placeholder': _('Awesome code goes here...')}),
)
lexer = forms.ChoiceField( lexer = forms.ChoiceField(
label=_(u'Lexer'), label=_(u'Lexer'),
initial=LEXER_DEFAULT, initial=LEXER_DEFAULT,

View file

@ -44,6 +44,8 @@ $(document).ready(function(){
} }
}); });
}); });
$('.autofocus input:text, .autofocus textarea').first().focus();
}); });
</script> </script>
{% endblock %} {% endblock %}

View file

@ -5,7 +5,7 @@
{{ snippet_form.non_field_errors }} {{ snippet_form.non_field_errors }}
<div style="display: none;">{{ snippet_form.title }}</div> <div style="display: none;">{{ snippet_form.title }}</div>
<div class="control-group form-content"> <div class="control-group form-content {% if is_new %}autofocus{% endif %}">
{{ snippet_form.content }} {{ snippet_form.content }}
</div> </div>
@ -26,7 +26,7 @@
</div> </div>
</div> </div>
<div class="form-actions"> <div class="form-actions">
{% if follow_button %} {% if is_new %}
<div class="twitter-follow-button-container"> <div class="twitter-follow-button-container">
<a href="https://twitter.com/bartTC" class="twitter-follow-button" data-show-count="false" data-size="large" data-dnt="true">Follow @bartTC</a> <a href="https://twitter.com/bartTC" class="twitter-follow-button" data-show-count="false" data-size="large" data-dnt="true">Follow @bartTC</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

View file

@ -6,7 +6,5 @@
{% block dpaste_nav_new %}active{% endblock %} {% block dpaste_nav_new %}active{% endblock %}
{% block page %} {% block page %}
{% with 1 as follow_button %} {% include "dpaste/snippet_form.html" %}
{% include "dpaste/snippet_form.html" %}
{% endwith %}
{% endblock %} {% endblock %}

View file

@ -44,6 +44,7 @@ def snippet_new(request, template_name='dpaste/snippet_new.html'):
template_context = { template_context = {
'snippet_form': snippet_form, 'snippet_form': snippet_form,
'is_new': True,
} }
return render_to_response( return render_to_response(