@nrk/core-datepicker
Advanced tools
Comparing version 2.0.0 to 2.0.1
'use strict'; | ||
var name = "@nrk/core-datepicker"; | ||
var version = "1.2.3"; | ||
var version = "2.0.0"; | ||
@@ -196,6 +196,5 @@ var IS_BROWSER = typeof window !== 'undefined'; | ||
var month = date.getMonth(); | ||
var today = new Date(); | ||
var day = index_min('y-m-1 mon', date); // Monday in first week of month | ||
table.caption.textContent = (escapeHTML(datepicker.months[month])) + ", " + (date.getFullYear()); | ||
table.caption.textContent = (escapeHTML(datepicker.months[date.getMonth()])) + ", " + (date.getFullYear()); | ||
@@ -212,4 +211,5 @@ queryAll('button', table).forEach(function (button) { | ||
button.setAttribute((ATTR + "-selected"), isSelected); | ||
button.setAttribute('aria-disabled', month !== day.getMonth()); | ||
button.setAttribute('aria-label', (dayInMonth + ". " + (datepicker.months[day.getMonth()]))); | ||
button[isToday ? 'setAttribute' : 'removeAttribute']('aria-current', 'date'); | ||
button[isSelected ? 'setAttribute' : 'removeAttribute']('autofocus', ''); | ||
day.setDate(dayInMonth + 1); | ||
@@ -216,0 +216,0 @@ }); |
@@ -99,6 +99,5 @@ import { name, version } from './package.json' | ||
const month = date.getMonth() | ||
const today = new Date() | ||
let day = parse('y-m-1 mon', date) // Monday in first week of month | ||
table.caption.textContent = `${escapeHTML(datepicker.months[month])}, ${date.getFullYear()}` | ||
table.caption.textContent = `${escapeHTML(datepicker.months[date.getMonth()])}, ${date.getFullYear()}` | ||
@@ -115,4 +114,5 @@ queryAll('button', table).forEach((button) => { | ||
button.setAttribute(`${ATTR}-selected`, isSelected) | ||
button.setAttribute('aria-disabled', month !== day.getMonth()) | ||
button.setAttribute('aria-label', `${dayInMonth}. ${datepicker.months[day.getMonth()]}`) | ||
button[isToday ? 'setAttribute' : 'removeAttribute']('aria-current', 'date') | ||
button[isSelected ? 'setAttribute' : 'removeAttribute']('autofocus', '') | ||
day.setDate(dayInMonth + 1) | ||
@@ -119,0 +119,0 @@ }) |
@@ -1,55 +0,3 @@ | ||
/*! @nrk/core-datepicker v1.2.3 - Copyright (c) 2017-2018 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.CoreDatepicker=t(e.React,e.PropTypes)}(this,function(a,e){"use strict";a=a&&a.hasOwnProperty("default")?a.default:a,e=e&&e.hasOwnProperty("default")?e.default:e;var t="undefined"!=typeof window,i=(t&&/(android)/i.test(navigator.userAgent),t&&/iPad|iPhone|iPod/.test(String(navigator.platform)),function(e){void 0===e&&(e=!1);try{window.addEventListener("test",null,{get passive(){e=!0}})}catch(e){}return e}()); | ||
/** | ||
* addEvent | ||
* @param {String} uuid An unique ID of the event to bind - ensurnes single instance | ||
* @param {String} type The type of event to bind | ||
* @param {Function} handler The function to call on event | ||
* @param {Boolean|Object} options useCapture or options object for addEventListener. Defaults to false | ||
*/ | ||
function n(e,t,n,r){(void 0===r&&(r=!1),"undefined"==typeof window||window[e=e+"-"+t])||(// Ensure single instance | ||
i||"object"!=typeof r||(r=Boolean(r.capture)),("resize"===t||"load"===t?window:document).addEventListener(window[e]=t,n,r))} | ||
/** | ||
* escapeHTML | ||
* @param {String} str A string with potential html tokens | ||
* @return {String} Escaped HTML string according to OWASP recommendation | ||
*/var r={"&":"&","<":"<",">":">",'"':""","/":"/","'":"'"};function s(e){return String(e||"").replace(/[&<>"'/]/g,function(e){return r[e]})} | ||
/** | ||
* exclude | ||
* @param {Object} target The target object | ||
* @param {Object} exclude The source to exclude keys from | ||
* @return {Object} The target object without keys found in source | ||
*/ | ||
/** | ||
* dispatchEvent - with infinite loop prevention | ||
* @param {Element} elem The target object | ||
* @param {String} name The source object(s) | ||
* @param {Object} detail Detail object (bubbles and cancelable is set to true) | ||
* @return {Boolean} Whether the event was canceled | ||
*/ | ||
var u="prevent_recursive_dispatch_maximum_callstack";function d(e,t,n){void 0===n&&(n={});var r,i=""+u+t;if(e[i])return!0;// Add name to dispatching ignore | ||
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); | ||
// IE reports incorrect event.defaultPrevented | ||
// but correct return value on element.dispatchEvent | ||
var o=e.dispatchEvent(r);// Remove name from dispatching ignore | ||
return e[i]=null,o;// Follow W3C standard for return value | ||
} | ||
/** | ||
* queryAll | ||
* @param {String|NodeList|Array|Element} elements A CSS selector string, nodeList, element array, or single element | ||
* @return {Element[]} Array of elements | ||
*/function c(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[]}"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var o,l=(function(e,t){var g,v,b,k;e.exports=(g={year:"FullYear",month:"Month",week:"Date",day:"Date",hour:"Hours",minute:"Minutes",second:"Seconds"},v=/([+-]\s*\d+)\s*(second|minute|hour|day|week|month|year)|(mon)|(tue)|(wed)|(thu)|(fri)|(sat)|(sun)/g,b=/([-\dy]+)[-/.]([\dm]+)[-/.]([\dd]+)/,k=/([\dh]+):([\dm]+):?([\ds]+)?/,function(e,t){if(isFinite(e))return new Date(Number(e));var n=String(e).toLowerCase(),i=new Date(isFinite(t)&&-1===n.indexOf("now")?Number(t):Date.now()),r=n.match(b)||[],o=r[1];void 0===o&&(o="y");var a=r[2];void 0===a&&(a="m");var u=r[3];void 0===u&&(u="d");var d=n.match(k)||[],s=d[1];void 0===s&&(s="h");var c=d[2];void 0===c&&(c="m");var l=d[3];void 0===l&&(l="s");var p={year:o,month:a,day:u,hour:s,minute:c,second:l};Object.keys(p).forEach(function(e){var t="month"===e?1:0,r=""+(i["get"+g[e]]()+t);p[e]=p[e].replace(/[^-\d]+/g,function(e,t,n){return t?r.substr(r.length-n.length+t,e.length):r.substr(0,Math.max(0,r.length-n.length+e.length))})-t});var h=new Date(p.year,Math.min(12,p.month+1),0).getDate();for(i.setFullYear(p.year,Math.min(11,p.month),Math.max(1,Math.min(h,p.day))),i.setHours(Math.min(24,p.hour),Math.min(59,p.minute),Math.min(59,p.second));null!==(p=v.exec(n));){var f=p[2],m=String(p[1]).replace(/\s/g,"")*("week"===f?7:1),y=p.slice(2).indexOf(p[0]);f?i["set"+g[f]](i["get"+g[f]]()+m):i.setDate(i.getDate()-(i.getDay()||7)+y)}return i})}(o={exports:{}},o.exports),o.exports),p="data-core-datepicker",h="data-@nrk/core-datepicker-1.2.3".replace(/\W+/g,"-"),f={33:"-1month",34:"+1month",35:"y-m-99",36:"y-m-1",37:"-1day",38:"-1week",39:"+1day",40:"+1week"},m={year:"*-m-d",month:"y-*-d",day:"y-m-*",hour:"*:m",minute:"h:*",second:"h:m:*",timestamp:"*"},y=6e4;function g(e,i){// date can be String, Timestamp or Date | ||
return c(e).map(function(o){var e=l(o.getAttribute(h)||i),t=l(void 0===i?e:i,e),a=function(){return!1};d(o,"datepicker.render",{nextDate:t,prevDate:e,disable:function(e){return a=e}}),a(t)&&(t=e);// Jump back to prev date if next is disabled | ||
var u=e.getTime()===t.getTime()||d(o,"datepicker.change",{prevDate:e,nextDate:t})?t:l(o.getAttribute(h)||Date.now()),n=new Date(u.getTime()-u.getTimezoneOffset()*y).toJSON().match(/\d+/g),r={year:u.getFullYear(),month:n[1],day:n[2],hour:n[3],minute:n[4],second:n[5],timestamp:u.getTime()};return o.setAttribute(h,r.timestamp),c("button").forEach(function(e){return n=u,r=a,i=o,void(((t=e).getAttribute(p)===i.id||i.contains(t))&&(t.disabled=r(l(t.value,n))));var t,n,r,i}),c("select",o).forEach(function(e){return function(e,n,r){e.firstElementChild||(e.innerHTML=g.months.map(function(e,t){return'<option value="y-'+(t+1)+'-d">'+s(e)+"</option>"}).join(""));c(e.children).forEach(function(e){var t=l(e.value,n);e.disabled=r(t),e.selected=t.getTime()===n.getTime()})}(e,u,a)}),c("input",o).forEach(function(e){return function(e,t,n,r){var i=e.getAttribute(h+"-type")||e.getAttribute("type");if("radio"===i||"checkbox"===i){var o=l(e.value,t);e.disabled=n(o),e.checked=o.getTime()===t.getTime()}else r[i]&&(e.setAttribute("type","number"),// Set input type to number | ||
e.setAttribute(h+"-type",i),// And store original input type | ||
e.value=r[i])}(e,u,a,r)}),c("table",o).forEach(function(e){return function(e,i,o){e.firstElementChild||(e.innerHTML="\n <caption></caption><thead><tr><th>"+g.days.map(s).join("</th><th>")+"</th></tr></thead>\n <tbody>"+Array(7).join("<tr>"+Array(8).join('<td><button type="button"></button></td>')+"</tr>")+"</tbody>");var a=i.getMonth(),u=new Date,d=l("y-m-1 mon",i);// Monday in first week of month | ||
e.caption.textContent=s(g.months[a])+", "+i.getFullYear(),c("button",e).forEach(function(e){var t=d.getDate()===u.getDate()&&d.getMonth()===u.getMonth()&&d.getFullYear()===u.getFullYear(),n=d.getTime()===i.getTime(),r=d.getDate();e.textContent=r,// Set textContent instead of innerHTML avoids reflow | ||
e.value=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+r,e.disabled=o(d),e.setAttribute("tabindex",n-1),e.setAttribute(p+"-selected",n),e.setAttribute("aria-disabled",a!==d.getMonth()),e[t?"setAttribute":"removeAttribute"]("aria-current","date"),d.setDate(r+1)})}(e,u,a)}),o})} | ||
// Expose API and config | ||
function v(e){for(var t=e.target,n=t,r=void 0;n;n=n.parentElement){var i=document.getElementById(n.getAttribute(p))||n,o=i.hasAttribute(h)&&(m[t.getAttribute(h+"-type")]||"*");// Store table while traversing DOM parents | ||
if(r||"TABLE"!==n.nodeName||(r=n),o){var a=o.replace("*",t.value);return(!i.contains(r)||d(i,"datepicker.click.day",{currentTarget:t,relatedTarget:r,prevDate:l(i.getAttribute(h)),nextDate:l(a)}))&&g(i,a)}}}g.parse=l,g.months=["januar","februar","mars","april","mai","juni","juli","august","september","oktober","november","desember"],g.days=["man","tirs","ons","tors","fre","lør","søn"],n(h,"change",v),n(h,"click",function(e){for(var t=e.target;t;t=t.parentElement)if("BUTTON"===t.nodeName)return v({target:t})}),n(h,"keydown",function(e){if(!(e.ctrlKey||e.metaKey||e.shitKey||e.altKey)&&f[e.keyCode])for(var t=e.target,n=void 0;t;t=t.parentElement)// Store table while traversing DOM parents | ||
if(n||"TABLE"!==t.nodeName||(n=t),n&&t.hasAttribute(h)){// Only listen to keyCodes inside table inside datepicker | ||
g(t,f[e.keyCode]),n.querySelector("["+p+'-selected="true"]').focus(),e.preventDefault();break}});var b=function(t){function o(e){t.call(this,e),this.onClickDay=this.onClickDay.bind(this),this.onChange=this.onChange.bind(this),this.onRender=this.onRender.bind(this)}t&&(o.__proto__=t),(o.prototype=Object.create(t&&t.prototype)).constructor=o;var e={defaultProps:{configurable:!0}};return e.defaultProps.get=function(){return{date:null,disable:null,onRender:null,onChange:null,onClickDay:null}},o.prototype.componentDidMount=function(){this.el.addEventListener("datepicker.click.day",this.onClickDay),this.el.addEventListener("datepicker.change",this.onChange),this.el.addEventListener("datepicker.render",this.onRender),g(this.el,this.props.date)},o.prototype.componentDidUpdate=function(){g(this.el,this.props.date)},o.prototype.componentWillUnmount=function(){this.el.removeEventListener("datepicker.click.day",this.onClickDay),this.el.removeEventListener("datepicker.change",this.onChange),this.el.removeEventListener("datepicker.render",this.onRender)},o.prototype.onClickDay=function(e){this.props.onClickDay&&this.props.onClickDay(e)},o.prototype.onChange=function(e){this.props.onChange&&this.props.onChange(e)},o.prototype.onRender=function(e){this.props.disable&&e.detail.disable(this.props.disable)},o.prototype.render=function(){var n,r,e,t=this,i=(n=this.props,r=o.defaultProps,void 0===(e={ref:function(e){return t.el=e}})&&(e={}),Object.keys(n).reduce(function(e,t){return r.hasOwnProperty(t)||(e[t]=n[t]),e},e));return a.createElement("div",i,this.props.children)},Object.defineProperties(o,e),o}(a.Component); | ||
// Expose API and config | ||
return b.parse=g.parse,b.months=g.months,b.days=g.days,b.propTypes={disable:e.func,onRender:e.func,onChange:e.func,onClickDay:e.func,date:e.oneOfType([e.string,e.number,e.instanceOf(Date)])},b}); | ||
/*! @nrk/core-datepicker v2.0.0 - Copyright (c) 2017-2018 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.CoreDatepicker=t(e.React,e.PropTypes)}(this,function(a,e){"use strict";a=a&&a.hasOwnProperty("default")?a.default:a,e=e&&e.hasOwnProperty("default")?e.default:e;var t="undefined"!=typeof window,o=(t&&/(android)/i.test(navigator.userAgent),t&&/iPad|iPhone|iPod/.test(String(navigator.platform)),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 d(e){return String(e||"").replace(/[&<>"'/]/g,function(e){return r[e]})}var u="prevent_recursive_dispatch_maximum_callstack";function s(e,t,n){void 0===n&&(n={});var r,o=""+u+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 c(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[]}"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var i,l=(function(e,t){var g,v,b,k;e.exports=(g={year:"FullYear",month:"Month",week:"Date",day:"Date",hour:"Hours",minute:"Minutes",second:"Seconds"},v=/([+-]\s*\d+)\s*(second|minute|hour|day|week|month|year)|(mon)|(tue)|(wed)|(thu)|(fri)|(sat)|(sun)/g,b=/([-\dy]+)[-/.]([\dm]+)[-/.]([\dd]+)/,k=/([\dh]+):([\dm]+):?([\ds]+)?/,function(e,t){if(isFinite(e))return new Date(Number(e));var n=String(e).toLowerCase(),o=new Date(isFinite(t)&&-1===n.indexOf("now")?Number(t):Date.now()),r=n.match(b)||[],i=r[1];void 0===i&&(i="y");var a=r[2];void 0===a&&(a="m");var u=r[3];void 0===u&&(u="d");var d=n.match(k)||[],s=d[1];void 0===s&&(s="h");var c=d[2];void 0===c&&(c="m");var l=d[3];void 0===l&&(l="s");var p={year:i,month:a,day:u,hour:s,minute:c,second:l};Object.keys(p).forEach(function(e){var t="month"===e?1:0,r=""+(o["get"+g[e]]()+t);p[e]=p[e].replace(/[^-\d]+/g,function(e,t,n){return t?r.substr(r.length-n.length+t,e.length):r.substr(0,Math.max(0,r.length-n.length+e.length))})-t});var h=new Date(p.year,Math.min(12,p.month+1),0).getDate();for(o.setFullYear(p.year,Math.min(11,p.month),Math.max(1,Math.min(h,p.day))),o.setHours(Math.min(24,p.hour),Math.min(59,p.minute),Math.min(59,p.second));null!==(p=v.exec(n));){var f=p[2],m=String(p[1]).replace(/\s/g,"")*("week"===f?7:1),y=p.slice(2).indexOf(p[0]);f?o["set"+g[f]](o["get"+g[f]]()+m):o.setDate(o.getDate()-(o.getDay()||7)+y)}return o})}(i={exports:{}},i.exports),i.exports),p="data-core-datepicker",h="data-@nrk/core-datepicker-2.0.0".replace(/\W+/g,"-"),f={33:"-1month",34:"+1month",35:"y-m-99",36:"y-m-1",37:"-1day",38:"-1week",39:"+1day",40:"+1week"},m={year:"*-m-d",month:"y-*-d",day:"y-m-*",hour:"*:m",minute:"h:*",second:"h:m:*",timestamp:"*"},y=6e4;function g(e,o){return c(e).map(function(i){var e=l(i.getAttribute(h)||o),t=l(void 0===o?e:o,e),a=function(){return!1};s(i,"datepicker.render",{nextDate:t,prevDate:e,disable:function(e){return a=e}}),a(t)&&(t=e);var u=e.getTime()===t.getTime()||s(i,"datepicker.change",{prevDate:e,nextDate:t})?t:l(i.getAttribute(h)||Date.now()),n=new Date(u.getTime()-u.getTimezoneOffset()*y).toJSON().match(/\d+/g),r={year:u.getFullYear(),month:n[1],day:n[2],hour:n[3],minute:n[4],second:n[5],timestamp:u.getTime()};return i.setAttribute(h,r.timestamp),c("button").forEach(function(e){return n=u,r=a,o=i,void(((t=e).getAttribute(p)===o.id||o.contains(t))&&(t.disabled=r(l(t.value,n))));var t,n,r,o}),c("select",i).forEach(function(e){return function(e,n,r){e.firstElementChild||(e.innerHTML=g.months.map(function(e,t){return'<option value="y-'+(t+1)+'-d">'+d(e)+"</option>"}).join(""));c(e.children).forEach(function(e){var t=l(e.value,n);e.disabled=r(t),e.selected=t.getTime()===n.getTime()})}(e,u,a)}),c("input",i).forEach(function(e){return function(e,t,n,r){var o=e.getAttribute(h+"-type")||e.getAttribute("type");if("radio"===o||"checkbox"===o){var i=l(e.value,t);e.disabled=n(i),e.checked=i.getTime()===t.getTime()}else r[o]&&(e.setAttribute("type","number"),e.setAttribute(h+"-type",o),e.value=r[o])}(e,u,a,r)}),c("table",i).forEach(function(e){return function(e,o,i){e.firstElementChild||(e.innerHTML="\n <caption></caption><thead><tr><th>"+g.days.map(d).join("</th><th>")+"</th></tr></thead>\n <tbody>"+Array(7).join("<tr>"+Array(8).join('<td><button type="button"></button></td>')+"</tr>")+"</tbody>");var a=new Date,u=l("y-m-1 mon",o);e.caption.textContent=d(g.months[o.getMonth()])+", "+o.getFullYear(),c("button",e).forEach(function(e){var t=u.getDate()===a.getDate()&&u.getMonth()===a.getMonth()&&u.getFullYear()===a.getFullYear(),n=u.getTime()===o.getTime(),r=u.getDate();e.textContent=r,e.value=u.getFullYear()+"-"+(u.getMonth()+1)+"-"+r,e.disabled=i(u),e.setAttribute("tabindex",n-1),e.setAttribute(p+"-selected",n),e.setAttribute("aria-label",r+". "+g.months[u.getMonth()]),e[t?"setAttribute":"removeAttribute"]("aria-current","date"),e[n?"setAttribute":"removeAttribute"]("autofocus",""),u.setDate(r+1)})}(e,u,a)}),i})}function v(e){for(var t=e.target,n=t,r=void 0;n;n=n.parentElement){var o=document.getElementById(n.getAttribute(p))||n,i=o.hasAttribute(h)&&(m[t.getAttribute(h+"-type")]||"*");if(r||"TABLE"!==n.nodeName||(r=n),i){var a=i.replace("*",t.value);return(!o.contains(r)||s(o,"datepicker.click.day",{currentTarget:t,relatedTarget:r,prevDate:l(o.getAttribute(h)),nextDate:l(a)}))&&g(o,a)}}}g.parse=l,g.months=["januar","februar","mars","april","mai","juni","juli","august","september","oktober","november","desember"],g.days=["man","tirs","ons","tors","fre","lør","søn"],n(h,"change",v),n(h,"click",function(e){for(var t=e.target;t;t=t.parentElement)if("BUTTON"===t.nodeName)return v({target:t})}),n(h,"keydown",function(e){if(!(e.ctrlKey||e.metaKey||e.shitKey||e.altKey)&&f[e.keyCode])for(var t=e.target,n=void 0;t;t=t.parentElement)if(n||"TABLE"!==t.nodeName||(n=t),n&&t.hasAttribute(h)){g(t,f[e.keyCode]),n.querySelector("["+p+'-selected="true"]').focus(),e.preventDefault();break}});var b=function(t){function i(e){t.call(this,e),this.onClickDay=this.onClickDay.bind(this),this.onChange=this.onChange.bind(this),this.onRender=this.onRender.bind(this)}t&&(i.__proto__=t),(i.prototype=Object.create(t&&t.prototype)).constructor=i;var e={defaultProps:{configurable:!0}};return e.defaultProps.get=function(){return{date:null,disable:null,onRender:null,onChange:null,onClickDay:null}},i.prototype.componentDidMount=function(){this.el.addEventListener("datepicker.click.day",this.onClickDay),this.el.addEventListener("datepicker.change",this.onChange),this.el.addEventListener("datepicker.render",this.onRender),g(this.el,this.props.date)},i.prototype.componentDidUpdate=function(){g(this.el,this.props.date)},i.prototype.componentWillUnmount=function(){this.el.removeEventListener("datepicker.click.day",this.onClickDay),this.el.removeEventListener("datepicker.change",this.onChange),this.el.removeEventListener("datepicker.render",this.onRender)},i.prototype.onClickDay=function(e){this.props.onClickDay&&this.props.onClickDay(e)},i.prototype.onChange=function(e){this.props.onChange&&this.props.onChange(e)},i.prototype.onRender=function(e){this.props.disable&&e.detail.disable(this.props.disable)},i.prototype.render=function(){var n,r,e,t=this,o=(n=this.props,r=i.defaultProps,void 0===(e={ref:function(e){return t.el=e}})&&(e={}),Object.keys(n).reduce(function(e,t){return r.hasOwnProperty(t)||(e[t]=n[t]),e},e));return a.createElement("div",o,this.props.children)},Object.defineProperties(i,e),i}(a.Component);return b.parse=g.parse,b.months=g.months,b.days=g.days,b.propTypes={disable:e.func,onRender:e.func,onChange:e.func,onClickDay:e.func,date:e.oneOfType([e.string,e.number,e.instanceOf(Date)])},b}); | ||
//# sourceMappingURL=core-datepicker.jsx.js.map |
@@ -1,46 +0,3 @@ | ||
/*! @nrk/core-datepicker v1.2.3 - Copyright (c) 2017-2018 NRK */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.coreDatepicker=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)),function(e){void 0===e&&(e=!1);try{window.addEventListener("test",null,{get passive(){e=!0}})}catch(e){}return e}()); | ||
/** | ||
* addEvent | ||
* @param {String} uuid An unique ID of the event to bind - ensurnes single instance | ||
* @param {String} type The type of event to bind | ||
* @param {Function} handler The function to call on event | ||
* @param {Boolean|Object} options useCapture or options object for addEventListener. Defaults to false | ||
*/ | ||
function t(e,t,n,r){(void 0===r&&(r=!1),"undefined"==typeof window||window[e=e+"-"+t])||(// Ensure single instance | ||
a||"object"!=typeof r||(r=Boolean(r.capture)),("resize"===t||"load"===t?window:document).addEventListener(window[e]=t,n,r))} | ||
/** | ||
* escapeHTML | ||
* @param {String} str A string with potential html tokens | ||
* @return {String} Escaped HTML string according to OWASP recommendation | ||
*/var n={"&":"&","<":"<",">":">",'"':""","/":"/","'":"'"};function c(e){return String(e||"").replace(/[&<>"'/]/g,function(e){return n[e]})} | ||
/** | ||
* dispatchEvent - with infinite loop prevention | ||
* @param {Element} elem The target object | ||
* @param {String} name The source object(s) | ||
* @param {Object} detail Detail object (bubbles and cancelable is set to true) | ||
* @return {Boolean} Whether the event was canceled | ||
*/var o="prevent_recursive_dispatch_maximum_callstack";function d(e,t,n){void 0===n&&(n={});var r,a=""+o+t;if(e[a])return!0;// Add name to dispatching ignore | ||
e[a]=!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); | ||
// IE reports incorrect event.defaultPrevented | ||
// but correct return value on element.dispatchEvent | ||
var i=e.dispatchEvent(r);// Remove name from dispatching ignore | ||
return e[a]=null,i;// Follow W3C standard for return value | ||
} | ||
/** | ||
* queryAll | ||
* @param {String|NodeList|Array|Element} elements A CSS selector string, nodeList, element array, or single element | ||
* @return {Element[]} Array of elements | ||
*/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[]}"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var r,m=(function(e,t){var p,y,b,w;e.exports=(p={year:"FullYear",month:"Month",week:"Date",day:"Date",hour:"Hours",minute:"Minutes",second:"Seconds"},y=/([+-]\s*\d+)\s*(second|minute|hour|day|week|month|year)|(mon)|(tue)|(wed)|(thu)|(fri)|(sat)|(sun)/g,b=/([-\dy]+)[-/.]([\dm]+)[-/.]([\dd]+)/,w=/([\dh]+):([\dm]+):?([\ds]+)?/,function(e,t){if(isFinite(e))return new Date(Number(e));var n=String(e).toLowerCase(),a=new Date(isFinite(t)&&-1===n.indexOf("now")?Number(t):Date.now()),r=n.match(b)||[],i=r[1];void 0===i&&(i="y");var o=r[2];void 0===o&&(o="m");var u=r[3];void 0===u&&(u="d");var d=n.match(w)||[],c=d[1];void 0===c&&(c="h");var s=d[2];void 0===s&&(s="m");var m=d[3];void 0===m&&(m="s");var l={year:i,month:o,day:u,hour:c,minute:s,second:m};Object.keys(l).forEach(function(e){var t="month"===e?1:0,r=""+(a["get"+p[e]]()+t);l[e]=l[e].replace(/[^-\d]+/g,function(e,t,n){return t?r.substr(r.length-n.length+t,e.length):r.substr(0,Math.max(0,r.length-n.length+e.length))})-t});var f=new Date(l.year,Math.min(12,l.month+1),0).getDate();for(a.setFullYear(l.year,Math.min(11,l.month),Math.max(1,Math.min(f,l.day))),a.setHours(Math.min(24,l.hour),Math.min(59,l.minute),Math.min(59,l.second));null!==(l=y.exec(n));){var h=l[2],g=String(l[1]).replace(/\s/g,"")*("week"===h?7:1),v=l.slice(2).indexOf(l[0]);h?a["set"+p[h]](a["get"+p[h]]()+g):a.setDate(a.getDate()-(a.getDay()||7)+v)}return a})}(r={exports:{}},r.exports),r.exports),l="data-core-datepicker",f="data-@nrk/core-datepicker-1.2.3".replace(/\W+/g,"-"),i={33:"-1month",34:"+1month",35:"y-m-99",36:"y-m-1",37:"-1day",38:"-1week",39:"+1day",40:"+1week"},u={year:"*-m-d",month:"y-*-d",day:"y-m-*",hour:"*:m",minute:"h:*",second:"h:m:*",timestamp:"*"},h=6e4;function g(e,a){// date can be String, Timestamp or Date | ||
return s(e).map(function(i){var e=m(i.getAttribute(f)||a),t=m(void 0===a?e:a,e),o=function(){return!1};d(i,"datepicker.render",{nextDate:t,prevDate:e,disable:function(e){return o=e}}),o(t)&&(t=e);// Jump back to prev date if next is disabled | ||
var u=e.getTime()===t.getTime()||d(i,"datepicker.change",{prevDate:e,nextDate:t})?t:m(i.getAttribute(f)||Date.now()),n=new Date(u.getTime()-u.getTimezoneOffset()*h).toJSON().match(/\d+/g),r={year:u.getFullYear(),month:n[1],day:n[2],hour:n[3],minute:n[4],second:n[5],timestamp:u.getTime()};return i.setAttribute(f,r.timestamp),s("button").forEach(function(e){return n=u,r=o,a=i,void(((t=e).getAttribute(l)===a.id||a.contains(t))&&(t.disabled=r(m(t.value,n))));var t,n,r,a}),s("select",i).forEach(function(e){return function(e,n,r){e.firstElementChild||(e.innerHTML=g.months.map(function(e,t){return'<option value="y-'+(t+1)+'-d">'+c(e)+"</option>"}).join(""));s(e.children).forEach(function(e){var t=m(e.value,n);e.disabled=r(t),e.selected=t.getTime()===n.getTime()})}(e,u,o)}),s("input",i).forEach(function(e){return function(e,t,n,r){var a=e.getAttribute(f+"-type")||e.getAttribute("type");if("radio"===a||"checkbox"===a){var i=m(e.value,t);e.disabled=n(i),e.checked=i.getTime()===t.getTime()}else r[a]&&(e.setAttribute("type","number"),// Set input type to number | ||
e.setAttribute(f+"-type",a),// And store original input type | ||
e.value=r[a])}(e,u,o,r)}),s("table",i).forEach(function(e){return function(e,a,i){e.firstElementChild||(e.innerHTML="\n <caption></caption><thead><tr><th>"+g.days.map(c).join("</th><th>")+"</th></tr></thead>\n <tbody>"+Array(7).join("<tr>"+Array(8).join('<td><button type="button"></button></td>')+"</tr>")+"</tbody>");var o=a.getMonth(),u=new Date,d=m("y-m-1 mon",a);// Monday in first week of month | ||
e.caption.textContent=c(g.months[o])+", "+a.getFullYear(),s("button",e).forEach(function(e){var t=d.getDate()===u.getDate()&&d.getMonth()===u.getMonth()&&d.getFullYear()===u.getFullYear(),n=d.getTime()===a.getTime(),r=d.getDate();e.textContent=r,// Set textContent instead of innerHTML avoids reflow | ||
e.value=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+r,e.disabled=i(d),e.setAttribute("tabindex",n-1),e.setAttribute(l+"-selected",n),e.setAttribute("aria-disabled",o!==d.getMonth()),e[t?"setAttribute":"removeAttribute"]("aria-current","date"),d.setDate(r+1)})}(e,u,o)}),i})} | ||
// Expose API and config | ||
function v(e){for(var t=e.target,n=t,r=void 0;n;n=n.parentElement){var a=document.getElementById(n.getAttribute(l))||n,i=a.hasAttribute(f)&&(u[t.getAttribute(f+"-type")]||"*");// Store table while traversing DOM parents | ||
if(r||"TABLE"!==n.nodeName||(r=n),i){var o=i.replace("*",t.value);return(!a.contains(r)||d(a,"datepicker.click.day",{currentTarget:t,relatedTarget:r,prevDate:m(a.getAttribute(f)),nextDate:m(o)}))&&g(a,o)}}}return g.parse=m,g.months=["januar","februar","mars","april","mai","juni","juli","august","september","oktober","november","desember"],g.days=["man","tirs","ons","tors","fre","lør","søn"],t(f,"change",v),t(f,"click",function(e){for(var t=e.target;t;t=t.parentElement)if("BUTTON"===t.nodeName)return v({target:t})}),t(f,"keydown",function(e){if(!(e.ctrlKey||e.metaKey||e.shitKey||e.altKey)&&i[e.keyCode])for(var t=e.target,n=void 0;t;t=t.parentElement)// Store table while traversing DOM parents | ||
if(n||"TABLE"!==t.nodeName||(n=t),n&&t.hasAttribute(f)){// Only listen to keyCodes inside table inside datepicker | ||
g(t,i[e.keyCode]),n.querySelector("["+l+'-selected="true"]').focus(),e.preventDefault();break}}),g}); | ||
/*! @nrk/core-datepicker v2.0.0 - Copyright (c) 2017-2018 NRK */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.coreDatepicker=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)),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])||(a||"object"!=typeof r||(r=Boolean(r.capture)),("resize"===t||"load"===t?window:document).addEventListener(window[e]=t,n,r))}var n={"&":"&","<":"<",">":">",'"':""","/":"/","'":"'"};function d(e){return String(e||"").replace(/[&<>"'/]/g,function(e){return n[e]})}var o="prevent_recursive_dispatch_maximum_callstack";function c(e,t,n){void 0===n&&(n={});var r,a=""+o+t;if(e[a])return!0;e[a]=!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[a]=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[]}"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var r,m=(function(e,t){var p,y,b,w;e.exports=(p={year:"FullYear",month:"Month",week:"Date",day:"Date",hour:"Hours",minute:"Minutes",second:"Seconds"},y=/([+-]\s*\d+)\s*(second|minute|hour|day|week|month|year)|(mon)|(tue)|(wed)|(thu)|(fri)|(sat)|(sun)/g,b=/([-\dy]+)[-/.]([\dm]+)[-/.]([\dd]+)/,w=/([\dh]+):([\dm]+):?([\ds]+)?/,function(e,t){if(isFinite(e))return new Date(Number(e));var n=String(e).toLowerCase(),a=new Date(isFinite(t)&&-1===n.indexOf("now")?Number(t):Date.now()),r=n.match(b)||[],i=r[1];void 0===i&&(i="y");var o=r[2];void 0===o&&(o="m");var u=r[3];void 0===u&&(u="d");var d=n.match(w)||[],c=d[1];void 0===c&&(c="h");var s=d[2];void 0===s&&(s="m");var m=d[3];void 0===m&&(m="s");var l={year:i,month:o,day:u,hour:c,minute:s,second:m};Object.keys(l).forEach(function(e){var t="month"===e?1:0,r=""+(a["get"+p[e]]()+t);l[e]=l[e].replace(/[^-\d]+/g,function(e,t,n){return t?r.substr(r.length-n.length+t,e.length):r.substr(0,Math.max(0,r.length-n.length+e.length))})-t});var f=new Date(l.year,Math.min(12,l.month+1),0).getDate();for(a.setFullYear(l.year,Math.min(11,l.month),Math.max(1,Math.min(f,l.day))),a.setHours(Math.min(24,l.hour),Math.min(59,l.minute),Math.min(59,l.second));null!==(l=y.exec(n));){var h=l[2],g=String(l[1]).replace(/\s/g,"")*("week"===h?7:1),v=l.slice(2).indexOf(l[0]);h?a["set"+p[h]](a["get"+p[h]]()+g):a.setDate(a.getDate()-(a.getDay()||7)+v)}return a})}(r={exports:{}},r.exports),r.exports),l="data-core-datepicker",f="data-@nrk/core-datepicker-2.0.0".replace(/\W+/g,"-"),i={33:"-1month",34:"+1month",35:"y-m-99",36:"y-m-1",37:"-1day",38:"-1week",39:"+1day",40:"+1week"},u={year:"*-m-d",month:"y-*-d",day:"y-m-*",hour:"*:m",minute:"h:*",second:"h:m:*",timestamp:"*"},h=6e4;function g(e,a){return s(e).map(function(i){var e=m(i.getAttribute(f)||a),t=m(void 0===a?e:a,e),o=function(){return!1};c(i,"datepicker.render",{nextDate:t,prevDate:e,disable:function(e){return o=e}}),o(t)&&(t=e);var u=e.getTime()===t.getTime()||c(i,"datepicker.change",{prevDate:e,nextDate:t})?t:m(i.getAttribute(f)||Date.now()),n=new Date(u.getTime()-u.getTimezoneOffset()*h).toJSON().match(/\d+/g),r={year:u.getFullYear(),month:n[1],day:n[2],hour:n[3],minute:n[4],second:n[5],timestamp:u.getTime()};return i.setAttribute(f,r.timestamp),s("button").forEach(function(e){return n=u,r=o,a=i,void(((t=e).getAttribute(l)===a.id||a.contains(t))&&(t.disabled=r(m(t.value,n))));var t,n,r,a}),s("select",i).forEach(function(e){return function(e,n,r){e.firstElementChild||(e.innerHTML=g.months.map(function(e,t){return'<option value="y-'+(t+1)+'-d">'+d(e)+"</option>"}).join(""));s(e.children).forEach(function(e){var t=m(e.value,n);e.disabled=r(t),e.selected=t.getTime()===n.getTime()})}(e,u,o)}),s("input",i).forEach(function(e){return function(e,t,n,r){var a=e.getAttribute(f+"-type")||e.getAttribute("type");if("radio"===a||"checkbox"===a){var i=m(e.value,t);e.disabled=n(i),e.checked=i.getTime()===t.getTime()}else r[a]&&(e.setAttribute("type","number"),e.setAttribute(f+"-type",a),e.value=r[a])}(e,u,o,r)}),s("table",i).forEach(function(e){return function(e,a,i){e.firstElementChild||(e.innerHTML="\n <caption></caption><thead><tr><th>"+g.days.map(d).join("</th><th>")+"</th></tr></thead>\n <tbody>"+Array(7).join("<tr>"+Array(8).join('<td><button type="button"></button></td>')+"</tr>")+"</tbody>");var o=new Date,u=m("y-m-1 mon",a);e.caption.textContent=d(g.months[a.getMonth()])+", "+a.getFullYear(),s("button",e).forEach(function(e){var t=u.getDate()===o.getDate()&&u.getMonth()===o.getMonth()&&u.getFullYear()===o.getFullYear(),n=u.getTime()===a.getTime(),r=u.getDate();e.textContent=r,e.value=u.getFullYear()+"-"+(u.getMonth()+1)+"-"+r,e.disabled=i(u),e.setAttribute("tabindex",n-1),e.setAttribute(l+"-selected",n),e.setAttribute("aria-label",r+". "+g.months[u.getMonth()]),e[t?"setAttribute":"removeAttribute"]("aria-current","date"),e[n?"setAttribute":"removeAttribute"]("autofocus",""),u.setDate(r+1)})}(e,u,o)}),i})}function v(e){for(var t=e.target,n=t,r=void 0;n;n=n.parentElement){var a=document.getElementById(n.getAttribute(l))||n,i=a.hasAttribute(f)&&(u[t.getAttribute(f+"-type")]||"*");if(r||"TABLE"!==n.nodeName||(r=n),i){var o=i.replace("*",t.value);return(!a.contains(r)||c(a,"datepicker.click.day",{currentTarget:t,relatedTarget:r,prevDate:m(a.getAttribute(f)),nextDate:m(o)}))&&g(a,o)}}}return g.parse=m,g.months=["januar","februar","mars","april","mai","juni","juli","august","september","oktober","november","desember"],g.days=["man","tirs","ons","tors","fre","lør","søn"],t(f,"change",v),t(f,"click",function(e){for(var t=e.target;t;t=t.parentElement)if("BUTTON"===t.nodeName)return v({target:t})}),t(f,"keydown",function(e){if(!(e.ctrlKey||e.metaKey||e.shitKey||e.altKey)&&i[e.keyCode])for(var t=e.target,n=void 0;t;t=t.parentElement)if(n||"TABLE"!==t.nodeName||(n=t),n&&t.hasAttribute(f)){g(t,i[e.keyCode]),n.querySelector("["+l+'-selected="true"]').focus(),e.preventDefault();break}}),g}); | ||
//# sourceMappingURL=core-datepicker.min.js.map |
@@ -196,10 +196,6 @@ const coreDatepicker = require('./core-datepicker.min') | ||
const datepickerEl = document.querySelector('.my-datepicker') | ||
const tableEl = datepickerEl.querySelector('table') | ||
const nowJan = new Date() | ||
// Set date to January so we can always assume 31 days in the month | ||
nowJan.setMonth(0) | ||
const nowJan = new Date('2018-01-01') // So we know the months has 31 days and starts on monday | ||
coreDatepicker(datepickerEl, nowJan) | ||
expect(tableEl.querySelectorAll('tbody td button[aria-disabled="false"]').length).toEqual(31) | ||
expect(datepickerEl.querySelectorAll('table button')[30].textContent).toEqual('31') | ||
}) | ||
@@ -206,0 +202,0 @@ it('should change date if a day is clicked', () => { |
@@ -9,3 +9,3 @@ 'use strict'; | ||
var name = "@nrk/core-datepicker"; | ||
var version = "1.2.3"; | ||
var version = "2.0.0"; | ||
@@ -217,6 +217,5 @@ var IS_BROWSER = typeof window !== 'undefined'; | ||
var month = date.getMonth(); | ||
var today = new Date(); | ||
var day = index_min('y-m-1 mon', date); // Monday in first week of month | ||
table.caption.textContent = (escapeHTML(datepicker.months[month])) + ", " + (date.getFullYear()); | ||
table.caption.textContent = (escapeHTML(datepicker.months[date.getMonth()])) + ", " + (date.getFullYear()); | ||
@@ -233,4 +232,5 @@ queryAll('button', table).forEach(function (button) { | ||
button.setAttribute((ATTR + "-selected"), isSelected); | ||
button.setAttribute('aria-disabled', month !== day.getMonth()); | ||
button.setAttribute('aria-label', (dayInMonth + ". " + (datepicker.months[day.getMonth()]))); | ||
button[isToday ? 'setAttribute' : 'removeAttribute']('aria-current', 'date'); | ||
button[isSelected ? 'setAttribute' : 'removeAttribute']('autofocus', ''); | ||
day.setDate(dayInMonth + 1); | ||
@@ -237,0 +237,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"author": "NRK <opensource@nrk.no> (https://www.nrk.no/)", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "core-datepicker.cjs.js", |
@@ -102,4 +102,2 @@ # Core Datepicker | ||
<script> | ||
// coreDate.days = ['m', 't', 'o', 't', 'f', 'l', 's'] // Change name of days | ||
// Update GUI | ||
@@ -285,2 +283,4 @@ document.addEventListener('datepicker.render', function (event) { | ||
### CSS | ||
```css | ||
@@ -295,1 +295,17 @@ .my-datepicker /* Target datepicker container */ | ||
``` | ||
--- | ||
## Language | ||
`@nrk/core-datepicker` defaults to Norwegian Bookmål text without abbreviations (writing `September` instead of `Sept`). This can be configured by setting the `days` and `months` properties. Note that abbreviations should always be at least 3 characters long to ensure a better experience for screen reader users (for instance writing `Mon`, `Tue`... instead of `m`, `t`...). | ||
```js | ||
//JS | ||
coreDatepicker.days = ['man', 'tir', 'ons', 'tor', 'fre', 'lør', 'søn'] // Change name of days | ||
coreDatepicker.months = ['jan', 'feb', ...] // Change name of months | ||
//JSX | ||
CoreDatepicker.days = ['man', 'tir', 'ons', 'tor', 'fre', 'lør', 'søn'] // Change name of days | ||
CoreDatepicker.months = ['jan', 'feb', ...] // Change name of months | ||
``` |
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
309
117420
892