From 83df7827e749e9696a82ea81d5463ca8f3648e3e Mon Sep 17 00:00:00 2001 From: Jordan Scales Date: Mon, 4 Nov 2013 17:13:11 -0500 Subject: [PATCH] Adding/removing tabindex to links dynamically to prevent strange slide transitions --- examples/basic.md | 4 +++- package.json | 2 +- resources/navigation.js | 24 ++++++++++++++++++++++++ templates/author.mustache | 6 +++--- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/examples/basic.md b/examples/basic.md index 1448fbd..04df63e 100644 --- a/examples/basic.md +++ b/examples/basic.md @@ -23,6 +23,8 @@ This will be in a separate paragraph. ![markdown-logo](logo.gif) +[Here's a link](http://google.com). + -- ### A list of things @@ -31,7 +33,7 @@ This will be in a separate paragraph. * Item B * Item gamma -No need for multiple templates! +No need for multiple templates! [Another link](http://google.com). -- diff --git a/package.json b/package.json index d4f0c19..0489ece 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cleaver", "preferGlobal": true, - "version": "0.4.1", + "version": "0.4.2", "author": "Jordan Scales ", "description": "30-second slideshows for hackers", "keywords": [ diff --git a/resources/navigation.js b/resources/navigation.js index abfe2df..f0b529b 100644 --- a/resources/navigation.js +++ b/resources/navigation.js @@ -13,6 +13,7 @@ function goBack() { setCurrentProgress(); updateURL(); + updateTabIndex(); } /** @@ -30,6 +31,7 @@ function goForward() { setCurrentProgress(); updateURL(); + updateTabIndex(); } /** @@ -99,11 +101,33 @@ function goToPage(page) { } } +/** + * Removes tabindex property from all links on the current slide, sets + * tabindex = -1 for all links on other slides. Prevents slides from appearing + * out of control. + */ +function updateTabIndex() { + var allLinks = document.querySelectorAll('.slide a'); + var currentPageLinks = document.querySelector('.slide').querySelectorAll('a'); + var i; + + for (i = 0; i < allLinks.length; i++) { + allLinks[i].setAttribute('tabindex', -1); + } + + for (i = 0; i < currentPageLinks.length; i++) { + allLinks[i].removeAttribute('tabindex'); + } +} + window.onload = function () { // Give each slide a "page" data attribute. setPageNumbers(); + // Update the tabindex to prevent weird slide transitioning + updateTabIndex(); + // If the location hash specifies a page number, go to it. var page = window.location.hash.slice(1); if (page) goToPage(page); diff --git a/templates/author.mustache b/templates/author.mustache index 2e7d1c6..b281310 100644 --- a/templates/author.mustache +++ b/templates/author.mustache @@ -2,17 +2,17 @@

{{name}}

{{#twitter}} {{/twitter}} {{#url}}

- {{{url}}} + {{{url}}}

{{/url}} {{#email}} {{/email}}