The branch selector now sends you to the correct url
[catagits/Gitalist.git] / root / static / js / site.js
CommitLineData
feb6e881 1function findPos(obj) {
2 var curleft = curtop = 0;
3 if (obj.offsetParent) {
7546a03c 4 do {
5 curleft += obj.offsetLeft;
6 curtop += obj.offsetTop;
fe89796b 7 }
7546a03c 8 while (obj = obj.offsetParent);
9 return [curleft,curtop];
feb6e881 10 }
11}
12
13function setNavClass(el){
14 var link_el = document.getElementById("actions_nav_link");
15 var offsetAry = findPos(link_el);
16 // set position of list
17 el.style.left = offsetAry[0]+"px";
18 el.style.top = offsetAry[1]+30 +"px";
19 el.className+=" actions_nav_list_over";
20}
21
22// handles hover sub menus in IE
23function startList() {
24 if(!document.getElementById("actions_nav_link"))
25 return;
26 var navList = document.getElementById("actions_nav_list");
27 var navLink = document.getElementById("actions_nav_link");
28 // assign event handlers to each element
29 navLink.onmouseover=function() {
30 setNavClass(navList);
31 };
32 navList.onmouseover=function() {
33 setNavClass(navList);
34 };
35 navList.onmouseout=function() {
36 navList.className=navList.className.replace(" actions_nav_list_over", "");
37 };
38 navLink.onmouseout=function() {
39 navList.className=navList.className.replace(" actions_nav_list_over", "");
40 };
41}
42
43function uriFor(action, sha1) {
44 return jQuery('#' + action + '-uri').text().replace(/\bHEAD\b/, sha1);
45}
46
47function switchBranch() {
535bc6e2 48 var branch = jQuery('#branch-list').val(),
49 action = branch != '...' ? 'current' : 'heads';
8d2e9264 50 document.location.href = uriFor(action, encodeURIComponent(branch).replace('/', '%2F'));
feb6e881 51}
52
53function compareDiffs(){
54 var path = jQuery('#compare-path').text(),
55 baseSha1 = jQuery('#compare-form input[name=sha1_a]:checked').val(),
56 compSha1 = jQuery('#compare-form input[name=sha1_b]:checked').val(),
57 diffUri = uriFor('diff', baseSha1);
d5fd80f5 58 document.location.href = diffUri + '/' + compSha1 + (path ? '/' + encodeURIComponent(path) : '');
feb6e881 59 return false;
60}
61
7546a03c 62function _loadCommitInfo(cells) {
63 var cell = jQuery(cells.shift());
64 var filename = cell.find('.js-data').text();
65 jQuery.getJSON(uriFor('file_commit_info') + '/' + filename, {}, function(commitInfo) {
66 cell.empty();
67 cell.html('<a href="'+uriFor('commit', commitInfo.sha1)+'">'+commitInfo.comment+'</a> '+commitInfo.age);
68 if(cells.length > 0)
69 _loadCommitInfo(cells);
feb6e881 70 });
71}
72
7546a03c 73function loadCommitInfo() {
48823ae8 74 var cells = jQuery('#commit-tree .message').get();
75 if(cells.length > 0)
76 _loadCommitInfo( cells );
7546a03c 77}
78
feb6e881 79jQuery(function() {
80 // Provide sub-nav dropdowns (I think).
81 startList();
82
83 // JS up any Compare links
84 jQuery('a.compare-link').click(compareDiffs);
85 // Change the URL when a branch is selected
86 jQuery('#branch-list').change(switchBranch);
87 // Wait for image requests to come back first
88 jQuery(window).load(loadCommitInfo);
89});