First iteration of JS vanilla'ization

This commit is contained in:
Martin Mahner 2017-09-01 12:34:52 +02:00
parent 470b8dd2b3
commit 201f78e81b
5 changed files with 28 additions and 40 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -27,29 +27,5 @@
PAGE MISSING
{% endblock %}
</div>
{% block script_footer %}
<script src="{{ jquery_url }}"></script>
<script src="{% static "dpaste/clipboardjs.min.js" %}"></script>
<script>
jQuery(function($) {
new Clipboard('.clip-button');
$('.autofocus textarea:first').focus();
$('.superenter textarea').on('keydown', function(e){
var metaKey;
if (navigator.appVersion.indexOf("Win")!=-1) {
metaKey = e.ctrlKey;
} else {
metaKey = event.metaKey;
}
if (e.keyCode == 13 && metaKey) {
$(this).closest('form').submit();
return false;
}
});
});
</script>
{% endblock %}
</body>
</html>

View file

@ -87,7 +87,8 @@
{% block script_footer %}
{{ block.super }}
<script>
jQuery(function($) {
<!--
$('.snippet-reply-hidden').click(function(e) {
$(this).removeClass('snippet-reply-hidden');
});
@ -166,5 +167,6 @@ jQuery(function($) {
$('.code').toggleClass('wordwrap');
});
});
-->
</script>
{% endblock %}

View file

@ -1,6 +1,6 @@
{% load i18n %}
<form method="post" action="" class="form-horizontal">
<form method="post" action="" class="form-horizontal snippet-form">
{% csrf_token %}
{{ form.non_field_errors }}
<div style="display: none;">{{ form.title }}</div>
@ -38,3 +38,27 @@
<span class="shortcut">&#8984;+&#9166; {% trans "or" %} Ctrl+&#9166;</span>
</div>
</form>
{% block script_footer %}
<script>
var af = document.querySelector(".autofocus textarea");
if (af !== null)
af.focus();
var se = document.querySelector(".superenter textarea");
if (se !== null) {
se.onkeydown = function(e) {
var metaKey;
if (navigator.appVersion.indexOf("Win") !== -1) {
metaKey = e.ctrlKey;
} else {
metaKey = event.metaKey;
}
if (e.keyCode == 13 && metaKey) {
document.querySelector(".snippet-form").submit();
return false;
}
}
}
</script>
{% endblock %}