Skip to content

Commit 83df782

Browse files
committed
Adding/removing tabindex to links dynamically to prevent strange slide transitions
1 parent ea5fa8c commit 83df782

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

examples/basic.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ This will be in a separate paragraph.
2323
![markdown-logo](logo.gif)
2424
<img src="logo.gif" />
2525

26+
[Here's a link](http://google.com).
27+
2628
--
2729

2830
### A list of things
@@ -31,7 +33,7 @@ This will be in a separate paragraph.
3133
* Item B
3234
* Item gamma
3335

34-
No need for multiple templates!
36+
No need for multiple templates! [Another link](http://google.com).
3537

3638
--
3739

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cleaver",
33
"preferGlobal": true,
4-
"version": "0.4.1",
4+
"version": "0.4.2",
55
"author": "Jordan Scales <scalesjordan@gmail.com>",
66
"description": "30-second slideshows for hackers",
77
"keywords": [

resources/navigation.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function goBack() {
1313

1414
setCurrentProgress();
1515
updateURL();
16+
updateTabIndex();
1617
}
1718

1819
/**
@@ -30,6 +31,7 @@ function goForward() {
3031

3132
setCurrentProgress();
3233
updateURL();
34+
updateTabIndex();
3335
}
3436

3537
/**
@@ -99,11 +101,33 @@ function goToPage(page) {
99101
}
100102
}
101103

104+
/**
105+
* Removes tabindex property from all links on the current slide, sets
106+
* tabindex = -1 for all links on other slides. Prevents slides from appearing
107+
* out of control.
108+
*/
109+
function updateTabIndex() {
110+
var allLinks = document.querySelectorAll('.slide a');
111+
var currentPageLinks = document.querySelector('.slide').querySelectorAll('a');
112+
var i;
113+
114+
for (i = 0; i < allLinks.length; i++) {
115+
allLinks[i].setAttribute('tabindex', -1);
116+
}
117+
118+
for (i = 0; i < currentPageLinks.length; i++) {
119+
allLinks[i].removeAttribute('tabindex');
120+
}
121+
}
122+
102123
window.onload = function () {
103124

104125
// Give each slide a "page" data attribute.
105126
setPageNumbers();
106127

128+
// Update the tabindex to prevent weird slide transitioning
129+
updateTabIndex();
130+
107131
// If the location hash specifies a page number, go to it.
108132
var page = window.location.hash.slice(1);
109133
if (page) goToPage(page);

templates/author.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
<h1 class="name">{{name}}</h1>
33
{{#twitter}}
44
<h3 class="twitter">
5-
<a href="http://twitter.com/{{{twitter}}}" tabindex="-1">{{{twitter}}}</a>
5+
<a href="http://twitter.com/{{{twitter}}}">{{{twitter}}}</a>
66
</h3>
77
{{/twitter}}
88
{{#url}}
99
<h3 class="url">
10-
<a href="{{{url}}}" tabindex="-1">{{{url}}}</a>
10+
<a href="{{{url}}}">{{{url}}}</a>
1111
</h3>
1212
{{/url}}
1313
{{#email}}
1414
<h3 class="email">
15-
<a href="mailto:{{{email}}}" tabindex="-1">{{{email}}}</a>
15+
<a href="mailto:{{{email}}}">{{{email}}}</a>
1616
</h3>
1717
{{/email}}
1818
</div>

0 commit comments

Comments
 (0)