Make side by side commitdiff TOC sticky
[gitphp.git] / js / commitdiff.js
blob:a/js/commitdiff.js -> blob:b/js/commitdiff.js
--- a/js/commitdiff.js
+++ b/js/commitdiff.js
@@ -1,40 +1,21 @@
 /*
- * GitPHP javascript commitdiff
+ * GitPHP Javascript commitdiff loader
  * 
- * Javascript enhancements to make side-by-side
- * commitdiff more usable
- *
+ * Initializes script modules used on the commitdiff page
+ * 
  * @author Christopher Han <xiphux@gmail.com>
  * @copyright Copyright (c) 2011 Christopher Han
  * @package GitPHP
+ * @subpackage Javascript
  */
 
-var TOCYloc = null;
-var TOCposition = null;
-var TOCtop = null;
-
-function initSBSCommitDiff() {
-	var sbsTOC = $('div.commitDiffSBS div.SBSTOC');
-	if (sbsTOC.size() < 1) {
-		return;
-	}
-
-	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);
+define(["jquery", "modules/sidebysidecommitdiff", "common"], function($, sbsDiff) {
+	$(function(){
+		var toc = $('div.commitDiffSBS div.SBSTOC');
+		var content = $('div.SBSContent');
+		if ((toc.size() > 0) && (content.size() > 0)) {
+			sbsDiff.init(toc, content);
 		}
 	});
-};
-
-$(document).ready(function() {
-	initSBSCommitDiff();
 });
 

comments