Turn side by side diff into a module
[gitphp.git] / js / commitdiff.js
blob:a/js/commitdiff.js -> blob:b/js/commitdiff.js
/* /*
* GitPHP javascript commitdiff * GitPHP Javascript commitdiff loader
* *
* Javascript enhancements to make side-by-side * Initializes script modules used on the commitdiff page
* commitdiff more usable *
*  
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2011 Christopher Han * @copyright Copyright (c) 2011 Christopher Han
* @package GitPHP * @package GitPHP
  * @subpackage Javascript
*/ */
   
var TOCYloc = null; define(["jquery"], function($) {
var TOCposition = null; $(function(){
var TOCtop = null; var toc = $('div.commitDiffSBS div.SBSTOC');
  var content = $('div.SBSContent');
function initSBSCommitDiff() { if ((toc.size() > 0) && (content.size() > 0)) {
var sbsTOC = $('div.commitDiffSBS div.SBSTOC'); require(["jquery", "modules/sidebysidecommitdiff"],
if (sbsTOC.size() < 1) { function($, sbsDiff) {
return; $(function() {
} sbsDiff.init(toc, content);
  });
TOCYloc = sbsTOC.position().top; }
TOCposition = sbsTOC.css('position'); );
TOCtop = sbsTOC.css('top');  
$(window).scroll(function() {  
var windowYloc = $(document).scrollTop();  
if (windowYloc > TOCYloc) {  
sbsTOC.css('position', 'fixed');  
sbsTOC.css('top', '0px');  
} else {  
sbsTOC.css('position', TOCposition);  
sbsTOC.css('top', TOCtop);  
} }
}); });
   
$('a.SBSTOCItem').click(function() {  
var clickedItem = $(this).get(0);  
$('a.SBSTOCItem').each(function(index, value) {  
if (clickedItem == value) {  
$(this).parent().addClass('activeItem');  
} else {  
$(this).parent().removeClass('activeItem');  
}  
});  
var clickedId = $(this).attr('href').substring(1);  
$('div.diffBlob').each(function() {  
if ($(this).attr('id') == clickedId) {  
$(this).slideDown('fast');  
} else {  
$(this).slideUp('fast');  
}  
});  
$('a.showAll').show();  
if ($(document).scrollTop() > $('div.SBSContent').offset().top) {  
$('html, body').animate({  
scrollTop: $('div.SBSContent').offset().top  
}, 200);  
}  
return false;  
});  
$('a.showAll').click(function() {  
$('a.SBSTOCItem').parent().removeClass('activeItem');  
$('div.diffBlob').slideDown('fast');  
$(this).hide();  
if ($(document).scrollTop() > $('div.SBSContent').offset().top) {  
$('html, body').animate({  
scrollTop: $('div.SBSContent').offset().top  
}, 200);  
}  
return false;  
});  
};  
   
$(document).ready(function() {  
initSBSCommitDiff();  
}); });
   
comments