@nrk/core-toggle
Advanced tools
Comparing version 4.0.1 to 4.0.2
@@ -1,2 +0,2 @@ | ||
/*! @nrk/core-toggle v4.0.1 - Copyright (c) 2017-2022 NRK */ | ||
/*! @nrk/core-toggle v4.0.2 - Copyright (c) 2017-2022 NRK */ | ||
'use strict'; | ||
@@ -168,5 +168,6 @@ | ||
var IS_BROWSER = typeof window !== 'undefined'; | ||
var IS_ANDROID = IS_BROWSER && /(android)/i.test(navigator.userAgent); // Bad, but needed | ||
var HAS_NAVIGATOR = IS_BROWSER && typeof window.navigator !== 'undefined'; | ||
var IS_ANDROID = HAS_NAVIGATOR && /(android)/i.test(navigator.userAgent); // Bad, but needed | ||
var IS_IOS = IS_BROWSER && /iPad|iPhone|iPod/.test(String(navigator.platform)); | ||
var IS_IOS = HAS_NAVIGATOR && /iPad|iPhone|iPod/.test(String(navigator.platform)); | ||
// Mock HTMLElement for Node | ||
@@ -173,0 +174,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! @nrk/core-toggle v4.0.1 - Copyright (c) 2017-2022 NRK */ | ||
/*! @nrk/core-toggle v4.0.2 - Copyright (c) 2017-2022 NRK */ | ||
(function (global, factory) { | ||
@@ -176,5 +176,6 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) : | ||
var IS_BROWSER = typeof window !== 'undefined'; | ||
var IS_ANDROID = IS_BROWSER && /(android)/i.test(navigator.userAgent); // Bad, but needed | ||
var HAS_NAVIGATOR = IS_BROWSER && typeof window.navigator !== 'undefined'; | ||
var IS_ANDROID = HAS_NAVIGATOR && /(android)/i.test(navigator.userAgent); // Bad, but needed | ||
var IS_IOS = IS_BROWSER && /iPad|iPhone|iPod/.test(String(navigator.platform)); | ||
var IS_IOS = HAS_NAVIGATOR && /iPad|iPhone|iPod/.test(String(navigator.platform)); | ||
// Mock HTMLElement for Node | ||
@@ -477,3 +478,3 @@ | ||
var version = "4.0.1"; | ||
var version = "4.0.2"; | ||
@@ -480,0 +481,0 @@ /** |
@@ -1,3 +0,3 @@ | ||
/*! @nrk/core-toggle v4.0.1 - Copyright (c) 2017-2022 NRK */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).coreToggle=e()}(this,(function(){"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function n(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function u(t,e,n){return u=r()?Reflect.construct.bind():function(t,e,n){var i=[null];i.push.apply(i,e);var r=new(Function.bind.apply(t,i));return n&&o(r,n.prototype),r},u.apply(null,arguments)}function s(t){var e="function"==typeof Map?new Map:void 0;return s=function(t){if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;var n;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return u(t,arguments,i(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,t)},s(t)}function a(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}var c="undefined"!=typeof window,d=c&&/(android)/i.test(navigator.userAgent),l=c&&/iPad|iPhone|iPod/.test(String(navigator.platform));c||global.HTMLElement||(global.HTMLElement=function(){return n((function e(){t(this,e)}))}());var h,p,f=(h="undefined"==typeof window?{}:window.Element.prototype,p=h.matches||h.msMatchesSelector||h.webkitMatchesSelector,h.closest?function(t,e){return t.closest(e)}:function(t,e){for(t.correspondingUseElement&&(t=t.correspondingUseElement);t;t=t.parentElement)if(p.call(t,e))return t;return null});function b(t,e){var n,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o="prevent_recursive_dispatch_maximum_callstack".concat(e);if(t[o])return!0;t[o]=!0,"function"==typeof window.CustomEvent?n=new window.CustomEvent(e,{bubbles:!0,cancelable:!0,detail:i}):(n=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,i);var r=t.dispatchEvent(n);return t[o]=null,r}function v(){return Date.now().toString(36)+Math.random().toString(36).slice(2,5)}function y(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:!this.hasAttribute(e);return!n===t.hasAttribute(e)&&t[n?"setAttribute":"removeAttribute"](e,""),n}var g=c&&document.createElement("div"),w=function(e){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e)}(h,e);var u,s,c=(u=h,s=r(),function(){var t,e=i(u);if(s){var n=i(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return a(this,t)});function h(){return t(this,h),c.apply(this,arguments)}return n(h,[{key:"connectedCallback",value:function(){l&&(document.documentElement.style.cursor="pointer"),d||this.setAttribute("aria-labelledby",this.button.id=this.button.id||v()),this.value=this.button.textContent,this.setAttribute("role","group"),this.button.setAttribute("aria-expanded",this._open=!this.hidden),this.button.setAttribute("aria-controls",this.id=this.id||v()),document.addEventListener("keydown",this,!0),document.addEventListener("click",this)}},{key:"disconnectedCallback",value:function(){this._button=null,document.removeEventListener("keydown",this,!0),document.removeEventListener("click",this),m(this,!0)}},{key:"attributeChangedCallback",value:function(){if(this._open===this.hidden){this.button.setAttribute("aria-expanded",this._open=!this.hidden);try{this.querySelector("[autofocus]").focus()}catch(t){}m(this,this.hidden),b(this,"toggle")}}},{key:"handleEvent",value:function(t){if(!t.defaultPrevented){if("resize"===t.type||"scroll"===t.type)return this.updatePosition();if("keydown"===t.type&&27===t.keyCode)if(t.target.getAttribute&&"true"===t.target.getAttribute("aria-expanded")?t.target===this.button:f(t.target,this.nodeName)===this)return this.hidden=!0,this.button.focus(),t.preventDefault();if("click"===t.type){var e=f(t.target,"a,button");e&&!e.hasAttribute("aria-expanded")&&f(t.target,this.nodeName)===this?b(this,"toggle.select",e):e&&e.getAttribute("aria-controls")===this.id?this.hidden=!this.hidden:this.popup&&!this.contains(t.target)&&(this.hidden=!0)}}}},{key:"updatePosition",value:function(){var t=this;if(!this._skipPosition&&this.button){this._skipPosition=!0,this.style.position="fixed";var e=this.button.getBoundingClientRect(),n=this.getBoundingClientRect(),i=e.left+n.width<window.innerWidth,o=e.right-n.width>=0,r=e.bottom+n.height<window.innerHeight,u=e.top-n.height>0,s=Math.round((window.innerWidth-n.width)/2);n.width>window.innerWidth?s=0:i?s=e.left:o&&(s=e.right-n.width);var a=r||!u,c=a?window.pageYOffset+e.bottom+n.height+30:0;this.style.left="".concat(s,"px"),this.style.top="".concat(Math.round(a?e.bottom:e.top-n.height),"px"),g.style.cssText="position:absolute;padding:1px;top:".concat(Math.round(c),"px"),setTimeout((function(){return t._skipPosition=null}))}}},{key:"button",get:function(){return this._button&&(this._button.getAttribute("data-for")||this._button.getAttribute("for"))===this.id?this._button:(this._button=this.id&&document.querySelector('[for="'.concat(this.id,'"],[data-for="').concat(this.id,'"]')))||this.previousElementSibling}},{key:"popup",get:function(){return"true"===this.getAttribute("data-popup")||this.getAttribute("data-popup")||this.hasAttribute("data-popup")},set:function(t){this[!1===t?"removeAttribute":"setAttribute"]("data-popup",t)}},{key:"autoposition",get:function(){return this.hasAttribute("autoposition")},set:function(t){y(this,"autoposition",t)}},{key:"hidden",get:function(){return this.hasAttribute("hidden")},set:function(t){y(this,"hidden",t)}},{key:"value",get:function(){return this.button.value||this.button.textContent},set:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.button&&this.popup.length){var e=this.button,n=(e.getAttribute("aria-label")||",".concat(this.popup)).split(",")[1],i=t.textContent||t||"";if(n===this.popup){var o=e.querySelector("span")||e;e.value=t.value||i,o[t.innerHTML?"innerHTML":"textContent"]=t.innerHTML||i,e.setAttribute("aria-label","".concat(e.textContent,",").concat(this.popup))}}}}],[{key:"observedAttributes",get:function(){return["hidden","autoposition"]}}]),h}(s(HTMLElement));function m(t,e){e?(t._positionObserver&&t._positionObserver.disconnect(),g.parentNode&&g.parentNode.removeChild(g),t.style.position=t._positionObserver=null,window.removeEventListener("scroll",t,!0),window.removeEventListener("resize",t)):t.autoposition&&(t._positionObserver||(t._positionObserver=window.MutationObserver&&new window.MutationObserver(t.updatePosition.bind(t))),t._positionObserver&&t._positionObserver.observe(t,{childList:!0,subtree:!0,attributes:!0}),document.body.appendChild(g),window.addEventListener("scroll",t,!0),window.addEventListener("resize",t),t.updatePosition())}return w})),window.customElements.define("core-toggle",coreToggle); | ||
/*! @nrk/core-toggle v4.0.2 - Copyright (c) 2017-2022 NRK */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).coreToggle=e()}(this,(function(){"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function n(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function u(t,e,n){return u=r()?Reflect.construct.bind():function(t,e,n){var i=[null];i.push.apply(i,e);var r=new(Function.bind.apply(t,i));return n&&o(r,n.prototype),r},u.apply(null,arguments)}function s(t){var e="function"==typeof Map?new Map:void 0;return s=function(t){if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;var n;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return u(t,arguments,i(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,t)},s(t)}function a(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}var c="undefined"!=typeof window,d=c&&void 0!==window.navigator,l=d&&/(android)/i.test(navigator.userAgent),h=d&&/iPad|iPhone|iPod/.test(String(navigator.platform));c||global.HTMLElement||(global.HTMLElement=function(){return n((function e(){t(this,e)}))}());var p,f,b=(p="undefined"==typeof window?{}:window.Element.prototype,f=p.matches||p.msMatchesSelector||p.webkitMatchesSelector,p.closest?function(t,e){return t.closest(e)}:function(t,e){for(t.correspondingUseElement&&(t=t.correspondingUseElement);t;t=t.parentElement)if(f.call(t,e))return t;return null});function v(t,e){var n,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o="prevent_recursive_dispatch_maximum_callstack".concat(e);if(t[o])return!0;t[o]=!0,"function"==typeof window.CustomEvent?n=new window.CustomEvent(e,{bubbles:!0,cancelable:!0,detail:i}):(n=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,i);var r=t.dispatchEvent(n);return t[o]=null,r}function y(){return Date.now().toString(36)+Math.random().toString(36).slice(2,5)}function g(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:!this.hasAttribute(e);return!n===t.hasAttribute(e)&&t[n?"setAttribute":"removeAttribute"](e,""),n}var w=c&&document.createElement("div"),m=function(e){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e)}(d,e);var u,s,c=(u=d,s=r(),function(){var t,e=i(u);if(s){var n=i(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return a(this,t)});function d(){return t(this,d),c.apply(this,arguments)}return n(d,[{key:"connectedCallback",value:function(){h&&(document.documentElement.style.cursor="pointer"),l||this.setAttribute("aria-labelledby",this.button.id=this.button.id||y()),this.value=this.button.textContent,this.setAttribute("role","group"),this.button.setAttribute("aria-expanded",this._open=!this.hidden),this.button.setAttribute("aria-controls",this.id=this.id||y()),document.addEventListener("keydown",this,!0),document.addEventListener("click",this)}},{key:"disconnectedCallback",value:function(){this._button=null,document.removeEventListener("keydown",this,!0),document.removeEventListener("click",this),E(this,!0)}},{key:"attributeChangedCallback",value:function(){if(this._open===this.hidden){this.button.setAttribute("aria-expanded",this._open=!this.hidden);try{this.querySelector("[autofocus]").focus()}catch(t){}E(this,this.hidden),v(this,"toggle")}}},{key:"handleEvent",value:function(t){if(!t.defaultPrevented){if("resize"===t.type||"scroll"===t.type)return this.updatePosition();if("keydown"===t.type&&27===t.keyCode)if(t.target.getAttribute&&"true"===t.target.getAttribute("aria-expanded")?t.target===this.button:b(t.target,this.nodeName)===this)return this.hidden=!0,this.button.focus(),t.preventDefault();if("click"===t.type){var e=b(t.target,"a,button");e&&!e.hasAttribute("aria-expanded")&&b(t.target,this.nodeName)===this?v(this,"toggle.select",e):e&&e.getAttribute("aria-controls")===this.id?this.hidden=!this.hidden:this.popup&&!this.contains(t.target)&&(this.hidden=!0)}}}},{key:"updatePosition",value:function(){var t=this;if(!this._skipPosition&&this.button){this._skipPosition=!0,this.style.position="fixed";var e=this.button.getBoundingClientRect(),n=this.getBoundingClientRect(),i=e.left+n.width<window.innerWidth,o=e.right-n.width>=0,r=e.bottom+n.height<window.innerHeight,u=e.top-n.height>0,s=Math.round((window.innerWidth-n.width)/2);n.width>window.innerWidth?s=0:i?s=e.left:o&&(s=e.right-n.width);var a=r||!u,c=a?window.pageYOffset+e.bottom+n.height+30:0;this.style.left="".concat(s,"px"),this.style.top="".concat(Math.round(a?e.bottom:e.top-n.height),"px"),w.style.cssText="position:absolute;padding:1px;top:".concat(Math.round(c),"px"),setTimeout((function(){return t._skipPosition=null}))}}},{key:"button",get:function(){return this._button&&(this._button.getAttribute("data-for")||this._button.getAttribute("for"))===this.id?this._button:(this._button=this.id&&document.querySelector('[for="'.concat(this.id,'"],[data-for="').concat(this.id,'"]')))||this.previousElementSibling}},{key:"popup",get:function(){return"true"===this.getAttribute("data-popup")||this.getAttribute("data-popup")||this.hasAttribute("data-popup")},set:function(t){this[!1===t?"removeAttribute":"setAttribute"]("data-popup",t)}},{key:"autoposition",get:function(){return this.hasAttribute("autoposition")},set:function(t){g(this,"autoposition",t)}},{key:"hidden",get:function(){return this.hasAttribute("hidden")},set:function(t){g(this,"hidden",t)}},{key:"value",get:function(){return this.button.value||this.button.textContent},set:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.button&&this.popup.length){var e=this.button,n=(e.getAttribute("aria-label")||",".concat(this.popup)).split(",")[1],i=t.textContent||t||"";if(n===this.popup){var o=e.querySelector("span")||e;e.value=t.value||i,o[t.innerHTML?"innerHTML":"textContent"]=t.innerHTML||i,e.setAttribute("aria-label","".concat(e.textContent,",").concat(this.popup))}}}}],[{key:"observedAttributes",get:function(){return["hidden","autoposition"]}}]),d}(s(HTMLElement));function E(t,e){e?(t._positionObserver&&t._positionObserver.disconnect(),w.parentNode&&w.parentNode.removeChild(w),t.style.position=t._positionObserver=null,window.removeEventListener("scroll",t,!0),window.removeEventListener("resize",t)):t.autoposition&&(t._positionObserver||(t._positionObserver=window.MutationObserver&&new window.MutationObserver(t.updatePosition.bind(t))),t._positionObserver&&t._positionObserver.observe(t,{childList:!0,subtree:!0,attributes:!0}),document.body.appendChild(w),window.addEventListener("scroll",t,!0),window.addEventListener("resize",t),t.updatePosition())}return m})),window.customElements.define("core-toggle",coreToggle); | ||
//# sourceMappingURL=core-toggle.min.js.map |
@@ -1,2 +0,2 @@ | ||
/*! @nrk/core-toggle v4.0.1 - Copyright (c) 2017-2022 NRK */ | ||
/*! @nrk/core-toggle v4.0.2 - Copyright (c) 2017-2022 NRK */ | ||
'use strict'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! @nrk/core-toggle v4.0.1 - Copyright (c) 2017-2022 NRK */ | ||
/*! @nrk/core-toggle v4.0.2 - Copyright (c) 2017-2022 NRK */ | ||
'use strict'; | ||
@@ -174,5 +174,6 @@ | ||
var IS_BROWSER = typeof window !== 'undefined'; | ||
var IS_ANDROID = IS_BROWSER && /(android)/i.test(navigator.userAgent); // Bad, but needed | ||
var HAS_NAVIGATOR = IS_BROWSER && typeof window.navigator !== 'undefined'; | ||
var IS_ANDROID = HAS_NAVIGATOR && /(android)/i.test(navigator.userAgent); // Bad, but needed | ||
var IS_IOS = IS_BROWSER && /iPad|iPhone|iPod/.test(String(navigator.platform)); | ||
var IS_IOS = HAS_NAVIGATOR && /iPad|iPhone|iPod/.test(String(navigator.platform)); | ||
// Mock HTMLElement for Node | ||
@@ -475,3 +476,3 @@ | ||
var version = "4.0.1"; | ||
var version = "4.0.2"; | ||
@@ -478,0 +479,0 @@ /** |
@@ -5,3 +5,3 @@ { | ||
"author": "NRK <opensource@nrk.no> (https://www.nrk.no/)", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "core-toggle.cjs.js", |
@@ -169,3 +169,3 @@ # Core Toggle | ||
<p>This example illustrates how core-toggle with <code style="font-size: 16px">autoposition</code> draws relative to the screen edge marked by the red frame</p> | ||
<iframe src="core-toggle/autoposition.html" width="300" height="400" style="border: 2px solid red;"></iframe> | ||
<iframe title="Examples for use of autoposition" src="core-toggle/autoposition.html" width="300" height="400" style="border: 2px solid red;"></iframe> | ||
``` | ||
@@ -172,0 +172,0 @@ ## Events |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
205780
2781