@nrk/core-input
Advanced tools
Comparing version 1.3.0 to 1.3.1
'use strict'; | ||
var name = "@nrk/core-input"; | ||
var version = "1.2.2"; | ||
var version = "1.3.0"; | ||
@@ -184,3 +184,3 @@ var IS_BROWSER = typeof window !== 'undefined'; | ||
input.focus(); | ||
setupExpand(input, false); | ||
requestAnimFrame(function () { return setupExpand(input, false); }); // Let IE11 finish focus event bubbling | ||
} | ||
@@ -187,0 +187,0 @@ } |
@@ -90,3 +90,3 @@ import { name, version } from './package.json' | ||
input.focus() | ||
setupExpand(input, false) | ||
requestAnimFrame(() => setupExpand(input, false)) // Let IE11 finish focus event bubbling | ||
} | ||
@@ -93,0 +93,0 @@ } |
@@ -1,3 +0,3 @@ | ||
/*! @nrk/core-input v1.2.2 - Copyright (c) 2017-2019 NRK */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["react","prop-types"],t):(e=e||self).CoreInput=t(e.React,e.PropTypes)}(this,function(i,e){"use strict";i=i&&i.hasOwnProperty("default")?i.default:i,e=e&&e.hasOwnProperty("default")?e.default:e;var t="undefined"!=typeof window,a=(t&&/(android)/i.test(navigator.userAgent),t&&/iPad|iPhone|iPod/.test(String(navigator.platform))),o=function(e){void 0===e&&(e=!1);try{window.addEventListener("test",null,{get passive(){e=!0}})}catch(e){}return e}();function n(e,t,n,r){(void 0===r&&(r=!1),"undefined"==typeof window||window[e=e+"-"+t])||(o||"object"!=typeof r||(r=Boolean(r.capture)),("resize"===t||"load"===t?window:document).addEventListener(window[e]=t,n,r))}var r={"&":"&","<":"<",">":">",'"':""","/":"/","'":"'"};function u(e){return String(e||"").replace(/[&<>"'/]/g,function(e){return r[e]})}var l="prevent_recursive_dispatch_maximum_callstack";function c(e,t,n){void 0===n&&(n={});var r,o=""+l+t;if(e[o])return!0;e[o]=!0,"function"==typeof window.CustomEvent?r=new window.CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n}):(r=document.createEvent("CustomEvent")).initCustomEvent(t,!0,!0,n);var i=e.dispatchEvent(r);return e[o]=null,i}function s(e,t){if(void 0===t&&(t=document),e){if(e.nodeType)return[e];if("string"==typeof e)return[].slice.call(t.querySelectorAll(e));if(e.length)return[].slice.call(e)}return[]}var p="data-@nrk/core-input-1.2.2".replace(/\W+/g,"-"),d=13,f=27,v=33,h=34,m=35,b=36,g=38,x=40,y='[tabindex="-1"]',E=500;function A(e,t){var o="object"==typeof t?t:{content:t},i="string"==typeof o.content;return s(e).map(function(e){var t=e.nextElementSibling,n=void 0===o.ajax?e.getAttribute(p):o.ajax,r=void 0===o.open?e===document.activeElement:o.open;return e.setAttribute(p,n||""),e.setAttribute(a?"data-role":"role","combobox"),e.setAttribute("aria-autocomplete","list"),e.setAttribute("autocomplete","off"),i&&(t.innerHTML=o.content),s("a,button",t).forEach(C),j(e,r),e})}function w(a){a.ctrlKey||a.altKey||a.metaKey||a.defaultPrevented||s("["+p+"]").forEach(function(e){var t,n,r=e.nextElementSibling,o=e===a.target||r.contains(a.target),i="click"===a.type&&o&&s(y,r).filter(function(e){return e.contains(a.target)})[0];i?(t=e,n={relatedTarget:r,currentTarget:i,value:i.value||i.textContent.trim()},c(t,"input.select",n)&&(t.value=n.value,t.focus(),j(t,!1))):j(e,o)})}function S(e,t){var n=e.nextElementSibling,r=[e].concat(s(y+":not([hidden])",n)),o=t.keyCode===f&&"true"===e.getAttribute("aria-expanded"),i=r.indexOf(document.activeElement),a=!1;t.keyCode===x?a=r[i+1]||r[0]:t.keyCode===g?a=r[i-1]||r.pop():n.contains(t.target)&&(t.keyCode===m||t.keyCode===h?a=r.pop():t.keyCode===b||t.keyCode===v?a=r[1]:t.keyCode!==d&&e.focus()),j(e,t.keyCode!==f),(!1!==a||o)&&t.preventDefault(),a&&a.focus()}function j(e,t){var n;void 0===t&&(t="true"===e.getAttribute("aria-expanded")),n=function(){e.nextElementSibling[t?"removeAttribute":"setAttribute"]("hidden",""),e.setAttribute("aria-expanded",t)},(window.requestAnimationFrame||window.setTimeout)(n)}function C(e,t,n){e.setAttribute("aria-label",e.textContent.trim()+", "+(t+1)+" av "+n.length),e.setAttribute("tabindex","-1"),e.setAttribute("type","button")}function L(e){var t=e.getAttribute(p),n=L.xhr=L.xhr||new window.XMLHttpRequest;if(!t)return!1;clearTimeout(L.timer),n.abort(),n.onload=function(){try{n.responseJSON=JSON.parse(n.responseText)}catch(e){n.responseJSON=!1}c(e,"input.ajax",n)},L.timer=setTimeout(function(){e.value&&c(e,"input.ajax.beforeSend",n)&&(n.open("GET",t.replace("{{value}}",window.encodeURIComponent(e.value)),!0),n.setRequestHeader("X-Requested-With","XMLHttpRequest"),n.send())},E)}A.escapeHTML=u,A.highlight=function(e,t){var n=t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&");return u(e).replace(new RegExp(n||".^","gi"),"<mark>$&</mark>")},n(p,"click",w),n(p,"focus",w,!0),n(p,"input",function(e){var i,t,n=e.target;n.hasAttribute(p)&&(t={relatedTarget:(i=n).nextElementSibling},c(i,"input.filter",t)&&!1===L(i)&&s(y,i.nextElementSibling).reduce(function(e,t){var n="LI"===t.parentElement.nodeName&&t.parentElement,r=-1!==t.textContent.toLowerCase().indexOf(i.value.toLowerCase()),o=r?"removeAttribute":"setAttribute";return n&&n[o]("hidden",""),t[o]("hidden",""),r?e.concat(t):e},[]).forEach(C))}),n(p,"keydown",function(e){if(!(e.ctrlKey||e.altKey||e.metaKey)){if(e.target.hasAttribute&&e.target.hasAttribute(p))return S(e.target,e);for(var t=e.target,n=void 0;t;t=t.parentElement)if((n=t.previousElementSibling)&&n.hasAttribute(p))return S(n,e)}},!0);var k=function(n){function t(e){var t=this;n.call(this,e),this.onFilter=function(e){return t.props.onFilter&&t.props.onFilter(e)},this.onSelect=function(e){return t.props.onSelect&&t.props.onSelect(e)},this.onAjaxBeforeSend=function(e){return t.props.onAjaxBeforeSend&&t.props.onAjaxBeforeSend(e)},this.onAjax=function(e){return t.props.onAjax&&t.props.onAjax(e)}}n&&(t.__proto__=n),(t.prototype=Object.create(n&&n.prototype)).constructor=t;var e={defaultProps:{configurable:!0}};return e.defaultProps.get=function(){return{open:null,ajax:null,onAjax:null,onAjaxBeforeSend:null,onFilter:null,onSelect:null}},t.prototype.componentDidMount=function(){this.el.addEventListener("input.filter",this.onFilter),this.el.addEventListener("input.select",this.onSelect),this.el.addEventListener("input.ajax.beforeSend",this.onAjaxBeforeSend),this.el.addEventListener("input.ajax",this.onAjax),A(this.el.firstElementChild,this.props)},t.prototype.componentDidUpdate=function(){A(this.el.firstElementChild)},t.prototype.componentWillUnmount=function(){this.el.removeEventListener("input.filter",this.onFilter),this.el.removeEventListener("input.select",this.onSelect),this.el.removeEventListener("input.beforeSend",this.onAjaxBeforeSend),this.el.removeEventListener("input.ajax",this.onAjax)},t.prototype.render=function(){var n,r,e,o=this;return i.createElement("div",(n=this.props,r=t.defaultProps,void 0===(e={ref:function(e){return o.el=e}})&&(e={}),Object.keys(n).reduce(function(e,t){return r.hasOwnProperty(t)||(e[t]=n[t]),e},e)),i.Children.map(this.props.children,function(e,t){return 0===t?i.cloneElement(e,{"aria-expanded":String(Boolean(o.props.open))}):1===t?i.cloneElement(e,{hidden:!o.props.open}):e}))},Object.defineProperties(t,e),t}(i.Component);return k.Highlight=function(e){var t=e.text,n=e.query;return void 0===n&&(n=""),i.createElement("span",{dangerouslySetInnerHTML:{__html:A.highlight(t,n)}})},k.propTypes={onFilter:e.func,onSelect:e.func,onAjax:e.func,open:e.bool,ajax:e.oneOfType([e.string,e.object])},k}); | ||
/*! @nrk/core-input v1.3.0 - Copyright (c) 2017-2019 NRK */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["react","prop-types"],t):(e=e||self).CoreInput=t(e.React,e.PropTypes)}(this,function(i,e){"use strict";i=i&&i.hasOwnProperty("default")?i.default:i,e=e&&e.hasOwnProperty("default")?e.default:e;var t="undefined"!=typeof window,a=(t&&/(android)/i.test(navigator.userAgent),t&&/iPad|iPhone|iPod/.test(String(navigator.platform))),o=function(e){void 0===e&&(e=!1);try{window.addEventListener("test",null,{get passive(){e=!0}})}catch(e){}return e}();function n(e,t,n,r){(void 0===r&&(r=!1),"undefined"==typeof window||window[e=e+"-"+t])||(o||"object"!=typeof r||(r=Boolean(r.capture)),("resize"===t||"load"===t?window:document).addEventListener(window[e]=t,n,r))}var r={"&":"&","<":"<",">":">",'"':""","/":"/","'":"'"};function u(e){return String(e||"").replace(/[&<>"'/]/g,function(e){return r[e]})}var l="prevent_recursive_dispatch_maximum_callstack";function c(e,t,n){void 0===n&&(n={});var r,o=""+l+t;if(e[o])return!0;e[o]=!0,"function"==typeof window.CustomEvent?r=new window.CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n}):(r=document.createEvent("CustomEvent")).initCustomEvent(t,!0,!0,n);var i=e.dispatchEvent(r);return e[o]=null,i}function s(e){(window.requestAnimationFrame||window.setTimeout)(e)}function p(e,t){if(void 0===t&&(t=document),e){if(e.nodeType)return[e];if("string"==typeof e)return[].slice.call(t.querySelectorAll(e));if(e.length)return[].slice.call(e)}return[]}var d="data-@nrk/core-input-1.3.0".replace(/\W+/g,"-"),f=13,v=27,h=33,m=34,b=35,g=36,x=38,y=40,E='[tabindex="-1"]',A=500;function w(e,t){var o="object"==typeof t?t:{content:t},i="string"==typeof o.content;return p(e).map(function(e){var t=e.nextElementSibling,n=void 0===o.ajax?e.getAttribute(d):o.ajax,r=void 0===o.open?e===document.activeElement:o.open;return e.setAttribute(d,n||""),e.setAttribute(a?"data-role":"role","combobox"),e.setAttribute("aria-autocomplete","list"),e.setAttribute("autocomplete","off"),i&&(t.innerHTML=o.content),p("a,button",t).forEach(L),C(e,r),e})}function S(a){a.ctrlKey||a.altKey||a.metaKey||a.defaultPrevented||p("["+d+"]").forEach(function(e){var t,n,r=e.nextElementSibling,o=e===a.target||r.contains(a.target),i="click"===a.type&&o&&p(E,r).filter(function(e){return e.contains(a.target)})[0];i?(t=e,n={relatedTarget:r,currentTarget:i,value:i.value||i.textContent.trim()},c(t,"input.select",n)&&(t.value=n.value,t.focus(),s(function(){return C(t,!1)}))):C(e,o)})}function j(e,t){var n=e.nextElementSibling,r=[e].concat(p(E+":not([hidden])",n)),o=t.keyCode===v&&"true"===e.getAttribute("aria-expanded"),i=r.indexOf(document.activeElement),a=!1;t.keyCode===y?a=r[i+1]||r[0]:t.keyCode===x?a=r[i-1]||r.pop():n.contains(t.target)&&(t.keyCode===b||t.keyCode===m?a=r.pop():t.keyCode===g||t.keyCode===h?a=r[1]:t.keyCode!==f&&e.focus()),C(e,t.keyCode!==v),(!1!==a||o)&&t.preventDefault(),a&&a.focus()}function C(e,t){void 0===t&&(t="true"===e.getAttribute("aria-expanded")),s(function(){e.nextElementSibling[t?"removeAttribute":"setAttribute"]("hidden",""),e.setAttribute("aria-expanded",t)})}function L(e,t,n){e.setAttribute("aria-label",e.textContent.trim()+", "+(t+1)+" av "+n.length),e.setAttribute("tabindex","-1"),e.setAttribute("type","button")}function k(e){var t=e.getAttribute(d),n=k.xhr=k.xhr||new window.XMLHttpRequest;if(!t)return!1;clearTimeout(k.timer),n.abort(),n.onload=function(){try{n.responseJSON=JSON.parse(n.responseText)}catch(e){n.responseJSON=!1}c(e,"input.ajax",n)},k.timer=setTimeout(function(){e.value&&c(e,"input.ajax.beforeSend",n)&&(n.open("GET",t.replace("{{value}}",window.encodeURIComponent(e.value)),!0),n.setRequestHeader("X-Requested-With","XMLHttpRequest"),n.send())},A)}w.escapeHTML=u,w.highlight=function(e,t){var n=t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&");return u(e).replace(new RegExp(n||".^","gi"),"<mark>$&</mark>")},n(d,"click",S),n(d,"focus",S,!0),n(d,"input",function(e){var i,t,n=e.target;n.hasAttribute(d)&&(t={relatedTarget:(i=n).nextElementSibling},c(i,"input.filter",t)&&!1===k(i)&&p(E,i.nextElementSibling).reduce(function(e,t){var n="LI"===t.parentElement.nodeName&&t.parentElement,r=-1!==t.textContent.toLowerCase().indexOf(i.value.toLowerCase()),o=r?"removeAttribute":"setAttribute";return n&&n[o]("hidden",""),t[o]("hidden",""),r?e.concat(t):e},[]).forEach(L))}),n(d,"keydown",function(e){if(!(e.ctrlKey||e.altKey||e.metaKey)){if(e.target.hasAttribute&&e.target.hasAttribute(d))return j(e.target,e);for(var t=e.target,n=void 0;t;t=t.parentElement)if((n=t.previousElementSibling)&&n.hasAttribute(d))return j(n,e)}},!0);var T=function(n){function t(e){var t=this;n.call(this,e),this.onFilter=function(e){return t.props.onFilter&&t.props.onFilter(e)},this.onSelect=function(e){return t.props.onSelect&&t.props.onSelect(e)},this.onAjaxBeforeSend=function(e){return t.props.onAjaxBeforeSend&&t.props.onAjaxBeforeSend(e)},this.onAjax=function(e){return t.props.onAjax&&t.props.onAjax(e)}}n&&(t.__proto__=n),(t.prototype=Object.create(n&&n.prototype)).constructor=t;var e={defaultProps:{configurable:!0}};return e.defaultProps.get=function(){return{open:null,ajax:null,onAjax:null,onAjaxBeforeSend:null,onFilter:null,onSelect:null}},t.prototype.componentDidMount=function(){this.el.addEventListener("input.filter",this.onFilter),this.el.addEventListener("input.select",this.onSelect),this.el.addEventListener("input.ajax.beforeSend",this.onAjaxBeforeSend),this.el.addEventListener("input.ajax",this.onAjax),w(this.el.firstElementChild,this.props)},t.prototype.componentDidUpdate=function(){w(this.el.firstElementChild)},t.prototype.componentWillUnmount=function(){this.el.removeEventListener("input.filter",this.onFilter),this.el.removeEventListener("input.select",this.onSelect),this.el.removeEventListener("input.beforeSend",this.onAjaxBeforeSend),this.el.removeEventListener("input.ajax",this.onAjax)},t.prototype.render=function(){var n,r,e,o=this;return i.createElement("div",(n=this.props,r=t.defaultProps,void 0===(e={ref:function(e){return o.el=e}})&&(e={}),Object.keys(n).reduce(function(e,t){return r.hasOwnProperty(t)||(e[t]=n[t]),e},e)),i.Children.map(this.props.children,function(e,t){return 0===t?i.cloneElement(e,{"aria-expanded":String(Boolean(o.props.open))}):1===t?i.cloneElement(e,{hidden:!o.props.open}):e}))},Object.defineProperties(t,e),t}(i.Component);return T.Highlight=function(e){var t=e.text,n=e.query;return void 0===n&&(n=""),i.createElement("span",{dangerouslySetInnerHTML:{__html:w.highlight(t,n)}})},T.propTypes={onFilter:e.func,onSelect:e.func,onAjax:e.func,open:e.bool,ajax:e.oneOfType([e.string,e.object])},T}); | ||
//# sourceMappingURL=core-input.jsx.js.map |
@@ -1,3 +0,3 @@ | ||
/*! @nrk/core-input v1.2.2 - Copyright (c) 2017-2019 NRK */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).coreInput=t()}(this,function(){"use strict";var e="undefined"!=typeof window,a=(e&&/(android)/i.test(navigator.userAgent),e&&/iPad|iPhone|iPod/.test(String(navigator.platform))),i=function(e){void 0===e&&(e=!1);try{window.addEventListener("test",null,{get passive(){e=!0}})}catch(e){}return e}();function t(e,t,n,r){(void 0===r&&(r=!1),"undefined"==typeof window||window[e=e+"-"+t])||(i||"object"!=typeof r||(r=Boolean(r.capture)),("resize"===t||"load"===t?window:document).addEventListener(window[e]=t,n,r))}var n={"&":"&","<":"<",">":">",'"':""","/":"/","'":"'"};function r(e){return String(e||"").replace(/[&<>"'/]/g,function(e){return n[e]})}var u="prevent_recursive_dispatch_maximum_callstack";function c(e,t,n){void 0===n&&(n={});var r,i=""+u+t;if(e[i])return!0;e[i]=!0,"function"==typeof window.CustomEvent?r=new window.CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n}):(r=document.createEvent("CustomEvent")).initCustomEvent(t,!0,!0,n);var o=e.dispatchEvent(r);return e[i]=null,o}function d(e,t){if(void 0===t&&(t=document),e){if(e.nodeType)return[e];if("string"==typeof e)return[].slice.call(t.querySelectorAll(e));if(e.length)return[].slice.call(e)}return[]}var l="data-@nrk/core-input-1.2.2".replace(/\W+/g,"-"),s=13,f=27,p=33,v=34,m=35,b=36,g=38,y=40,w='[tabindex="-1"]',o=500;function x(e,t){var i="object"==typeof t?t:{content:t},o="string"==typeof i.content;return d(e).map(function(e){var t=e.nextElementSibling,n=void 0===i.ajax?e.getAttribute(l):i.ajax,r=void 0===i.open?e===document.activeElement:i.open;return e.setAttribute(l,n||""),e.setAttribute(a?"data-role":"role","combobox"),e.setAttribute("aria-autocomplete","list"),e.setAttribute("autocomplete","off"),o&&(t.innerHTML=i.content),d("a,button",t).forEach(C),A(e,r),e})}function h(a){a.ctrlKey||a.altKey||a.metaKey||a.defaultPrevented||d("["+l+"]").forEach(function(e){var t,n,r=e.nextElementSibling,i=e===a.target||r.contains(a.target),o="click"===a.type&&i&&d(w,r).filter(function(e){return e.contains(a.target)})[0];o?(t=e,n={relatedTarget:r,currentTarget:o,value:o.value||o.textContent.trim()},c(t,"input.select",n)&&(t.value=n.value,t.focus(),A(t,!1))):A(e,i)})}function E(e,t){var n=e.nextElementSibling,r=[e].concat(d(w+":not([hidden])",n)),i=t.keyCode===f&&"true"===e.getAttribute("aria-expanded"),o=r.indexOf(document.activeElement),a=!1;t.keyCode===y?a=r[o+1]||r[0]:t.keyCode===g?a=r[o-1]||r.pop():n.contains(t.target)&&(t.keyCode===m||t.keyCode===v?a=r.pop():t.keyCode===b||t.keyCode===p?a=r[1]:t.keyCode!==s&&e.focus()),A(e,t.keyCode!==f),(!1!==a||i)&&t.preventDefault(),a&&a.focus()}function A(e,t){var n;void 0===t&&(t="true"===e.getAttribute("aria-expanded")),n=function(){e.nextElementSibling[t?"removeAttribute":"setAttribute"]("hidden",""),e.setAttribute("aria-expanded",t)},(window.requestAnimationFrame||window.setTimeout)(n)}function C(e,t,n){e.setAttribute("aria-label",e.textContent.trim()+", "+(t+1)+" av "+n.length),e.setAttribute("tabindex","-1"),e.setAttribute("type","button")}function k(e){var t=e.getAttribute(l),n=k.xhr=k.xhr||new window.XMLHttpRequest;if(!t)return!1;clearTimeout(k.timer),n.abort(),n.onload=function(){try{n.responseJSON=JSON.parse(n.responseText)}catch(e){n.responseJSON=!1}c(e,"input.ajax",n)},k.timer=setTimeout(function(){e.value&&c(e,"input.ajax.beforeSend",n)&&(n.open("GET",t.replace("{{value}}",window.encodeURIComponent(e.value)),!0),n.setRequestHeader("X-Requested-With","XMLHttpRequest"),n.send())},o)}return x.escapeHTML=r,x.highlight=function(e,t){var n=t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&");return r(e).replace(new RegExp(n||".^","gi"),"<mark>$&</mark>")},t(l,"click",h),t(l,"focus",h,!0),t(l,"input",function(e){var o,t,n=e.target;n.hasAttribute(l)&&(t={relatedTarget:(o=n).nextElementSibling},c(o,"input.filter",t)&&!1===k(o)&&d(w,o.nextElementSibling).reduce(function(e,t){var n="LI"===t.parentElement.nodeName&&t.parentElement,r=-1!==t.textContent.toLowerCase().indexOf(o.value.toLowerCase()),i=r?"removeAttribute":"setAttribute";return n&&n[i]("hidden",""),t[i]("hidden",""),r?e.concat(t):e},[]).forEach(C))}),t(l,"keydown",function(e){if(!(e.ctrlKey||e.altKey||e.metaKey)){if(e.target.hasAttribute&&e.target.hasAttribute(l))return E(e.target,e);for(var t=e.target,n=void 0;t;t=t.parentElement)if((n=t.previousElementSibling)&&n.hasAttribute(l))return E(n,e)}},!0),x}); | ||
/*! @nrk/core-input v1.3.0 - Copyright (c) 2017-2019 NRK */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).coreInput=t()}(this,function(){"use strict";var e="undefined"!=typeof window,a=(e&&/(android)/i.test(navigator.userAgent),e&&/iPad|iPhone|iPod/.test(String(navigator.platform))),i=function(e){void 0===e&&(e=!1);try{window.addEventListener("test",null,{get passive(){e=!0}})}catch(e){}return e}();function t(e,t,n,r){(void 0===r&&(r=!1),"undefined"==typeof window||window[e=e+"-"+t])||(i||"object"!=typeof r||(r=Boolean(r.capture)),("resize"===t||"load"===t?window:document).addEventListener(window[e]=t,n,r))}var n={"&":"&","<":"<",">":">",'"':""","/":"/","'":"'"};function r(e){return String(e||"").replace(/[&<>"'/]/g,function(e){return n[e]})}var u="prevent_recursive_dispatch_maximum_callstack";function c(e,t,n){void 0===n&&(n={});var r,i=""+u+t;if(e[i])return!0;e[i]=!0,"function"==typeof window.CustomEvent?r=new window.CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n}):(r=document.createEvent("CustomEvent")).initCustomEvent(t,!0,!0,n);var o=e.dispatchEvent(r);return e[i]=null,o}function d(e){(window.requestAnimationFrame||window.setTimeout)(e)}function l(e,t){if(void 0===t&&(t=document),e){if(e.nodeType)return[e];if("string"==typeof e)return[].slice.call(t.querySelectorAll(e));if(e.length)return[].slice.call(e)}return[]}var f="data-@nrk/core-input-1.3.0".replace(/\W+/g,"-"),s=13,p=27,v=33,m=34,b=35,g=36,y=38,w=40,x='[tabindex="-1"]',o=500;function h(e,t){var i="object"==typeof t?t:{content:t},o="string"==typeof i.content;return l(e).map(function(e){var t=e.nextElementSibling,n=void 0===i.ajax?e.getAttribute(f):i.ajax,r=void 0===i.open?e===document.activeElement:i.open;return e.setAttribute(f,n||""),e.setAttribute(a?"data-role":"role","combobox"),e.setAttribute("aria-autocomplete","list"),e.setAttribute("autocomplete","off"),o&&(t.innerHTML=i.content),l("a,button",t).forEach(k),C(e,r),e})}function E(a){a.ctrlKey||a.altKey||a.metaKey||a.defaultPrevented||l("["+f+"]").forEach(function(e){var t,n,r=e.nextElementSibling,i=e===a.target||r.contains(a.target),o="click"===a.type&&i&&l(x,r).filter(function(e){return e.contains(a.target)})[0];o?(t=e,n={relatedTarget:r,currentTarget:o,value:o.value||o.textContent.trim()},c(t,"input.select",n)&&(t.value=n.value,t.focus(),d(function(){return C(t,!1)}))):C(e,i)})}function A(e,t){var n=e.nextElementSibling,r=[e].concat(l(x+":not([hidden])",n)),i=t.keyCode===p&&"true"===e.getAttribute("aria-expanded"),o=r.indexOf(document.activeElement),a=!1;t.keyCode===w?a=r[o+1]||r[0]:t.keyCode===y?a=r[o-1]||r.pop():n.contains(t.target)&&(t.keyCode===b||t.keyCode===m?a=r.pop():t.keyCode===g||t.keyCode===v?a=r[1]:t.keyCode!==s&&e.focus()),C(e,t.keyCode!==p),(!1!==a||i)&&t.preventDefault(),a&&a.focus()}function C(e,t){void 0===t&&(t="true"===e.getAttribute("aria-expanded")),d(function(){e.nextElementSibling[t?"removeAttribute":"setAttribute"]("hidden",""),e.setAttribute("aria-expanded",t)})}function k(e,t,n){e.setAttribute("aria-label",e.textContent.trim()+", "+(t+1)+" av "+n.length),e.setAttribute("tabindex","-1"),e.setAttribute("type","button")}function S(e){var t=e.getAttribute(f),n=S.xhr=S.xhr||new window.XMLHttpRequest;if(!t)return!1;clearTimeout(S.timer),n.abort(),n.onload=function(){try{n.responseJSON=JSON.parse(n.responseText)}catch(e){n.responseJSON=!1}c(e,"input.ajax",n)},S.timer=setTimeout(function(){e.value&&c(e,"input.ajax.beforeSend",n)&&(n.open("GET",t.replace("{{value}}",window.encodeURIComponent(e.value)),!0),n.setRequestHeader("X-Requested-With","XMLHttpRequest"),n.send())},o)}return h.escapeHTML=r,h.highlight=function(e,t){var n=t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&");return r(e).replace(new RegExp(n||".^","gi"),"<mark>$&</mark>")},t(f,"click",E),t(f,"focus",E,!0),t(f,"input",function(e){var o,t,n=e.target;n.hasAttribute(f)&&(t={relatedTarget:(o=n).nextElementSibling},c(o,"input.filter",t)&&!1===S(o)&&l(x,o.nextElementSibling).reduce(function(e,t){var n="LI"===t.parentElement.nodeName&&t.parentElement,r=-1!==t.textContent.toLowerCase().indexOf(o.value.toLowerCase()),i=r?"removeAttribute":"setAttribute";return n&&n[i]("hidden",""),t[i]("hidden",""),r?e.concat(t):e},[]).forEach(k))}),t(f,"keydown",function(e){if(!(e.ctrlKey||e.altKey||e.metaKey)){if(e.target.hasAttribute&&e.target.hasAttribute(f))return A(e.target,e);for(var t=e.target,n=void 0;t;t=t.parentElement)if((n=t.previousElementSibling)&&n.hasAttribute(f))return A(n,e)}},!0),h}); | ||
//# sourceMappingURL=core-input.min.js.map |
@@ -9,3 +9,3 @@ 'use strict'; | ||
var name = "@nrk/core-input"; | ||
var version = "1.2.2"; | ||
var version = "1.3.0"; | ||
@@ -205,3 +205,3 @@ var IS_BROWSER = typeof window !== 'undefined'; | ||
input.focus(); | ||
setupExpand(input, false); | ||
requestAnimFrame(function () { return setupExpand(input, false); }); // Let IE11 finish focus event bubbling | ||
} | ||
@@ -208,0 +208,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "NRK <opensource@nrk.no> (https://www.nrk.no/)", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "core-input.cjs.js", |
@@ -14,7 +14,5 @@ # Core Input | ||
import coreInput from '@nrk/core-input' // Vanilla JS | ||
import CoreInput from '@nrk/core-input/jsx' // ...or React/Preact compatible JSX | ||
import CoreInput from '@nrk/core-input/jsx' // React/Preact JSX | ||
``` | ||
<!--demo | ||
@@ -28,4 +26,2 @@ <script src="core-input/core-input.min.js"></script> | ||
Typing toggles the [hidden attribute](https://developer.mozilla.org/en/docs/Web/HTML/Global_attributes/hidden) on items of type `<button>` and `<a>`, based on matching [textContent](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent). The default filtering behavior can easily be altered through the `'input.select'` and `'input.filter'` [events](#events). | ||
```html | ||
@@ -67,9 +63,12 @@ <!--demo--> | ||
Typing toggles the [hidden attribute](https://developer.mozilla.org/en/docs/Web/HTML/Global_attributes/hidden) on items of type `<button>` and `<a>`, based on matching [textContent](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent). Focusing the input unhides the following element. The default filtering behavior can easily be altered through the The default filtering behavior can easily be altered through the `'input.select'`, `'input.filter'`, `'input.ajax'` and `'input.ajax.beforeSend'` [events](#events). | ||
Results will be rendered in the element directly after the `<input>`. | ||
Always use `coreInput.escapeHTML(String)` to safely render data from API or user. | ||
### HTML / JavaScript | ||
<small><b>Important:</b> Always use `coreInput.escapeHTML(String)` to safely render data from API or user.</small> | ||
<small><b>Important:</b> Results will always be rendered in the element directly after the `<input>`</small> | ||
```html | ||
<input type="text" class="my-input"> <!-- Input element must be a <input> --> | ||
<input type="text" class="my-input"> <!-- Input element must be a textual <input> --> | ||
<ul hidden> <!-- Can be any tag, but items should be inside <li> --> | ||
@@ -85,8 +84,8 @@ <li><button>Item 1</button></li> <!-- Items must be <button> or <a> --> | ||
coreInput(String|Element|Elements, { // Accepts a selector string, NodeList, Element or array of Elements | ||
open: null, // Optional. Defaults to value of aria-expanded. Use true|false to force open state | ||
content: null, // Optional. Set String of HTML content. HTML is used for full flexibility on markup | ||
ajax: null // Optional. Fetch external data, example: "https://search.com?q={{value}}" | ||
open: Boolean, // Optional. Defaults to value of aria-expanded. Use to force open state | ||
content: String, // Optional. Set String of HTML content. HTML is used for full flexibility on markup | ||
ajax: String // Optional. Fetch external data, example: "https://search.com?q={{value}}" | ||
}) | ||
// Helpers: | ||
// Passing a string as second argument sets the 'content' option | ||
coreInput('.my-input', '<li><a href="?q=' + coreInput.escapeHTML(input.value) + '">More results</a></li>') // escape html | ||
@@ -98,4 +97,2 @@ coreInput('.my-input', '<li><button>' + coreInput.highlight(item.text, input.value) + '</button></li>') // highlight match | ||
<small><b>Important:</b> First direct of `<CoreToggle>` must be a `<input>` and next direct child will be used for results</small> | ||
```js | ||
@@ -106,8 +103,8 @@ import CoreInput from '@nrk/core-input/jsx' | ||
// Props like className, style, etc. will be applied as actual attributes | ||
// <Input> will handle state itself unless you call event.preventDefault() in onFilter or onSelect | ||
// <CoreInput> will handle state itself unless you call event.preventDefault() in onFilter, onSelect or onAjax | ||
<CoreInput open={false} onFilter={(event) => {}} onSelect={(event) => {}} onAjax={(event) => {}} onAjaxBeforeSend={(event) => {}} ajax="https://search.com?q={{value}}"> | ||
<input type="text" /> <!-- First element must result in a input-tag. Accepts both elements and components --> | ||
<input type="text" /> // First element must result in a input-tag. Accepts both elements and components | ||
<ul> // Next element will be used for items. Accepts both elements and components | ||
<li><button>Item 1</button></li> <!-- Interactive items must be <button> or <a> --> | ||
<li><button>Item 1</button></li> // Interactive items must be <button> or <a> | ||
<li><button value="Suprise!">Item 2</button></li> // Alternative value can be defined | ||
@@ -198,8 +195,8 @@ <li><a href="https://www.nrk.no/">NRK.no</a></li> // Actual links are recommended when applicable | ||
## Ajax | ||
## Notes | ||
### Ajax | ||
When using `@nrk/core-input` with the `ajax: https://search.com?q={{value}}` functionality, make sure to implement both a `Searching...` status (while fetching data from the server), and a `No hits` status (if server responds with no results). These status indicators are highly recommended, but not provided by default as the context of use will affect the optimal textual formulation. [See example implementation →](#demo-ajax) | ||
### Customise the request | ||
If you need to alter default headers, request method or post data, use the [`input.ajax.beforeSend` event →](#input-ajax-beforesend) | ||
@@ -206,0 +203,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
113088
13
413
1