From 12fc4747b58eeeab59b3e904ec5c6e104ad348e7 Mon Sep 17 00:00:00 2001 From: Oleg Roschupkin Date: Mon, 1 Aug 2011 21:06:35 +0900 Subject: [PATCH] Update onclick slide check to be more flexible. --- scripts/script.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/scripts/script.js b/scripts/script.js index e8a3b85..56b418b 100755 --- a/scripts/script.js +++ b/scripts/script.js @@ -80,18 +80,29 @@ updateProgress(slide_number); } } + + function getContainingSlideId(el) { + var node = el; + while ('BODY' !== node.nodeName) { + if (-1 !== node.className.indexOf('slide')) { + return node.id; + } else { + node = node.parentNode; + } + } + + return ''; + } function dispatchSingleSlideMode(e) { - if ( - 'SECTION' === e.target.nodeName && - -1 !== e.target.parentNode.parentNode.className.indexOf('slide') && - isSlideListMode() - ) { + var slideId = getContainingSlideId(e.target); + + if ('' !== slideId && isSlideListMode()) { e.preventDefault(); // NOTE: we should update hash to get things work properly - url.hash = '#' + e.target.parentNode.parentNode.id; - history.replaceState(null, null, url.pathname + '?full#' + e.target.parentNode.parentNode.id); + url.hash = '#' + slideId; + history.replaceState(null, null, url.pathname + '?full#' + slideId); enterSingleSlideMode(); updateProgress(getCurrentSlideNumber());