The branch selector now sends you to the correct url
[catagits/Gitalist.git] / root / static / js / site.js
index 7f9265b..5af7d11 100755 (executable)
@@ -1,12 +1,12 @@
 function findPos(obj) {
        var curleft = curtop = 0;
        if (obj.offsetParent) {
-       do {
-               curleft += obj.offsetLeft;
-               curtop += obj.offsetTop;
-       } 
-       while (obj = obj.offsetParent);
-       return [curleft,curtop];
+         do {
+                 curleft += obj.offsetLeft;
+                 curtop += obj.offsetTop;
+         }
+         while (obj = obj.offsetParent);
+         return [curleft,curtop];
        }
 }
 
@@ -45,8 +45,9 @@ function uriFor(action, sha1) {
 }
 
 function switchBranch() {
-    var branch = jQuery('#branch-list').val();
-    document.location.href = uriFor('current', branch);
+    var branch = jQuery('#branch-list').val(),
+        action = branch != '...' ? 'current' : 'heads';
+    document.location.href = uriFor(action, encodeURIComponent(branch).replace('/', '%2F'));
 }
 
 function compareDiffs(){
@@ -58,17 +59,23 @@ function compareDiffs(){
     return false;
 }
 
-function loadCommitInfo() {
-  jQuery('#commit-tree .message').each(function() {
-    var cell     = jQuery(this);
-    var filename = cell.find('.js-data').text();
-    jQuery.getJSON(uriFor('file_commit_info') + '/' + filename, {}, function(commitInfo) {
-      cell.empty();
-      cell.html('<a href="'+uriFor('commit', commitInfo.sha1)+'">'+commitInfo.comment+'</a> '+commitInfo.age);
-    });
+function _loadCommitInfo(cells) {
+  var cell     = jQuery(cells.shift());
+  var filename = cell.find('.js-data').text();
+  jQuery.getJSON(uriFor('file_commit_info') + '/' + filename, {}, function(commitInfo) {
+    cell.empty();
+    cell.html('<a href="'+uriFor('commit', commitInfo.sha1)+'">'+commitInfo.comment+'</a> '+commitInfo.age);
+    if(cells.length > 0)
+      _loadCommitInfo(cells);
   });
 }
 
+function loadCommitInfo() {
+  var cells = jQuery('#commit-tree .message').get();
+  if(cells.length > 0)
+    _loadCommitInfo( cells );
+}
+
 jQuery(function() {
     // Provide sub-nav dropdowns (I think).
     startList();