@nrk/core-input
Advanced tools
Comparing version 1.4.1 to 1.4.2
'use strict'; | ||
var name = "@nrk/core-input"; | ||
var version = "1.4.1"; | ||
var version = "1.4.2"; | ||
@@ -96,3 +96,3 @@ var IS_BROWSER = typeof window !== 'undefined'; | ||
var UUID = ("data-" + name + "-" + version).replace(/\W+/g, '-'); // Strip invalid attribute characters | ||
var UUID = ("data-" + name + "-" + version).replace(/\W+/g, '-'); | ||
var KEYS = { ENTER: 13, ESC: 27, PAGEUP: 33, PAGEDOWN: 34, END: 35, HOME: 36, UP: 38, DOWN: 40 }; | ||
@@ -104,3 +104,2 @@ var AJAX_DEBOUNCE = 500; | ||
var repaint = typeof options.content === 'string'; | ||
var limit = Math.max(options.limit, 0) || 0; | ||
@@ -110,2 +109,3 @@ return queryAll(elements).map(function (input) { | ||
var ajax = typeof options.ajax === 'undefined' ? input.getAttribute(UUID) : options.ajax; | ||
var limit = typeof options.limit === 'undefined' ? input.getAttribute((UUID + "-limit")) : Math.max(options.limit || 0, 0); | ||
var open = typeof options.open === 'undefined' ? input === document.activeElement : options.open; | ||
@@ -112,0 +112,0 @@ |
import { name, version } from './package.json' | ||
import { IS_IOS, addEvent, escapeHTML, dispatchEvent, requestAnimFrame, queryAll } from '../utils' | ||
const UUID = `data-${name}-${version}`.replace(/\W+/g, '-') // Strip invalid attribute characters | ||
const UUID = `data-${name}-${version}`.replace(/\W+/g, '-') | ||
const KEYS = { ENTER: 13, ESC: 27, PAGEUP: 33, PAGEDOWN: 34, END: 35, HOME: 36, UP: 38, DOWN: 40 } | ||
@@ -11,3 +11,2 @@ const AJAX_DEBOUNCE = 500 | ||
const repaint = typeof options.content === 'string' | ||
const limit = Math.max(options.limit, 0) || 0 | ||
@@ -17,2 +16,3 @@ return queryAll(elements).map((input) => { | ||
const ajax = typeof options.ajax === 'undefined' ? input.getAttribute(UUID) : options.ajax | ||
const limit = typeof options.limit === 'undefined' ? input.getAttribute(`${UUID}-limit`) : Math.max(options.limit || 0, 0) | ||
const open = typeof options.open === 'undefined' ? input === document.activeElement : options.open | ||
@@ -19,0 +19,0 @@ |
@@ -1,3 +0,3 @@ | ||
/*! @nrk/core-input v1.4.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,u=(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 a(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 p(e){(window.requestAnimationFrame||window.setTimeout)(e)}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 d="data-@nrk/core-input-1.4.1".replace(/\W+/g,"-"),f=13,m=27,v=33,h=34,b=35,g=36,x=38,y=40,E=500;function A(e,t){var o="object"==typeof t?t:{content:t},i="string"==typeof o.content,a=Math.max(o.limit,0)||0;return s(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(d+"-limit",a),e.setAttribute(u?"data-role":"role","combobox"),e.setAttribute("aria-autocomplete","list"),e.setAttribute("autocomplete","off"),i&&(t.innerHTML=o.content),s("a,button",t).forEach(function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];return C.apply(void 0,[a].concat(e))}),j(e,r),e})}function w(a){a.ctrlKey||a.altKey||a.metaKey||a.defaultPrevented||s("["+d+"]").forEach(function(e){var t,n,r=e.nextElementSibling,o=e===a.target||r.contains(a.target),i="click"===a.type&&o&&s('[tabindex="-1"]',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(),p(function(){return j(t,!1)}))):j(e,o)})}function S(e,t){var n=e.nextElementSibling,r=[e].concat(s('[tabindex="-1"]:not([hidden])',n)),o=t.keyCode===m&&"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===h?a=r.pop():t.keyCode===g||t.keyCode===v?a=r[1]:t.keyCode!==f&&e.focus()),j(e,t.keyCode!==m),(!1!==a||o)&&t.preventDefault(),a&&a.focus()}function j(e,t){void 0===t&&(t="true"===e.getAttribute("aria-expanded")),p(function(){e.nextElementSibling[t?"removeAttribute":"setAttribute"]("hidden",""),e.setAttribute("aria-expanded",t)})}function C(e,t,n,r){t.setAttribute("aria-label",t.textContent.trim()+", "+(n+1)+" av "+r.length),t.setAttribute("tabindex","-1"),t.setAttribute("type","button"),e&&e<=n&&t.parentElement.setAttribute("hidden","")}function L(e){var t=e.getAttribute(d),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=a,A.highlight=function(e,t){var n=t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&");return a(e).replace(new RegExp(n||".^","gi"),"<mark>$&</mark>")},n(d,"click",w),n(d,"focus",w,!0),n(d,"input",function(e){var a,t,n,r=e.target;r.hasAttribute(d)&&(t={relatedTarget:(a=r).nextElementSibling},n=Number(a.getAttribute(d+"-limit"))||1/0,c(a,"input.filter",t)&&!1===L(a)&&s('[tabindex="-1"]',a.nextElementSibling).reduce(function(e,t,n){var r="LI"===t.parentElement.nodeName&&t.parentElement,o=-1!==t.textContent.toLowerCase().indexOf(a.value.toLowerCase()),i=o?"removeAttribute":"setAttribute";return r&&r[i]("hidden",""),t[i]("hidden",""),o?e.concat(t):e},[]).forEach(function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];return C.apply(void 0,[n].concat(e))}))}),n(d,"keydown",function(e){if(!(e.ctrlKey||e.altKey||e.metaKey)){if(e.target.hasAttribute&&e.target.hasAttribute(d))return S(e.target,e);for(var t=e.target,n=void 0;t;t=t.parentElement)if((n=t.previousElementSibling)&&n.hasAttribute(d))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,limit: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,limit:e.number,ajax:e.oneOfType([e.string,e.object])},k}); | ||
/*! @nrk/core-input v1.4.1 - 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(o,e){"use strict";o=o&&o.hasOwnProperty("default")?o.default:o,e=e&&e.hasOwnProperty("default")?e.default:e;var t="undefined"!=typeof window,u=(t&&/(android)/i.test(navigator.userAgent),t&&/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 n(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 r={"&":"&","<":"<",">":">",'"':""","/":"/","'":"'"};function a(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,i=""+l+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 p(e){(window.requestAnimationFrame||window.setTimeout)(e)}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 d="data-@nrk/core-input-1.4.2".replace(/\W+/g,"-"),f=13,m=27,v=33,h=34,b=35,g=36,x=38,y=40,A=500;function E(e,t){var o="object"==typeof t?t:{content:t},a="string"==typeof o.content;return s(e).map(function(e){var t=e.nextElementSibling,n=void 0===o.ajax?e.getAttribute(d):o.ajax,r=void 0===o.limit?e.getAttribute(d+"-limit"):Math.max(o.limit||0,0),i=void 0===o.open?e===document.activeElement:o.open;return e.setAttribute(d,n||""),e.setAttribute(d+"-limit",r),e.setAttribute(u?"data-role":"role","combobox"),e.setAttribute("aria-autocomplete","list"),e.setAttribute("autocomplete","off"),a&&(t.innerHTML=o.content),s("a,button",t).forEach(function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];return C.apply(void 0,[r].concat(e))}),j(e,i),e})}function w(a){a.ctrlKey||a.altKey||a.metaKey||a.defaultPrevented||s("["+d+"]").forEach(function(e){var t,n,r=e.nextElementSibling,i=e===a.target||r.contains(a.target),o="click"===a.type&&i&&s('[tabindex="-1"]',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(),p(function(){return j(t,!1)}))):j(e,i)})}function S(e,t){var n=e.nextElementSibling,r=[e].concat(s('[tabindex="-1"]:not([hidden])',n)),i=t.keyCode===m&&"true"===e.getAttribute("aria-expanded"),o=r.indexOf(document.activeElement),a=!1;t.keyCode===y?a=r[o+1]||r[0]:t.keyCode===x?a=r[o-1]||r.pop():n.contains(t.target)&&(t.keyCode===b||t.keyCode===h?a=r.pop():t.keyCode===g||t.keyCode===v?a=r[1]:t.keyCode!==f&&e.focus()),j(e,t.keyCode!==m),(!1!==a||i)&&t.preventDefault(),a&&a.focus()}function j(e,t){void 0===t&&(t="true"===e.getAttribute("aria-expanded")),p(function(){e.nextElementSibling[t?"removeAttribute":"setAttribute"]("hidden",""),e.setAttribute("aria-expanded",t)})}function C(e,t,n,r){t.setAttribute("aria-label",t.textContent.trim()+", "+(n+1)+" av "+r.length),t.setAttribute("tabindex","-1"),t.setAttribute("type","button"),e&&e<=n&&t.parentElement.setAttribute("hidden","")}function L(e){var t=e.getAttribute(d),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())},A)}E.escapeHTML=a,E.highlight=function(e,t){var n=t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&");return a(e).replace(new RegExp(n||".^","gi"),"<mark>$&</mark>")},n(d,"click",w),n(d,"focus",w,!0),n(d,"input",function(e){var a,t,n,r=e.target;r.hasAttribute(d)&&(t={relatedTarget:(a=r).nextElementSibling},n=Number(a.getAttribute(d+"-limit"))||1/0,c(a,"input.filter",t)&&!1===L(a)&&s('[tabindex="-1"]',a.nextElementSibling).reduce(function(e,t,n){var r="LI"===t.parentElement.nodeName&&t.parentElement,i=-1!==t.textContent.toLowerCase().indexOf(a.value.toLowerCase()),o=i?"removeAttribute":"setAttribute";return r&&r[o]("hidden",""),t[o]("hidden",""),i?e.concat(t):e},[]).forEach(function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];return C.apply(void 0,[n].concat(e))}))}),n(d,"keydown",function(e){if(!(e.ctrlKey||e.altKey||e.metaKey)){if(e.target.hasAttribute&&e.target.hasAttribute(d))return S(e.target,e);for(var t=e.target,n=void 0;t;t=t.parentElement)if((n=t.previousElementSibling)&&n.hasAttribute(d))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,limit: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),E(this.el.firstElementChild,this.props)},t.prototype.componentDidUpdate=function(){E(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,i=this;return o.createElement("div",(n=this.props,r=t.defaultProps,void 0===(e={ref:function(e){return i.el=e}})&&(e={}),Object.keys(n).reduce(function(e,t){return r.hasOwnProperty(t)||(e[t]=n[t]),e},e)),o.Children.map(this.props.children,function(e,t){return 0===t?o.cloneElement(e,{"aria-expanded":String(Boolean(i.props.open))}):1===t?o.cloneElement(e,{hidden:!i.props.open}):e}))},Object.defineProperties(t,e),t}(o.Component);return k.Highlight=function(e){var t=e.text,n=e.query;return void 0===n&&(n=""),o.createElement("span",{dangerouslySetInnerHTML:{__html:E.highlight(t,n)}})},k.propTypes={onFilter:e.func,onSelect:e.func,onAjax:e.func,open:e.bool,limit:e.number,ajax:e.oneOfType([e.string,e.object])},k}); | ||
//# sourceMappingURL=core-input.jsx.js.map |
@@ -1,3 +0,3 @@ | ||
/*! @nrk/core-input v1.4.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,u=(e&&/(android)/i.test(navigator.userAgent),e&&/iPad|iPhone|iPod/.test(String(navigator.platform))),r=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,i){(void 0===i&&(i=!1),"undefined"==typeof window||window[e=e+"-"+t])||(r||"object"!=typeof i||(i=Boolean(i.capture)),("resize"===t||"load"===t?window:document).addEventListener(window[e]=t,n,i))}var n={"&":"&","<":"<",">":">",'"':""","/":"/","'":"'"};function i(e){return String(e||"").replace(/[&<>"'/]/g,function(e){return n[e]})}var a="prevent_recursive_dispatch_maximum_callstack";function c(e,t,n){void 0===n&&(n={});var i,r=""+a+t;if(e[r])return!0;e[r]=!0,"function"==typeof window.CustomEvent?i=new window.CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n}):(i=document.createEvent("CustomEvent")).initCustomEvent(t,!0,!0,n);var o=e.dispatchEvent(i);return e[r]=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.4.1".replace(/\W+/g,"-"),s=13,p=27,m=33,v=34,b=35,g=36,y=38,x=40,o=500;function w(e,t){var r="object"==typeof t?t:{content:t},o="string"==typeof r.content,a=Math.max(r.limit,0)||0;return l(e).map(function(e){var t=e.nextElementSibling,n=void 0===r.ajax?e.getAttribute(f):r.ajax,i=void 0===r.open?e===document.activeElement:r.open;return e.setAttribute(f,n||""),e.setAttribute(f+"-limit",a),e.setAttribute(u?"data-role":"role","combobox"),e.setAttribute("aria-autocomplete","list"),e.setAttribute("autocomplete","off"),o&&(t.innerHTML=r.content),l("a,button",t).forEach(function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];return C.apply(void 0,[a].concat(e))}),E(e,i),e})}function h(a){a.ctrlKey||a.altKey||a.metaKey||a.defaultPrevented||l("["+f+"]").forEach(function(e){var t,n,i=e.nextElementSibling,r=e===a.target||i.contains(a.target),o="click"===a.type&&r&&l('[tabindex="-1"]',i).filter(function(e){return e.contains(a.target)})[0];o?(t=e,n={relatedTarget:i,currentTarget:o,value:o.value||o.textContent.trim()},c(t,"input.select",n)&&(t.value=n.value,t.focus(),d(function(){return E(t,!1)}))):E(e,r)})}function A(e,t){var n=e.nextElementSibling,i=[e].concat(l('[tabindex="-1"]:not([hidden])',n)),r=t.keyCode===p&&"true"===e.getAttribute("aria-expanded"),o=i.indexOf(document.activeElement),a=!1;t.keyCode===x?a=i[o+1]||i[0]:t.keyCode===y?a=i[o-1]||i.pop():n.contains(t.target)&&(t.keyCode===b||t.keyCode===v?a=i.pop():t.keyCode===g||t.keyCode===m?a=i[1]:t.keyCode!==s&&e.focus()),E(e,t.keyCode!==p),(!1!==a||r)&&t.preventDefault(),a&&a.focus()}function E(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 C(e,t,n,i){t.setAttribute("aria-label",t.textContent.trim()+", "+(n+1)+" av "+i.length),t.setAttribute("tabindex","-1"),t.setAttribute("type","button"),e&&e<=n&&t.parentElement.setAttribute("hidden","")}function k(e){var t=e.getAttribute(f),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 w.escapeHTML=i,w.highlight=function(e,t){var n=t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&");return i(e).replace(new RegExp(n||".^","gi"),"<mark>$&</mark>")},t(f,"click",h),t(f,"focus",h,!0),t(f,"input",function(e){var a,t,n,i=e.target;i.hasAttribute(f)&&(t={relatedTarget:(a=i).nextElementSibling},n=Number(a.getAttribute(f+"-limit"))||1/0,c(a,"input.filter",t)&&!1===k(a)&&l('[tabindex="-1"]',a.nextElementSibling).reduce(function(e,t,n){var i="LI"===t.parentElement.nodeName&&t.parentElement,r=-1!==t.textContent.toLowerCase().indexOf(a.value.toLowerCase()),o=r?"removeAttribute":"setAttribute";return i&&i[o]("hidden",""),t[o]("hidden",""),r?e.concat(t):e},[]).forEach(function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];return C.apply(void 0,[n].concat(e))}))}),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),w}); | ||
/*! @nrk/core-input v1.4.1 - Copyright (c) 2017-2019 NRK */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).coreInput=e()}(this,function(){"use strict";var t="undefined"!=typeof window,u=(t&&/(android)/i.test(navigator.userAgent),t&&/iPad|iPhone|iPod/.test(String(navigator.platform))),r=function(t){void 0===t&&(t=!1);try{window.addEventListener("test",null,{get passive(){t=!0}})}catch(t){}return t}();function e(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 n={"&":"&","<":"<",">":">",'"':""","/":"/","'":"'"};function i(t){return String(t||"").replace(/[&<>"'/]/g,function(t){return n[t]})}var a="prevent_recursive_dispatch_maximum_callstack";function c(t,e,n){void 0===n&&(n={});var i,r=""+a+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}function d(t){(window.requestAnimationFrame||window.setTimeout)(t)}function l(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 f="data-@nrk/core-input-1.4.2".replace(/\W+/g,"-"),s=13,p=27,m=33,v=34,b=35,g=36,y=38,x=40,o=500;function w(t,e){var o="object"==typeof e?e:{content:e},a="string"==typeof o.content;return l(t).map(function(t){var e=t.nextElementSibling,n=void 0===o.ajax?t.getAttribute(f):o.ajax,i=void 0===o.limit?t.getAttribute(f+"-limit"):Math.max(o.limit||0,0),r=void 0===o.open?t===document.activeElement:o.open;return t.setAttribute(f,n||""),t.setAttribute(f+"-limit",i),t.setAttribute(u?"data-role":"role","combobox"),t.setAttribute("aria-autocomplete","list"),t.setAttribute("autocomplete","off"),a&&(e.innerHTML=o.content),l("a,button",e).forEach(function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return C.apply(void 0,[i].concat(t))}),E(t,r),t})}function h(a){a.ctrlKey||a.altKey||a.metaKey||a.defaultPrevented||l("["+f+"]").forEach(function(t){var e,n,i=t.nextElementSibling,r=t===a.target||i.contains(a.target),o="click"===a.type&&r&&l('[tabindex="-1"]',i).filter(function(t){return t.contains(a.target)})[0];o?(e=t,n={relatedTarget:i,currentTarget:o,value:o.value||o.textContent.trim()},c(e,"input.select",n)&&(e.value=n.value,e.focus(),d(function(){return E(e,!1)}))):E(t,r)})}function A(t,e){var n=t.nextElementSibling,i=[t].concat(l('[tabindex="-1"]:not([hidden])',n)),r=e.keyCode===p&&"true"===t.getAttribute("aria-expanded"),o=i.indexOf(document.activeElement),a=!1;e.keyCode===x?a=i[o+1]||i[0]:e.keyCode===y?a=i[o-1]||i.pop():n.contains(e.target)&&(e.keyCode===b||e.keyCode===v?a=i.pop():e.keyCode===g||e.keyCode===m?a=i[1]:e.keyCode!==s&&t.focus()),E(t,e.keyCode!==p),(!1!==a||r)&&e.preventDefault(),a&&a.focus()}function E(t,e){void 0===e&&(e="true"===t.getAttribute("aria-expanded")),d(function(){t.nextElementSibling[e?"removeAttribute":"setAttribute"]("hidden",""),t.setAttribute("aria-expanded",e)})}function C(t,e,n,i){e.setAttribute("aria-label",e.textContent.trim()+", "+(n+1)+" av "+i.length),e.setAttribute("tabindex","-1"),e.setAttribute("type","button"),t&&t<=n&&e.parentElement.setAttribute("hidden","")}function k(t){var e=t.getAttribute(f),n=k.xhr=k.xhr||new window.XMLHttpRequest;if(!e)return!1;clearTimeout(k.timer),n.abort(),n.onload=function(){try{n.responseJSON=JSON.parse(n.responseText)}catch(t){n.responseJSON=!1}c(t,"input.ajax",n)},k.timer=setTimeout(function(){t.value&&c(t,"input.ajax.beforeSend",n)&&(n.open("GET",e.replace("{{value}}",window.encodeURIComponent(t.value)),!0),n.setRequestHeader("X-Requested-With","XMLHttpRequest"),n.send())},o)}return w.escapeHTML=i,w.highlight=function(t,e){var n=e.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&");return i(t).replace(new RegExp(n||".^","gi"),"<mark>$&</mark>")},e(f,"click",h),e(f,"focus",h,!0),e(f,"input",function(t){var a,e,n,i=t.target;i.hasAttribute(f)&&(e={relatedTarget:(a=i).nextElementSibling},n=Number(a.getAttribute(f+"-limit"))||1/0,c(a,"input.filter",e)&&!1===k(a)&&l('[tabindex="-1"]',a.nextElementSibling).reduce(function(t,e,n){var i="LI"===e.parentElement.nodeName&&e.parentElement,r=-1!==e.textContent.toLowerCase().indexOf(a.value.toLowerCase()),o=r?"removeAttribute":"setAttribute";return i&&i[o]("hidden",""),e[o]("hidden",""),r?t.concat(e):t},[]).forEach(function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return C.apply(void 0,[n].concat(t))}))}),e(f,"keydown",function(t){if(!(t.ctrlKey||t.altKey||t.metaKey)){if(t.target.hasAttribute&&t.target.hasAttribute(f))return A(t.target,t);for(var e=t.target,n=void 0;e;e=e.parentElement)if((n=e.previousElementSibling)&&n.hasAttribute(f))return A(n,t)}},!0),w}); | ||
//# sourceMappingURL=core-input.min.js.map |
@@ -0,3 +1,5 @@ | ||
const { name, version } = require('./package.json') | ||
const coreInput = require('./core-input.min') | ||
const UUID = `data-${name}-${version}`.replace(/\W+/g, '-') | ||
const standardHTML = ` | ||
@@ -103,5 +105,15 @@ <input type="text" class="my-input" placeholder="Type something..."> | ||
it('should limit length of suggestions from option', () => { | ||
it('should remember and ovewrite options', () => { | ||
document.body.innerHTML = standardHTML | ||
const input = document.querySelector('.my-input') | ||
coreInput(input, { limit: 11, ajax: 'https://example.com/{{value}}' }) | ||
expect(input.getAttribute(`${UUID}-limit`)).toEqual('11') | ||
coreInput(input, { limit: 12 }) | ||
expect(input.getAttribute(`${UUID}-limit`)).toEqual('12') | ||
expect(input.getAttribute(UUID)).toEqual('https://example.com/{{value}}') | ||
}) | ||
it('should limit length of suggestions from limit option', () => { | ||
document.body.innerHTML = standardHTML | ||
const input = document.querySelector('.my-input') | ||
const suggestions = document.querySelector('.my-input + ul') | ||
@@ -108,0 +120,0 @@ coreInput(input, { limit: 2 }) |
@@ -9,3 +9,3 @@ 'use strict'; | ||
var name = "@nrk/core-input"; | ||
var version = "1.4.1"; | ||
var version = "1.4.2"; | ||
@@ -117,3 +117,3 @@ var IS_BROWSER = typeof window !== 'undefined'; | ||
var UUID = ("data-" + name + "-" + version).replace(/\W+/g, '-'); // Strip invalid attribute characters | ||
var UUID = ("data-" + name + "-" + version).replace(/\W+/g, '-'); | ||
var KEYS = { ENTER: 13, ESC: 27, PAGEUP: 33, PAGEDOWN: 34, END: 35, HOME: 36, UP: 38, DOWN: 40 }; | ||
@@ -125,3 +125,2 @@ var AJAX_DEBOUNCE = 500; | ||
var repaint = typeof options.content === 'string'; | ||
var limit = Math.max(options.limit, 0) || 0; | ||
@@ -131,2 +130,3 @@ return queryAll(elements).map(function (input) { | ||
var ajax = typeof options.ajax === 'undefined' ? input.getAttribute(UUID) : options.ajax; | ||
var limit = typeof options.limit === 'undefined' ? input.getAttribute((UUID + "-limit")) : Math.max(options.limit || 0, 0); | ||
var open = typeof options.open === 'undefined' ? input === document.activeElement : options.open; | ||
@@ -133,0 +133,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"author": "NRK <opensource@nrk.no> (https://www.nrk.no/)", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "core-input.cjs.js", |
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
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
141310
929