100% vanilla JS now.

This commit is contained in:
Martin Mahner 2017-09-01 18:57:06 +02:00
parent 1167d6fcdb
commit 3aa06d30e0
5 changed files with 65 additions and 105 deletions

View file

@ -137,12 +137,12 @@ h1, h2, h3, h4 {
margin-top: 30px; margin-top: 30px;
} }
.snippet-reply-hidden { .snippet-reply[data-hidden=yes] {
opacity: 0.3; opacity: 0.3;
} }
.snippet-reply-hidden, .snippet-reply[data-hidden=yes],
.snippet-reply-hidden *{ .snippet-reply[data-hidden=yes] *{
cursor: pointer; cursor: pointer;
} }

View file

@ -27,5 +27,30 @@
PAGE MISSING PAGE MISSING
{% endblock %} {% endblock %}
</div> </div>
{% 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 %}
</body> </body>
</html> </html>

View file

@ -1 +1 @@
<div class="code {{ snippet.lexer }}"><ol>{% for line in highlighted %}<li id="{{ forloop.counter }}">{{ line|safe|default:"&nbsp;" }}</li>{% endfor %}</ol></div> <div class="code {{ snippet.lexer }}"><ol>{% for line in highlighted %}<li id="l{{ forloop.counter }}">{{ line|safe|default:"&nbsp;" }}</li>{% endfor %}</ol></div>

View file

@ -77,7 +77,7 @@
<!-- ====================================================================== <!-- ======================================================================
Snippet Reply Snippet Reply
======================================================================= --> ======================================================================= -->
<div class="snippet-reply snippet-reply-hidden"> <div class="snippet-reply" data-hidden="yes">
<h3>{% trans "Reply to this snippet" %} &rarr;</h3> <h3>{% trans "Reply to this snippet" %} &rarr;</h3>
{% include "dpaste/snippet_form.html" %} {% include "dpaste/snippet_form.html" %}
</div> </div>
@ -87,86 +87,45 @@
{% block script_footer %} {% block script_footer %}
{{ block.super }} {{ block.super }}
<script> <script>
var reply = document.querySelector('.snippet-reply');
reply.onclick = function(e) {
this.dataset.hidden = "no";
};
<!-- // Line Highlighting
$('.snippet-reply-hidden').click(function(e) {
$(this).removeClass('snippet-reply-hidden');
});
var curLine = document.location.hash; var curLine = document.location.hash;
{% if snippet.parent %}
/* ------------------------------------------------------------------------
Diff Ajax Call
------------------------------------------------------------------------ */
function fetchDiff() {
var a = {{ snippet.parent.pk }},
b = {{ snippet.pk }};
window.location.hash = 'D' + a + ',' + b;
// Cancel previous request if it is still pending
if (diffReq) {
diffReq.abort();
}
diffReq = $.get("{% url "snippet_diff" %}", {
a: a,
b: b
}).done(function(data) {
$('#diff').html(data).slideDown('fast');
}).complete(function() {
diffReq = null;
});
}
var diffReq;
$('.snippet-diff-trigger').click(function(e) {
e.preventDefault();
fetchDiff();
$('#snippet-diff').slideDown('fast');
});
if (curLine.substring(0, 2) === '#D') {
fetchDiff();
$('#snippet-diff').slideDown('fast');
}
{% endif %}
/* ------------------------------------------------------------------------
Line Highlighting
------------------------------------------------------------------------ */
if (curLine.substring(0, 2) === '#L') { if (curLine.substring(0, 2) === '#L') {
hashlist = curLine.substring(2).split(','); hashlist = curLine.substring(2).split(',');
window.console.log(hashlist);
if (hashlist.length > 0 && hashlist[0] !== '') { if (hashlist.length > 0 && hashlist[0] !== '') {
$.each(hashlist, function(index, elem){ hashlist.forEach(function(el) {
$('.code li#' + elem).addClass('marked'); var line = document.getElementById('l'+el)
if (line)
line.classList.add('marked');
}); });
} }
} }
$('.code li').click(function(e) { document.getElementById('toggleWordwrap').onclick = function(e) {
var line = $(this),
hash = 'L';
line.toggleClass('marked');
$('.code li.marked').each(function (index, elem) {
if (hash !== 'L') hash += ',';
hash += $(elem).attr('id');
});
window.location.hash = hash;
});
/* ------------------------------------------------------------------------
Wordwrap
------------------------------------------------------------------------ */
$('#toggleWordwrap').click(function(e){
e.preventDefault(); e.preventDefault();
$('.code').toggleClass('wordwrap'); document.querySelector('.code').classList.toggle('wordwrap');
}
var lines = document.querySelectorAll('.code li');
lines.forEach(function(el){
el.onclick = function(e) {
el.classList.toggle('marked');
var hash = 'L';
var marked = document.querySelectorAll('.code li.marked');
marked.forEach(function(line){
if (hash !== 'L')
hash += ',';
hash += line.getAttribute('id').substring(1);
}); });
window.location.hash = hash;
}
}); });
-->
</script> </script>
{% endblock %} {% endblock %}

View file

@ -38,27 +38,3 @@
<span class="shortcut">&#8984;+&#9166; {% trans "or" %} Ctrl+&#9166;</span> <span class="shortcut">&#8984;+&#9166; {% trans "or" %} Ctrl+&#9166;</span>
</div> </div>
</form> </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 %}