Skip to content

Commit d7c53af

Browse files
committed
Allow keyboard navigation of the log in the demo.
Make the log entries specially focusable (i.e. tabindex=0) and accept enter key to activate in addition to click. Makes it easier to activate one commit after another.
1 parent c9571f8 commit d7c53af

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

demos/repo-viewer/repo-viewer.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ RepoViewer = {
3333
},
3434

3535
attachCommitClickEvents: function() {
36-
$(".commit").click(function(e) {
36+
function activated(e) {
3737
e.preventDefault()
3838
var id = $(e.target).attr("id")
3939
if (id.split("-")[0] == "commit") {
@@ -47,7 +47,10 @@ RepoViewer = {
4747
RepoViewer.highlightCommit(sha)
4848
RepoViewer.clearFileView()
4949
}
50-
})
50+
}
51+
$(".commit").click(activated).keydown(function(e) {
52+
if (13 === e.keyCode) activated(e);
53+
});
5154
},
5255

5356
displayCommitDiffInfo: function(commit) {
@@ -96,10 +99,11 @@ RepoViewer = {
9699
},
97100

98101
attachMoreCommitsEvents: function() {
99-
$(".more-commits").click(function(e) {
102+
function activated(e) {
100103
e.preventDefault()
101-
$(e.target).parent().parent().parent().remove()
102-
var id = $(e.target).parent().attr("id")
104+
var id = $(e.target).closest('[id]').attr("id");
105+
$(e.target).closest('tr').prev('tr').find('[tabindex]').focus()
106+
$(e.target).closest('tr').remove();
103107
if (id.split("-")[0] == "more") {
104108
var sha = id.split("-")[1]
105109
RepoViewer.repo.getObject(sha, function(err, commit) {
@@ -108,13 +112,16 @@ RepoViewer = {
108112
})
109113
})
110114
}
111-
})
115+
}
116+
$(".more-commits").click(activated).keydown(function(e) {
117+
if (13 === e.keyCode) activated(e);
118+
});
112119
},
113120

114121
displayCommit: function(commit) {
115122
if ($("#commit-" + commit.sha).length == 0) {
116123
var row = "<tr>"
117-
row += "<td class=\"commit\" id=\"commit-" + commit.sha + "\">" + commit.message.split("\n")[0] + "</td>"
124+
row += "<td class=\"commit\" id=\"commit-" + commit.sha + "\" tabindex=0>" + commit.message.split("\n")[0] + "</td>"
118125
row += "<td>" + commit.author.name + "</td>"
119126

120127
row += "<td>" + commit.author.date.toUTCString() + "</td>"
@@ -127,7 +134,7 @@ RepoViewer = {
127134
this.displayCommit(commit)
128135
if (max == 0) {
129136
this.attachCommitClickEvents()
130-
var row = "<tr><td><a class='more-commits' id='more-" + commit.sha + "'><em>More...</em></a></td></tr>"
137+
var row = "<tr><td><a class='more-commits' id='more-" + commit.sha + "' tabindex=0><em>More...</em></a></td></tr>"
131138
$("#commits table").append(row)
132139
this.attachMoreCommitsEvents()
133140
if (callback) { callback() }

0 commit comments

Comments
 (0)