Ability to link and open to diffs directly. Fixes issue #2.

This commit is contained in:
Martin Mahner 2013-03-20 13:41:31 +01:00
parent e14192d2d1
commit 1f863b345f
2 changed files with 26 additions and 8 deletions

View file

@ -155,8 +155,8 @@ ol.linenums li.marked {
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
Pygments Pygments
---------------------------------------------------------------------------- */ ---------------------------------------------------------------------------- */
pre .gd { background-color: #d68c83; display: block; } pre .gd { background-color: rgba(226, 12, 19, .5); display: block; }
pre .gi { background-color: #a7cb7d; display: block; } pre .gi { background-color: rgba(23, 189, 10, .5); display: block; }
pre .hll { background-color: #49483e } pre .hll { background-color: #49483e }

View file

@ -83,26 +83,44 @@ $(document).ready(function(){
$(this).removeClass('snippet-reply-hidden'); $(this).removeClass('snippet-reply-hidden');
}); });
/**
* Diff Ajax Call
*/
$('.snippet-diff-trigger').click(function(e){ $('.snippet-diff-trigger').click(function(e){
e.preventDefault(); e.preventDefault();
$('#snippet-diff').slideDown('fast'); $('#snippet-diff').slideDown('fast');
$('#snippet-diff form').submit(); $('#snippet-diff form').submit();
}); });
/**
* Diff Ajax Call
*/
$("form#diffform").submit(function() { $("form#diffform").submit(function() {
var a = $("input[name=a]:checked").val(),
b = $("input[name=b]:checked").val(),
hash = 'D'+a+','+b;
$.get("{% url "snippet_diff" %}", { $.get("{% url "snippet_diff" %}", {
a: $("input[name=a]:checked").val(), a: a,
b: $("input[name=b]:checked").val() b: b
}, function(data){ }, function(data){
$('#diff').html(data).slideDown('fast'); $('#diff').html(data).slideDown('fast');
}); });
window.location.hash = hash;
return false; return false;
}); });
var curLine = document.location.hash,
hashlist;
if(curLine.substring(0,2) == '#D'){
hashlist = curLine.substring(2).split(',');
if (hashlist.length == 2) {
console.log(hashlist);
$('form#diffform input[name=a][value='+hashlist[0]+']').attr('checked', true);
$('form#diffform input[name=b][value='+hashlist[1]+']').attr('checked', true);
$('#snippet-diff').slideDown('fast');
$('#snippet-diff form').submit();
}
}
/** /**
* Line Highlighting * Line Highlighting
*/ */