@nrk/core-toggle
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -8,2 +8,3 @@ import {name, version} from './package.json' | ||
const POPS = 'aria-haspopup' | ||
const KEYS = {ESC: 27} | ||
@@ -27,2 +28,14 @@ export default function toggle (buttons, open) { | ||
addEvent(UUID, 'keydown', (event) => { | ||
if (event.keyCode === KEYS.ESC) { | ||
for (let el = event.target; el; el = el.parentElement) { | ||
if (el.hasAttribute(UUID)) { | ||
const open = el.getAttribute(OPEN) === 'true' | ||
const pops = el.getAttribute(POPS) === 'true' | ||
if (open && pops) return setOpen(el, false) | ||
} | ||
} | ||
} | ||
}) | ||
addEvent(UUID, 'click', ({target}) => { | ||
@@ -29,0 +42,0 @@ queryAll(`[${UUID}]`).forEach((el) => { |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.coreToggle=e()}(this,function(){"use strict";var t="undefined"!=typeof window,e=t&&/(android)/i.test(navigator.userAgent),n=(t&&/iPad|iPhone|iPod/.test(String(navigator.platform)),function(t){void 0===t&&(t=!1);try{window.addEventListener("test",null,{get passive(){t=!0}})}catch(t){}return t}());var i="prevent_recursive_dispatch_maximum_callstack";function o(t){return Date.now().toString(36)+Math.random().toString(36).slice(2,5)}function r(t,e){if(void 0===e&&(e=document),t){if(t.nodeType)return[t];if("string"==typeof t)return[].slice.call(e.querySelectorAll(t));if(t.length)return[].slice.call(t)}return[]}var u,a,d,l,c="data-@nrk/core-toggle-1.1.3".replace(/\W+/g,"-"),f=e?"data":"aria",p="aria-expanded",s="aria-haspopup";function g(t,e){var n=t.nextElementSibling,o="true"===t.getAttribute(p),r="boolean"==typeof e?e:"toggle"===e?!o:o,u=o===r||function(t,e,n){void 0===n&&(n={});var o,r=""+i+e;if(t[r])return!0;t[r]=!0,"function"==typeof window.CustomEvent?o=new window.CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n}):(o=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,n);var u=t.dispatchEvent(o);return t[r]=null,u}(t,"toggle",{relatedTarget:n,isOpen:o,willOpen:r})?r:"true"===t.getAttribute(p);t.setAttribute(p,u),t.nextElementSibling[u?"removeAttribute":"setAttribute"]("hidden","")}return u=c,a="click",d=function(t){var e=t.target;r("["+c+"]").forEach(function(t){var n="true"===t.getAttribute(p),i="true"===t.getAttribute(s),o=t.nextElementSibling;t.contains(e)?g(t,!n):i&&n&&g(t,o.contains(e))})},void 0===l&&(l=!1),"undefined"==typeof window||window[u=u+"-"+a]||(n||"object"!=typeof l||(l=Boolean(l.capture)),("resize"===a||"load"===a?window:document).addEventListener(window[u]=a,d,l)),function(t,e){var n="object"==typeof e?e:{open:e};return r(t).map(function(t){var e="boolean"==typeof n.open?n.open:"true"===t.getAttribute(p),i="boolean"==typeof n.popup?n.popup:"true"===t.getAttribute(s),r=t.nextElementSibling;return t.setAttribute(c,""),t.setAttribute(s,i),t.setAttribute("aria-controls",r.id=r.id||o()),r.setAttribute(f+"-labelledby",t.id=t.id||o()),g(t,e),t})}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.coreToggle=e()}(this,function(){"use strict";var t="undefined"!=typeof window,e=t&&/(android)/i.test(navigator.userAgent),r=(t&&/iPad|iPhone|iPod/.test(String(navigator.platform)),function(t){void 0===t&&(t=!1);try{window.addEventListener("test",null,{get passive(){t=!0}})}catch(t){}return t}());function n(t,e,n,i){(void 0===i&&(i=!1),"undefined"==typeof window||window[t=t+"-"+e])||(r||"object"!=typeof i||(i=Boolean(i.capture)),("resize"===e||"load"===e?window:document).addEventListener(window[t]=e,n,i))}var u="prevent_recursive_dispatch_maximum_callstack";function o(t){return Date.now().toString(36)+Math.random().toString(36).slice(2,5)}function i(t,e){if(void 0===e&&(e=document),t){if(t.nodeType)return[t];if("string"==typeof t)return[].slice.call(e.querySelectorAll(t));if(t.length)return[].slice.call(t)}return[]}var a="data-@nrk/core-toggle-1.1.4".replace(/\W+/g,"-"),d=e?"data":"aria",l="aria-expanded",c="aria-haspopup",f=27;function p(t,e){var n=t.nextElementSibling,i="true"===t.getAttribute(l),r="boolean"==typeof e?e:"toggle"===e?!i:i,o=i===r||function(t,e,n){void 0===n&&(n={});var i,r=""+u+e;if(t[r])return!0;t[r]=!0,"function"==typeof window.CustomEvent?i=new window.CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n}):(i=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,n);var o=t.dispatchEvent(i);return t[r]=null,o}(t,"toggle",{relatedTarget:n,isOpen:i,willOpen:r})?r:"true"===t.getAttribute(l);t.setAttribute(l,o),t.nextElementSibling[o?"removeAttribute":"setAttribute"]("hidden","")}return n(a,"keydown",function(t){if(t.keyCode===f)for(var e=t.target;e;e=e.parentElement)if(e.hasAttribute(a)){var n="true"===e.getAttribute(l),i="true"===e.getAttribute(c);if(n&&i)return p(e,!1)}}),n(a,"click",function(t){var r=t.target;i("["+a+"]").forEach(function(t){var e="true"===t.getAttribute(l),n="true"===t.getAttribute(c),i=t.nextElementSibling;t.contains(r)?p(t,!e):n&&e&&p(t,i.contains(r))})}),function(t,e){var r="object"==typeof e?e:{open:e};return i(t).map(function(t){var e="boolean"==typeof r.open?r.open:"true"===t.getAttribute(l),n="boolean"==typeof r.popup?r.popup:"true"===t.getAttribute(c),i=t.nextElementSibling;return t.setAttribute(a,""),t.setAttribute(c,n),t.setAttribute("aria-controls",i.id=i.id||o()),i.setAttribute(d+"-labelledby",t.id=t.id||o()),p(t,e),t})}}); | ||
//# sourceMappingURL=core-toggle.min.js.map |
@@ -1,2 +0,2 @@ | ||
import toggle from './core-toggle' | ||
const toggle = require('./core-toggle.min') | ||
@@ -3,0 +3,0 @@ describe('toggle', () => { |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):t.CoreToggle=e(t.React)}(this,function(t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var e="undefined"!=typeof window,n=e&&/(android)/i.test(navigator.userAgent),o=(e&&/iPad|iPhone|iPod/.test(String(navigator.platform)),function(t){void 0===t&&(t=!1);try{window.addEventListener("test",null,{get passive(){t=!0}})}catch(t){}return t}());var r="prevent_recursive_dispatch_maximum_callstack";function i(t){return Date.now().toString(36)+Math.random().toString(36).slice(2,5)}function u(t,e){if(void 0===e&&(e=document),t){if(t.nodeType)return[t];if("string"==typeof t)return[].slice.call(e.querySelectorAll(t));if(t.length)return[].slice.call(t)}return[]}var p,a,l,d,c="data-@nrk/core-toggle-1.1.3".replace(/\W+/g,"-"),s=n?"data":"aria",f="aria-expanded",g="aria-haspopup";function v(t,e){var n="object"==typeof e?e:{open:e};return u(t).map(function(t){var e="boolean"==typeof n.open?n.open:"true"===t.getAttribute(f),o="boolean"==typeof n.popup?n.popup:"true"===t.getAttribute(g),r=t.nextElementSibling;return t.setAttribute(c,""),t.setAttribute(g,o),t.setAttribute("aria-controls",r.id=r.id||i()),r.setAttribute(s+"-labelledby",t.id=t.id||i()),m(t,e),t})}function m(t,e){var n=t.nextElementSibling,o="true"===t.getAttribute(f),i="boolean"==typeof e?e:"toggle"===e?!o:o,u=o===i||function(t,e,n){void 0===n&&(n={});var o,i=""+r+e;if(t[i])return!0;t[i]=!0,"function"==typeof window.CustomEvent?o=new window.CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n}):(o=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,n);var u=t.dispatchEvent(o);return t[i]=null,u}(t,"toggle",{relatedTarget:n,isOpen:o,willOpen:i})?i:"true"===t.getAttribute(f);t.setAttribute(f,u),t.nextElementSibling[u?"removeAttribute":"setAttribute"]("hidden","")}p=c,a="click",l=function(t){var e=t.target;u("["+c+"]").forEach(function(t){var n="true"===t.getAttribute(f),o="true"===t.getAttribute(g),r=t.nextElementSibling;t.contains(e)?m(t,!n):o&&n&&m(t,r.contains(e))})},void 0===d&&(d=!1),"undefined"==typeof window||window[p=p+"-"+a]||(o||"object"!=typeof d||(d=Boolean(d.capture)),("resize"===a||"load"===a?window:document).addEventListener(window[p]=a,l,d));var b={open:null,popup:null,onToggle:null};return function(e){function n(){e.apply(this,arguments)}return e&&(n.__proto__=e),n.prototype=Object.create(e&&e.prototype),n.prototype.constructor=n,n.prototype.componentDidMount=function(){v(this.el.firstElementChild),this.el.addEventListener("toggle",this.props.onToggle)},n.prototype.componentDidUpdate=function(){v(this.el.firstElementChild)},n.prototype.componentWillUnmount=function(){this.el.removeEventListener("toggle",this.props.onToggle)},n.prototype.render=function(){var e=this;return t.createElement("div",function(t,e,n){return void 0===n&&(n={}),Object.keys(t).reduce(function(n,o){return e.hasOwnProperty(o)||(n[o]=t[o]),n},n)}(this.props,b,{ref:function(t){return e.el=t}}),t.Children.map(this.props.children,function(n,o){return 0===o?t.cloneElement(n,{"aria-expanded":String(Boolean(e.props.open)),"aria-haspopup":String(Boolean(e.props.popup))}):1===o?t.cloneElement(n,{hidden:!e.props.open}):n}))},n}(t.Component)}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):t.CoreToggle=e(t.React)}(this,function(i){"use strict";i=i&&i.hasOwnProperty("default")?i.default:i;var t="undefined"!=typeof window,e=t&&/(android)/i.test(navigator.userAgent),r=(t&&/iPad|iPhone|iPod/.test(String(navigator.platform)),function(t){void 0===t&&(t=!1);try{window.addEventListener("test",null,{get passive(){t=!0}})}catch(t){}return t}());function n(t,e,n,o){(void 0===o&&(o=!1),"undefined"==typeof window||window[t=t+"-"+e])||(r||"object"!=typeof o||(o=Boolean(o.capture)),("resize"===e||"load"===e?window:document).addEventListener(window[t]=e,n,o))}var u="prevent_recursive_dispatch_maximum_callstack";function a(t){return Date.now().toString(36)+Math.random().toString(36).slice(2,5)}function o(t,e){if(void 0===e&&(e=document),t){if(t.nodeType)return[t];if("string"==typeof t)return[].slice.call(e.querySelectorAll(t));if(t.length)return[].slice.call(t)}return[]}var p="data-@nrk/core-toggle-1.1.4".replace(/\W+/g,"-"),l=e?"data":"aria",d="aria-expanded",c="aria-haspopup",s=27;function f(t,e){var r="object"==typeof e?e:{open:e};return o(t).map(function(t){var e="boolean"==typeof r.open?r.open:"true"===t.getAttribute(d),n="boolean"==typeof r.popup?r.popup:"true"===t.getAttribute(c),o=t.nextElementSibling;return t.setAttribute(p,""),t.setAttribute(c,n),t.setAttribute("aria-controls",o.id=o.id||a()),o.setAttribute(l+"-labelledby",t.id=t.id||a()),g(t,e),t})}function g(t,e){var n=t.nextElementSibling,o="true"===t.getAttribute(d),r="boolean"==typeof e?e:"toggle"===e?!o:o,i=o===r||function(t,e,n){void 0===n&&(n={});var o,r=""+u+e;if(t[r])return!0;t[r]=!0,"function"==typeof window.CustomEvent?o=new window.CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n}):(o=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,n);var i=t.dispatchEvent(o);return t[r]=null,i}(t,"toggle",{relatedTarget:n,isOpen:o,willOpen:r})?r:"true"===t.getAttribute(d);t.setAttribute(d,i),t.nextElementSibling[i?"removeAttribute":"setAttribute"]("hidden","")}n(p,"keydown",function(t){if(t.keyCode===s)for(var e=t.target;e;e=e.parentElement)if(e.hasAttribute(p)){var n="true"===e.getAttribute(d),o="true"===e.getAttribute(c);if(n&&o)return g(e,!1)}}),n(p,"click",function(t){var r=t.target;o("["+p+"]").forEach(function(t){var e="true"===t.getAttribute(d),n="true"===t.getAttribute(c),o=t.nextElementSibling;t.contains(r)?g(t,!e):n&&e&&g(t,o.contains(r))})});var v={open:null,popup:null,onToggle:null};return function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype.componentDidMount=function(){f(this.el.firstElementChild),this.el.addEventListener("toggle",this.props.onToggle)},e.prototype.componentDidUpdate=function(){f(this.el.firstElementChild)},e.prototype.componentWillUnmount=function(){this.el.removeEventListener("toggle",this.props.onToggle)},e.prototype.render=function(){var n,o,t,r=this;return i.createElement("div",(n=this.props,o=v,void 0===(t={ref:function(t){return r.el=t}})&&(t={}),Object.keys(n).reduce(function(t,e){return o.hasOwnProperty(e)||(t[e]=n[e]),t},t)),i.Children.map(this.props.children,function(t,e){return 0===e?i.cloneElement(t,{"aria-expanded":String(Boolean(r.props.open)),"aria-haspopup":String(Boolean(r.props.popup))}):1===e?i.cloneElement(t,{hidden:!r.props.open}):t}))},e}(i.Component)}); | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,3 @@ { | ||
"author": "NRK <opensource@nrk.no> (https://www.nrk.no/)", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "core-toggle.min.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39777
108