From 8b72bff8aede849b40ac0990e092a9a6e76ece6c Mon Sep 17 00:00:00 2001 From: Matteo Leoni Date: Wed, 23 Oct 2019 12:45:49 +0200 Subject: [PATCH] fix space key error --- README.md | 4 ++-- dist/fisarmonica.min.js | 2 +- src/fisarmonica.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bd83a8f..2e57a89 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ Include css and js files Be sure to use the latest version ```html - - + + ``` Prepare the base markup diff --git a/dist/fisarmonica.min.js b/dist/fisarmonica.min.js index 1c77d45..b3f2367 100644 --- a/dist/fisarmonica.min.js +++ b/dist/fisarmonica.min.js @@ -1 +1 @@ -var Fisarmonica=function(e){var r,t,a={},i=Object.assign({keepPanelsOpen:!1,selector:"[data-fisarmonica]"},e),s="js-is-hidden",n="js-focus",o=document.querySelector(i.selector);function c(){for(var e="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",n=t.length,a=0;a<8;a++)e+=t.charAt(Math.floor(Math.random()*n));return e}a.open=function(e){return u(e,"open")},a.close=function(e){return u(e,"close")},a.disable=function(e){return u(e,"disable")},a.enable=function(e){return u(e,"enable")};function l(e){e.target.matches("button")&&(d(e.target),o.classList.add(n),e.preventDefault())}var u=function(n,a){t.forEach(function(e,t){"open"===a?n?n.includes(t)&&e.classList.remove(s):e.classList.remove(s):"close"===a&&(n?n.includes(t)&&e.classList.add(s):e.classList.add(s))}),r.forEach(function(e,t){"open"===a?n?n.includes(t)&&(e.setAttribute("aria-expanded",!0),1===n.length&&e.focus()):e.setAttribute("aria-expanded",!0):"close"===a?n?n.includes(t)&&e.setAttribute("aria-expanded",!1):e.setAttribute("aria-expanded",!1):"disable"===a?n?n.includes(t)&&e.setAttribute("disabled",!0):e.setAttribute("disabled",!0):"enable"===a&&(n?n.includes(t)&&e.removeAttribute("disabled"):e.removeAttribute("disabled"))})},d=function(e){var t=Array.from(r).indexOf(e);if(!i.keepPanelsOpen){var n=Array.apply(null,Array(r.length)).map(function(e,t){return t}).filter(function(e){return e!==t});a.close(n)}"false"===e.getAttribute("aria-expanded")?a.open([t]):a.close([t])};return o?(r=Array.from(o.querySelectorAll("dt > button")),t=Array.from(o.querySelectorAll("dd")),a.close(),function(){o.classList.add("fisarmonica");var n=c(),a=c();r.forEach(function(e,t){e.setAttribute("aria-controls","fisarmonica-panel-"+n+"-"+t),e.setAttribute("id","fisarmonica-panel-"+a+"-"+t)}),t.forEach(function(e,t){e.setAttribute("id","fisarmonica-panel-"+n+"-"+t),e.setAttribute("aria-labelledby","fisarmonica-panel-"+a+"-"+t)})}(),function(){if(i.theme)for(var e in i.theme)o.style.setProperty("--"+e,i.theme[e])}(),r.forEach(function(e){e.addEventListener("focus",function(){o.classList.add(n)}),e.addEventListener("blur",function(){o.classList.remove(n)})}),o.addEventListener("keydown",function(e){var t=event.which.toString(),n=event.target,a=r.indexOf(n);-1!==a&&("40"===t||"38"===t||"36"===t||"35"===t?("40"===t||"38"===t?a="40"===t?a+1===r.length?0:a+1:a-1==-1?r.length-1:a-1:"36"===t?a=0:"35"===t&&(a=r.length-1),r[a].focus(),e.preventDefault()):"32"!==t&&"13"!==t||(d(r[a]),e.preventDefault()))}),o.addEventListener("click",l,!1)):console.warn("Cannot find an fisarmonica with class"+i.selector),a}; \ No newline at end of file +var Fisarmonica=function(e){var r,t,a={},i=Object.assign({keepPanelsOpen:!1,selector:"[data-fisarmonica]"},e),s="js-is-hidden",n="js-focus",o=document.querySelector(i.selector);function c(){for(var e="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",n=t.length,a=0;a<8;a++)e+=t.charAt(Math.floor(Math.random()*n));return e}a.open=function(e){return u(e,"open")},a.close=function(e){return u(e,"close")},a.disable=function(e){return u(e,"disable")},a.enable=function(e){return u(e,"enable")};function l(e){e.target.matches("button")&&(d(e.target),o.classList.add(n),e.preventDefault())}var u=function(n,a){t.forEach(function(e,t){"open"===a?n?n.includes(t)&&e.classList.remove(s):e.classList.remove(s):"close"===a&&(n?n.includes(t)&&e.classList.add(s):e.classList.add(s))}),r.forEach(function(e,t){"open"===a?n?n.includes(t)&&(e.setAttribute("aria-expanded",!0),1===n.length&&e.focus()):e.setAttribute("aria-expanded",!0):"close"===a?n?n.includes(t)&&e.setAttribute("aria-expanded",!1):e.setAttribute("aria-expanded",!1):"disable"===a?n?n.includes(t)&&e.setAttribute("disabled",!0):e.setAttribute("disabled",!0):"enable"===a&&(n?n.includes(t)&&e.removeAttribute("disabled"):e.removeAttribute("disabled"))})},d=function(e){var t=Array.from(r).indexOf(e);if(!i.keepPanelsOpen){var n=Array.apply(null,Array(r.length)).map(function(e,t){return t}).filter(function(e){return e!==t});a.close(n)}"false"===e.getAttribute("aria-expanded")?a.open([t]):a.close([t])};return o?(r=Array.from(o.querySelectorAll("dt > button")),t=Array.from(o.querySelectorAll("dd")),a.close(),function(){o.classList.add("fisarmonica");var n=c(),a=c();r.forEach(function(e,t){e.setAttribute("aria-controls","fisarmonica-panel-"+n+"-"+t),e.setAttribute("id","fisarmonica-panel-"+a+"-"+t)}),t.forEach(function(e,t){e.setAttribute("id","fisarmonica-panel-"+n+"-"+t),e.setAttribute("aria-labelledby","fisarmonica-panel-"+a+"-"+t)})}(),function(){if(i.theme)for(var e in i.theme)o.style.setProperty("--"+e,i.theme[e])}(),r.forEach(function(e){e.addEventListener("focus",function(){o.classList.add(n)}),e.addEventListener("blur",function(){o.classList.remove(n)})}),o.addEventListener("keydown",function(e){var t=event.which.toString(),n=event.target,a=r.indexOf(n);-1!==a&&("40"===t||"38"===t||"36"===t||"35"===t?("40"===t||"38"===t?a="40"===t?a+1===r.length?0:a+1:a-1==-1?r.length-1:a-1:"36"===t?a=0:"35"===t&&(a=r.length-1),r[a].focus(),e.preventDefault()):"13"===t&&(d(r[a]),e.preventDefault()))}),o.addEventListener("click",l,!1)):console.warn("Cannot find an fisarmonica with class"+i.selector),a}; \ No newline at end of file diff --git a/src/fisarmonica.js b/src/fisarmonica.js index 2bac821..24537eb 100644 --- a/src/fisarmonica.js +++ b/src/fisarmonica.js @@ -251,7 +251,7 @@ var Fisarmonica = function (options) { // eslint-disable-line no-unused-vars, pa } buttons[index].focus() e.preventDefault() - } else if (key === '32' || key === '13') { // enter or space + } else if (key === '13') { // enter _buttonClickHandler(buttons[index]) e.preventDefault() }