mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 08:02:54 +11:00
100% vanilla JS now.
This commit is contained in:
parent
1167d6fcdb
commit
3aa06d30e0
5 changed files with 65 additions and 105 deletions
|
@ -137,12 +137,12 @@ h1, h2, h3, h4 {
|
|||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.snippet-reply-hidden {
|
||||
.snippet-reply[data-hidden=yes] {
|
||||
opacity: 0.3;
|
||||
}
|
||||
|
||||
.snippet-reply-hidden,
|
||||
.snippet-reply-hidden *{
|
||||
.snippet-reply[data-hidden=yes],
|
||||
.snippet-reply[data-hidden=yes] *{
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,5 +27,30 @@
|
|||
PAGE MISSING
|
||||
{% endblock %}
|
||||
</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>
|
||||
</html>
|
||||
|
|
|
@ -1 +1 @@
|
|||
<div class="code {{ snippet.lexer }}"><ol>{% for line in highlighted %}<li id="{{ forloop.counter }}">{{ line|safe|default:" " }}</li>{% endfor %}</ol></div>
|
||||
<div class="code {{ snippet.lexer }}"><ol>{% for line in highlighted %}<li id="l{{ forloop.counter }}">{{ line|safe|default:" " }}</li>{% endfor %}</ol></div>
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
<!-- ======================================================================
|
||||
Snippet Reply
|
||||
======================================================================= -->
|
||||
<div class="snippet-reply snippet-reply-hidden">
|
||||
<div class="snippet-reply" data-hidden="yes">
|
||||
<h3>{% trans "Reply to this snippet" %} →</h3>
|
||||
{% include "dpaste/snippet_form.html" %}
|
||||
</div>
|
||||
|
@ -87,86 +87,45 @@
|
|||
{% block script_footer %}
|
||||
{{ block.super }}
|
||||
<script>
|
||||
var reply = document.querySelector('.snippet-reply');
|
||||
reply.onclick = function(e) {
|
||||
this.dataset.hidden = "no";
|
||||
};
|
||||
|
||||
<!--
|
||||
$('.snippet-reply-hidden').click(function(e) {
|
||||
$(this).removeClass('snippet-reply-hidden');
|
||||
});
|
||||
|
||||
// Line Highlighting
|
||||
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') {
|
||||
hashlist = curLine.substring(2).split(',');
|
||||
window.console.log(hashlist);
|
||||
if (hashlist.length > 0 && hashlist[0] !== '') {
|
||||
$.each(hashlist, function(index, elem){
|
||||
$('.code li#' + elem).addClass('marked');
|
||||
hashlist.forEach(function(el) {
|
||||
var line = document.getElementById('l'+el)
|
||||
if (line)
|
||||
line.classList.add('marked');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$('.code li').click(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){
|
||||
document.getElementById('toggleWordwrap').onclick = function(e) {
|
||||
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>
|
||||
{% endblock %}
|
||||
|
|
|
@ -38,27 +38,3 @@
|
|||
<span class="shortcut">⌘+⏎ {% trans "or" %} Ctrl+⏎</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 %}
|
||||
|
|
Loading…
Reference in a new issue