UNPKG

pq-calendar-lite

Version:
1 lines 16.3 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.calendar=t():e.calendar=t()}(window,(function(){return function(e){var t={};function n(a){if(t[a])return t[a].exports;var r=t[a]={i:a,l:!1,exports:{}};return e[a].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,a){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(a,r,function(t){return e[t]}.bind(null,r));return a},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/lib/",n(n.s=4)}([function(e,t,n){var a=n(1),r=n(2);"string"==typeof(r=r.__esModule?r.default:r)&&(r=[[e.i,r,""]]);var o={insert:"head",singleton:!1};a(r,o);e.exports=r.locals||{}},function(e,t,n){"use strict";var a,r=function(){return void 0===a&&(a=Boolean(window&&document&&document.all&&!window.atob)),a},o=function(){var e={};return function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}e[t]=n}return e[t]}}(),i=[];function c(e){for(var t=-1,n=0;n<i.length;n++)if(i[n].identifier===e){t=n;break}return t}function s(e,t){for(var n={},a=[],r=0;r<e.length;r++){var o=e[r],s=t.base?o[0]+t.base:o[0],l=n[s]||0,d="".concat(s," ").concat(l);n[s]=l+1;var u=c(d),f={css:o[1],media:o[2],sourceMap:o[3]};-1!==u?(i[u].references++,i[u].updater(f)):i.push({identifier:d,updater:v(f,t),references:1}),a.push(d)}return a}function l(e){var t=document.createElement("style"),a=e.attributes||{};if(void 0===a.nonce){var r=n.nc;r&&(a.nonce=r)}if(Object.keys(a).forEach((function(e){t.setAttribute(e,a[e])})),"function"==typeof e.insert)e.insert(t);else{var i=o(e.insert||"head");if(!i)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");i.appendChild(t)}return t}var d,u=(d=[],function(e,t){return d[e]=t,d.filter(Boolean).join("\n")});function f(e,t,n,a){var r=n?"":a.media?"@media ".concat(a.media," {").concat(a.css,"}"):a.css;if(e.styleSheet)e.styleSheet.cssText=u(t,r);else{var o=document.createTextNode(r),i=e.childNodes;i[t]&&e.removeChild(i[t]),i.length?e.insertBefore(o,i[t]):e.appendChild(o)}}function h(e,t,n){var a=n.css,r=n.media,o=n.sourceMap;if(r?e.setAttribute("media",r):e.removeAttribute("media"),o&&btoa&&(a+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(o))))," */")),e.styleSheet)e.styleSheet.cssText=a;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(a))}}var p=null,y=0;function v(e,t){var n,a,r;if(t.singleton){var o=y++;n=p||(p=l(t)),a=f.bind(null,n,o,!1),r=f.bind(null,n,o,!0)}else n=l(t),a=h.bind(null,n,t),r=function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(n)};return a(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;a(e=t)}else r()}}e.exports=function(e,t){(t=t||{}).singleton||"boolean"==typeof t.singleton||(t.singleton=r());var n=s(e=e||[],t);return function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){for(var a=0;a<n.length;a++){var r=c(n[a]);i[r].references--}for(var o=s(e,t),l=0;l<n.length;l++){var d=c(n[l]);0===i[d].references&&(i[d].updater(),i.splice(d,1))}n=o}}}},function(e,t,n){(t=n(3)(!1)).push([e.i,".calendar_container_3ie{width:100vw}.calendar_controller_Hhh{display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;margin-bottom:2.667vw;height:9.867vw}.calendar_showMonth_2rY{margin:0 5.333vw;font-size:5.867vw;color:#f0554a;font-weight:600;margin-bottom:0.533vw}.calendar_controllerArrow_2U9{font-size:5.867vw;position:relative;bottom:0.267vw}.calendar_weekBox_2u3{display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-ms-flex-align:center;align-items:center;height:9.6vw}.calendar_weekItem_g_8{-webkit-flex:1;-ms-flex:1;flex:1;font-size:4.267vw;text-align:center;color:#000}.calendar_weekItemAwards_1aM{-webkit-flex:1;-ms-flex:1;flex:1;font-size:4.267vw;text-align:center;color:#bdbdbd}.calendar_dayBox_3Ws{display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap}.calendar_dayItem_1pA{display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;margin:0.667vw -1px 0.667vw 0;-webkit-flex:0 0 calc(100% / 7);-ms-flex:0 0 calc(100% / 7);flex:0 0 calc(100% / 7);height:10.933vw;border:0;padding:0 !important;font-size:4vw;background:none}.calendar_dayItemWithAward_2Fe{display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;margin:0.667vw 0;-webkit-flex:0 0 12.5%;-ms-flex:0 0 12.5%;flex:0 0 12.5%;height:9.6vw;border:0;padding:0 !important;font-size:4vw;background:none}.calendar_dayItemContainer_Vm_{display:-webkit-flex;display:-ms-flexbox;display:flex;position:relative;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;width:9.6vw;height:9.6vw;border-radius:50%;transition:background-color 200ms ease;margin-left:1.6vw}.calendar_dayItemText_117{color:#000;transition:color 200ms ease}.calendar_blurDay_15z .calendar_dayItemText_117{color:#e1e4e7}.calendar_dayWithActions_2VE{width:1.333vw;height:1.333vw;border-radius:50%;position:absolute;bottom:0.533vw}.calendar_today_2oW .calendar_dayItemText_117{font-weight:bold;color:#667cff}.calendar_chooseDate_2NB .calendar_dayItemContainer_Vm_{background-color:#667cff}.calendar_chooseDate_2NB .calendar_dayItemContainer_Vm_ .calendar_dayItemText_117{color:#fff}.calendar_chooseDate_2NB .calendar_dayItemContainer_Vm_ .calendar_dayWithActions_2VE{display:none}\n",""]),t.locals={container:"calendar_container_3ie",controller:"calendar_controller_Hhh",showMonth:"calendar_showMonth_2rY",controllerArrow:"calendar_controllerArrow_2U9",weekBox:"calendar_weekBox_2u3",weekItem:"calendar_weekItem_g_8",weekItemAwards:"calendar_weekItemAwards_1aM",dayBox:"calendar_dayBox_3Ws",dayItem:"calendar_dayItem_1pA",dayItemWithAward:"calendar_dayItemWithAward_2Fe",dayItemContainer:"calendar_dayItemContainer_Vm_",dayItemText:"calendar_dayItemText_117",blurDay:"calendar_blurDay_15z",dayWithActions:"calendar_dayWithActions_2VE",today:"calendar_today_2oW",chooseDate:"calendar_chooseDate_2NB"},e.exports=t},function(e,t,n){"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var n=function(e,t){var n=e[1]||"",a=e[3];if(!a)return n;if(t&&"function"==typeof btoa){var r=(i=a,c=btoa(unescape(encodeURIComponent(JSON.stringify(i)))),s="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(c),"/*# ".concat(s," */")),o=a.sources.map((function(e){return"/*# sourceURL=".concat(a.sourceRoot||"").concat(e," */")}));return[n].concat(o).concat([r]).join("\n")}var i,c,s;return[n].join("\n")}(t,e);return t[2]?"@media ".concat(t[2]," {").concat(n,"}"):n})).join("")},t.i=function(e,n,a){"string"==typeof e&&(e=[[null,e,""]]);var r={};if(a)for(var o=0;o<this.length;o++){var i=this[o][0];null!=i&&(r[i]=!0)}for(var c=0;c<e.length;c++){var s=[].concat(e[c]);a&&r[s[0]]||(n&&(s[2]?s[2]="".concat(n," and ").concat(s[2]):s[2]=n),t.push(s))}},t}},function(e,t,n){"use strict";n.r(t);var a=function(e){return(e=e.toString())[1]?e:"0"+e},r=function(e,t){var n=document.createElement(e);return t&&(n.className=t),n},o=function(e,t){var n={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};for(var a in/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length))),n)new RegExp("("+a+")").test(t)&&(t=t.replace(RegExp.$1,1===RegExp.$1.length?n[a]:("00"+n[a]).substr((""+n[a]).length)));return t},i=n(0),c=n.n(i);function s(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function l(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?s(Object(n),!0).forEach((function(t){d(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}var f=o(new Date,"yyyy/MM/dd"),h=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e);var n={currentDate:f,format:"yyyy/MM/dd",monthFormat:"yyyy/MM/dd",chooseDate:""};t.currentDate&&(n.chooseDate=o(new Date(t.currentDate),"yyyy/MM/dd")),this.options=l(l({},n),t),this.init()}var t,n,i;return t=e,(n=[{key:"init",value:function(){this.renderContainer(),this.renderController(),this.renderContent();var e=this.options,t=e.onDayClick,n=e.format;t&&t(o(new Date(this.options.currentDate),n))}},{key:"renderContainer",value:function(){var e=this.options.el,t=r("div",c.a.container);this.options.containerEl=t,e.appendChild(t)}},{key:"renderController",value:function(){var e=this,t=this.options.containerEl,n=r("div",c.a.controller),a=r("div",c.a.showMonth),o=r("div",c.a.controllerArrow);o.innerHTML='<i class="fa fa-caret-left" style="font-size:28px; color: #000000 "></i>',o.onclick=function(){return e.switchMonth("prev")};var i=r("div",c.a.controllerArrow);i.innerHTML='<i class="fa fa-caret-right" style="font-size:28px; color: #000000 "></i>',i.onclick=function(){return e.switchMonth("next")},this.options.showMonthEl=a,this.handleShowMonth(),n.appendChild(o),n.appendChild(a),n.appendChild(i),t.appendChild(n)}},{key:"renderContent",value:function(){var e=this.options.containerEl,t=r("div",c.a.content),n=r("div");this.options.daysEl=n,this.renderDays(),t.innerHTML=this.renderWeeks(),t.appendChild(n),e.appendChild(t)}},{key:"renderWeeks",value:function(){var e=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];this.options.showAwards&&e.push("Award");var t=e.map((function(e){return"Awd"===e?"<span class=".concat(c.a.weekItemAwards,">").concat(e,"</span>"):"<span class=".concat(c.a.weekItem,">").concat(e,"</span>")}));return"<div class=".concat(c.a.weekBox,">").concat(t.join(""),"</div>")}},{key:"renderDays",value:function(){var e=this,t=this.options,n=t.chooseDate,a=t.daysEl,o=t.daysWithActions,i=t.startDay,s=this.generateCalendarGroup(),l=r("div",c.a.dayBox),d=i>=0?this.getDayValue(i):0,u=0;s.forEach((function(t,a){var i=e.options.showAwards?c.a.dayItemWithAward:c.a.dayItem,s=t.value;if("current"!==t.type&&(i="".concat(i," ").concat(c.a.blurDay)),s===f&&(i="".concat(i," ").concat(c.a.today)),s===n&&(i="".concat(i," ").concat(c.a.chooseDate)),e.options.showAwards&&a>0&&a<=31&&a%7==0){var h=r("div",i);h.setAttribute("id","award-"+a/6),l.appendChild(h)}var p=r("div",i);"current"===t.type&&(u++,p.style=e.getGradientStyling(e.getColorForDate(t.value,o))+" "+e.getBorderRadius(t.value,d,1===u),p.innerHTML="<div class=".concat(c.a.dayItemContainer,">\n <span class=").concat(c.a.dayItemText,">").concat(t.text,"</span>\n ")+e.appendActionsIconToDate(t.value,o,c.a.dayWithActions)+"\n </div>",p.onclick=function(){return e.chooseDate(p,s)}),l.appendChild(p)}));var h=a.firstChild;h?a.replaceChild(l,h):a.appendChild(l)}},{key:"generateCalendarGroup",value:function(){var e=this.options.currentDate;e=new Date(e);for(var t=new Date(this.switchMonthOfDate("prev")),n=new Date(this.switchMonthOfDate("next")),r=e.getFullYear(),o=e.getMonth()+1,i=t.getFullYear(),c=t.getMonth()+1,s=n.getFullYear(),l=n.getMonth()+1,d=new Date(r,o,0).getDate(),u=new Date("".concat(r,"/").concat(a(o),"/01")).getDay(),f=0===u?6:u-1,h=new Date(i,c,0).getDate(),p=[],y=0;y<f;y++){var v=h-y,w={text:v,type:"prev",value:"".concat(i,"/").concat(a(c),"/").concat(a(v))};p.push(w)}p.reverse();for(var g=1;g<=d;g++){var m=g,b={text:m,type:"current",value:"".concat(r,"/").concat(a(o),"/").concat(a(m))};p.push(b)}for(var D=1;p.length<42;D++){var x=D,_={text:x,type:"next",value:"".concat(s,"/").concat(a(l),"/").concat(a(x))};p.push(_)}return p}},{key:"chooseDate",value:function(e,t){var n=this.options,a=n.onDayClick,r=n.format;this.options.chooseDate=t,this.options.currentDate=t;var i=document.getElementsByClassName(c.a.chooseDate)[0];i&&i.classList.remove(c.a.chooseDate),e.classList.add(c.a.chooseDate),a&&a(o(new Date(t),r))}},{key:"switchMonth",value:function(e){this.options.currentDate=this.switchMonthOfDate(e),this.handleShowMonth(!0),this.renderDays()}},{key:"switchMonthOfDate",value:function(e){var t,n,r=this.options,o=r.currentDate,i=r.onClickPreMonth,c=r.onClickNextMonth,s=r.onMonthChange,l=(o=new Date(o)).getFullYear(),d=o.getMonth()+1;return"prev"===e?(n=l,(t=d-1)<1&&(n=l-1,t=12),i&&i()):"next"===e&&(n=l,(t=d+1)>12&&(n=l+1,t=1),c&&c()),s&&s(),"".concat(n,"/").concat(a(t),"/01")}},{key:"handleShowMonth",value:function(e){var t=this.options,n=t.showMonthEl,a=t.currentDate,r=(t.monthFormat,t.onMonthChangeClick);n.textContent=["January","February","March","April","May","June","July","August","September","October","November","December"][new Date(a).getMonth()]+" "+new Date(a).getFullYear(),e&&r(new Date(a).getFullYear()+"/"+(new Date(a).getMonth()+1)+"/01")}},{key:"appendActionsIconToDate",value:function(e,t,n){if(t&&t.length>0)for(var a in t)if(new Date(t[a].date).setHours(0,0,0,0)===new Date(e).setHours(0,0,0,0)&&t[a].xp>0)return"<div class=".concat(n,' style="background-color: ').concat(t[a].color,'" ></div>');return""}},{key:"getColorForDate",value:function(e,t){var n=new Date(e),a=n.setHours(0,0,0,0)===(new Date).setHours(0,0,0,0);if(n.getDay()>0&&!a){var r=n.getMonth();n.setDate(n.getDate()+(7-n.getDay())),n.setHours(0,0,0,0)>(new Date).setHours(0,0,0,0)&&new Date(e).setHours(0,0,0,0)<(new Date).setHours(0,0,0,0)&&n.setDate((new Date).getDate()-1),r<n.getMonth()&&(n=new Date(n.getFullYear(),r+1,0))}else n.setDate(n.getDate());if(t&&t.length>0)for(var o in t)if(new Date(t[o].date).setHours(0,0,0,0)===n.setHours(0,0,0,0))return t[o].color;return""}},{key:"getDayValue",value:function(e){return{sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6}[e.toLowerCase()]}},{key:"getGradientStyling",value:function(e){return"red"===e.toLowerCase()?"background-image: linear-gradient(#FF9976, #FFA889);":"yellow"===e.toLowerCase()?"background-image: linear-gradient(#FFE068, #FFAF66);":"blue"===e.toLowerCase()?"background-image: linear-gradient(#86E6F6, #72DFDF);":void 0}},{key:"getBorderRadius",value:function(e,t,n){var a=new Date,r=new Date(a.setDate(a.getDate()-1)).setHours(0,0,0,0),o=new Date(e).setHours(0,0,0,0),i=new Date(e).getDay();return n&&0===new Date(e).getDay()?"border-radius: 44%":r===o||0===i||this.isLastDay(e)?"border-radius: 0 44% 44% 0":i===t||1===i||n?"border-radius: 44% 0 0 44%":"border-radius: 0"}},{key:"isLastDay",value:function(e){var t=new Date(e);return 1===new Date(t.getTime()+864e5).getDate()}}])&&u(t.prototype,n),i&&u(t,i),e}();t.default=h}])}));