|
(function() { |
|
var commits = [], repo = document.location.href.match(/github\.com\/([^\/]+\/[^\/]+)\//)[1]; |
|
|
|
// Play for all commits |
|
$('.commit-group .commit-links') |
|
.append($('<a href="#" class="browse-button github-play-select">Play</a>')); |
|
|
|
// show next commit |
|
var nextCommit = function () { |
|
$('.site .container').load(commits.shift() + ' #.site .container', function () { |
|
$('span.sha').each(function () { |
|
var sha = $(this).html(); |
|
$(this).replaceWith($('<a class="sha" href="/' + repo + '/commit/'+ sha + '">' + sha + '</a>')); |
|
}); |
|
$('html, body').animate({scrollTop:0}, 'fast'); |
|
}); |
|
|
|
if (commits.length < 1) $('#next-commit').hide(); |
|
return false; |
|
} |
|
|
|
// When commit play-ed |
|
$('.site .container').on('click', '.github-play-select', function(ev) { |
|
$('#play-spinner').css({'left' : ev.pageX + 15, 'top' : ev.pageY + 15}).show(); |
|
|
|
var x, href = $(ev.target).closest('li.commit').find('a.gobutton')[0].href; |
|
if(!(x = href.match(/commit\/([0-9a-f]+)/))) return false; // something must have gone wrong |
|
var fromCommit = x[1]; //TODO: make diff from parent of this commit |
|
|
|
$.get('https://github.com/' + repo + '/compare/' + fromCommit.toString() +'...HEAD', function(compare) { |
|
$(compare).find('table.commits tr').each(function () { |
|
commits.push($(this).find('td:first a').attr('href')); |
|
}); |
|
|
|
var spinner = $('#play-spinner') |
|
.css({'position':'relative', 'left':'0', 'top':'0'}); |
|
|
|
// next commit link |
|
$('#next-commit').click(nextCommit).show() |
|
.prepend(spinner).click(); |
|
}); |
|
|
|
return false; |
|
}); |
|
|
|
// next commit link |
|
$('<a href="#" id="next-commit">Next commit</a>').css({ |
|
'right':'20px', 'bottom':'20px', 'position':'fixed', // position |
|
'font-size':'20px', 'font-weight':'bold', 'display':'none', 'z-index':'1000' // style |
|
}).appendTo('body'); |
|
|
|
// spinner |
|
$('<img id="play-spinner" />') |
|
.attr('src', GitHub.Ajax.spinner) |
|
.css({'position':'absolute', 'display':'none', 'z-index':'1000'}) |
|
.appendTo('body'); |
|
|
|
$('#play-spinner') |
|
.ajaxStart(function() { $(this).show(); }) |
|
.ajaxStop(function() { $(this).hide(); }); |
|
|
|
})() |
Very nice!