lddatetimepicker 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +3 -0
- package/index.js +21 -3
- package/index.min.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ Constructor options:
|
|
|
29
29
|
|
|
30
30
|
- `host`: host element ( should be an input element, if provided )
|
|
31
31
|
- `time`: default true. hide and disable time picker if false.
|
|
32
|
+
- `suppress`: default false. suppress popup when clicking host if true.
|
|
32
33
|
- `fixed`: (deprecated) default false. true to enabled fixed mode.
|
|
33
34
|
- `mode`: either `in-place`, `out-place` or `fixed`.
|
|
34
35
|
- `fixed`:
|
|
@@ -58,6 +59,8 @@ Constructor options:
|
|
|
58
59
|
- `on(n, cb)`
|
|
59
60
|
- `update()`
|
|
60
61
|
- `value()`
|
|
62
|
+
- `config(opt)`: update configuration. following options are supported:
|
|
63
|
+
- `suppress`: see constructor option for this option.
|
|
61
64
|
|
|
62
65
|
|
|
63
66
|
## License
|
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
var ref$, _c, div, r, x$, _handler, e, this$ = this;
|
|
6
6
|
opt == null && (opt = {});
|
|
7
7
|
this.opt = opt;
|
|
8
|
+
this._suppress = opt.suppress;
|
|
8
9
|
this._enabled = {
|
|
9
10
|
time: !(opt.time != null) || opt.time
|
|
10
11
|
};
|
|
@@ -67,7 +68,9 @@
|
|
|
67
68
|
? document.querySelector(opt.host)
|
|
68
69
|
: opt.host;
|
|
69
70
|
this.host.addEventListener('mouseup', function(evt){
|
|
70
|
-
|
|
71
|
+
if (!this$._suppress) {
|
|
72
|
+
return this$.toggle();
|
|
73
|
+
}
|
|
71
74
|
});
|
|
72
75
|
}
|
|
73
76
|
div.innerHTML = html;
|
|
@@ -96,7 +99,6 @@
|
|
|
96
99
|
minute: r.querySelector('.lddtp-minute-sel')
|
|
97
100
|
}
|
|
98
101
|
};
|
|
99
|
-
this.n.t.style.display = this._enabled.time ? '' : 'none';
|
|
100
102
|
this.months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
101
103
|
this.wdays = ['SUN', 'MON', 'TUE', 'WED', 'THR', 'FRI', 'SAT'];
|
|
102
104
|
this.n.ds.innerHTML = [0, 1, 2, 3, 4, 5, 6].map(function(w){
|
|
@@ -324,7 +326,10 @@
|
|
|
324
326
|
? (ref$ = [vx, vy], x = ref$[0], y = ref$[1], ref$)
|
|
325
327
|
: [ix, iy], x = ref$[0], y = ref$[1];
|
|
326
328
|
c.style.transform = "translate(" + x + "px, " + y + "px)";
|
|
327
|
-
|
|
329
|
+
ref$ = c.style;
|
|
330
|
+
ref$.top = 0;
|
|
331
|
+
ref$.left = 0;
|
|
332
|
+
return this.render();
|
|
328
333
|
function fn$(it){
|
|
329
334
|
return s[it] !== 'visible';
|
|
330
335
|
}
|
|
@@ -384,6 +389,19 @@
|
|
|
384
389
|
this._last = this.cur;
|
|
385
390
|
this.sel = this.cur = v;
|
|
386
391
|
return this.update();
|
|
392
|
+
},
|
|
393
|
+
config: function(cfg){
|
|
394
|
+
cfg == null && (cfg = {});
|
|
395
|
+
if (cfg.suppress != null) {
|
|
396
|
+
this._suppress = cfg.suppress;
|
|
397
|
+
}
|
|
398
|
+
if (cfg.time != null) {
|
|
399
|
+
this._enabled.time = cfg.time;
|
|
400
|
+
return this.render();
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
render: function(){
|
|
404
|
+
return this.n.t.style.display = this._enabled.time ? '' : 'none';
|
|
387
405
|
}
|
|
388
406
|
});
|
|
389
407
|
if (typeof module != 'undefined' && module !== null) {
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var t;(t=function(t){var e,s,n,i=this;if(this.opt=t=null==t?{}:t,this._enabled={time:!(null!=t.time)||t.time},this._zmgr=t.zmgr||null,this._mode="in-place"===(e=t.mode)||"out-place"===e||"fixed"===e?t.mode:t.fixed?"fixed":t.container?"out-place":"in-place",this.evthdr={},n=t.container){if(!("object"==typeof n&&n.isOn&&n.toggle&&n.node))throw new Error("[lddatetimepicker] `isOn`, `toggle` and `node` are all required within `container` option.");this._toggle=n.toggle,this.isOn=n.isOn,this._container=n.node,this._pos=n.position}if(this.hdr={mouseup:function(t){if(t.target!==i.host)return i._toggle(!1),document.removeEventListener("mouseup",i.hdr.mouseup),document.removeEventListener("keydown",i.hdr.keydown)},keydown:function(t){var e;if(i.isOn()&&(13===(e=t.keyCode)||27===e||37===e||38===e||39===e||40===e)&&i.sel)return 13===e||27===e?i.toggle(!1):(t.stopPropagation(),t.preventDefault(),i.sel=37===e?i.sel.subtract(1,"day"):39===e?i.sel.add(1,"day"):38===e?i.sel.subtract(7,"day"):40===e?i.sel.add(7,"day"):void 0,i.cur=i.sel,i.update())}},n=document.createElement("div"),t.host&&(this.host="string"==typeof t.host?document.querySelector(t.host):t.host,this.host.addEventListener("mouseup",function(t){return i.toggle()})),n.innerHTML='<div class="lddtp"><div>\n <div class="lddtp-h">\n <div class="lddtp-a" data-action="-"></div>\n <div class="lddtp-f"><select class="lddtp-month-sel"></select></div>\n <div class="lddtp-f"><input class="lddtp-year-sel" type="number"/></div>\n <div class="lddtp-a" data-action="+"></div>\n </div>\n <div class="lddtp-ds">\n </div>\n <div class="lddtp-t">\n <div class="lddtp-f"><select class="lddtp-hour-sel"></select></div>\n <div><b>:</b></div>\n <div class="lddtp-f"><select class="lddtp-minute-sel"></select></div>\n </div>\n <div class="lddtp-c"></div>\n</div></div>',this.root=s=n.querySelector(".lddtp"),this._container?(this._container.appendChild(n),this.root.classList.add("static","bare")):"out-place"===this._mode?document.body.appendChild(n):"fixed"!==this._mode&&this.host?this.host&&this.host.parentNode.insertBefore(n,t.host.nextSibling):(document.body.appendChild(n),this.root.classList.toggle("fixed")),this.root.addEventListener("mouseup",function(t){return t.stopPropagation()}),this.n={ds:s.querySelector(".lddtp-ds"),t:s.querySelector(".lddtp-t"),sel:{year:s.querySelector(".lddtp-year-sel"),month:s.querySelector(".lddtp-month-sel"),hour:s.querySelector(".lddtp-hour-sel"),minute:s.querySelector(".lddtp-minute-sel")}},this.
|
|
1
|
+
!function(){var t;(t=function(t){var e,s,n,i=this;if(this.opt=t=null==t?{}:t,this._suppress=t.suppress,this._enabled={time:!(null!=t.time)||t.time},this._zmgr=t.zmgr||null,this._mode="in-place"===(e=t.mode)||"out-place"===e||"fixed"===e?t.mode:t.fixed?"fixed":t.container?"out-place":"in-place",this.evthdr={},n=t.container){if(!("object"==typeof n&&n.isOn&&n.toggle&&n.node))throw new Error("[lddatetimepicker] `isOn`, `toggle` and `node` are all required within `container` option.");this._toggle=n.toggle,this.isOn=n.isOn,this._container=n.node,this._pos=n.position}if(this.hdr={mouseup:function(t){if(t.target!==i.host)return i._toggle(!1),document.removeEventListener("mouseup",i.hdr.mouseup),document.removeEventListener("keydown",i.hdr.keydown)},keydown:function(t){var e;if(i.isOn()&&(13===(e=t.keyCode)||27===e||37===e||38===e||39===e||40===e)&&i.sel)return 13===e||27===e?i.toggle(!1):(t.stopPropagation(),t.preventDefault(),i.sel=37===e?i.sel.subtract(1,"day"):39===e?i.sel.add(1,"day"):38===e?i.sel.subtract(7,"day"):40===e?i.sel.add(7,"day"):void 0,i.cur=i.sel,i.update())}},n=document.createElement("div"),t.host&&(this.host="string"==typeof t.host?document.querySelector(t.host):t.host,this.host.addEventListener("mouseup",function(t){if(!i._suppress)return i.toggle()})),n.innerHTML='<div class="lddtp"><div>\n <div class="lddtp-h">\n <div class="lddtp-a" data-action="-"></div>\n <div class="lddtp-f"><select class="lddtp-month-sel"></select></div>\n <div class="lddtp-f"><input class="lddtp-year-sel" type="number"/></div>\n <div class="lddtp-a" data-action="+"></div>\n </div>\n <div class="lddtp-ds">\n </div>\n <div class="lddtp-t">\n <div class="lddtp-f"><select class="lddtp-hour-sel"></select></div>\n <div><b>:</b></div>\n <div class="lddtp-f"><select class="lddtp-minute-sel"></select></div>\n </div>\n <div class="lddtp-c"></div>\n</div></div>',this.root=s=n.querySelector(".lddtp"),this._container?(this._container.appendChild(n),this.root.classList.add("static","bare")):"out-place"===this._mode?document.body.appendChild(n):"fixed"!==this._mode&&this.host?this.host&&this.host.parentNode.insertBefore(n,t.host.nextSibling):(document.body.appendChild(n),this.root.classList.toggle("fixed")),this.root.addEventListener("mouseup",function(t){return t.stopPropagation()}),this.n={ds:s.querySelector(".lddtp-ds"),t:s.querySelector(".lddtp-t"),sel:{year:s.querySelector(".lddtp-year-sel"),month:s.querySelector(".lddtp-month-sel"),hour:s.querySelector(".lddtp-hour-sel"),minute:s.querySelector(".lddtp-minute-sel")}},this.months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],this.wdays=["SUN","MON","TUE","WED","THR","FRI","SAT"],this.n.ds.innerHTML=[0,1,2,3,4,5,6].map(function(t){return'<div class="lddtp-w">'+i.wdays[t]+"</div>"}).join("")+[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41].map(function(t){return'<div class="lddtp-d"></div>'}).join(""),(e=this.n).dh=Array.from(s.querySelectorAll(".lddtp-w")),e.dc=Array.from(s.querySelectorAll(".lddtp-d")),e=[0,1,2].map(function(){return dayjs()}),this.cur=e[0],this.today=e[1],this.sel=e[2],this.n.sel.month.innerHTML=this.months.map(function(t){return'<option value="'+t+'">'+t+"</option>"}).join(""),(t=this.n.sel.year).setAttribute("min",1900),t.setAttribute("max",2300),t.setAttribute("value",this.today.year()),this.n.sel.hour.innerHTML=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23].map(function(t){return'<option value="'+t+'">'+(""+t).padStart(2,"0")+"</option>"}).join(""),this.n.sel.minute.innerHTML=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59].map(function(t){return'<option value="'+t+'">'+(""+t).padStart(2,"0")+"</option>"}).join(""),this.root.addEventListener("click",function(t){return"fixed"===i._mode&&t.target.classList.contains("fixed")?i.toggle(!1):(t=t.target).classList.contains("lddtp-d")?(i.sel=dayjs(new Date(t.date.year,t.date.month,t.date.date,i.sel.hour(),i.sel.minute())),i.update(i.cur)):"-"===t.getAttribute("data-action")?(i.cur=i.cur.subtract(1,"month"),i.update(i.cur)):"+"===t.getAttribute("data-action")?(i.cur=i.cur.add(1,"month"),i.update(i.cur)):t.classList.contains("lddtp-c")?i.toggle(!1):void 0}),this.n.sel.minute.addEventListener("change",function(t){return i.sel=i.sel.minute(t.target.value),i.update()}),this.n.sel.hour.addEventListener("change",function(t){return i.sel=i.sel.hour(t.target.value),i.update()}),this.n.sel.year.addEventListener("change",function(t){return i.cur=dayjs(new Date(i.n.sel.year.value,i.months.indexOf(i.n.sel.month.value),1)),i.update(i.cur)}),this.n.sel.month.addEventListener("change",function(t){return i.cur=dayjs(new Date(i.n.sel.year.value,i.months.indexOf(i.n.sel.month.value),1)),i.update(i.cur)}),this.host&&(n=debounce(function(){var t;try{return t=dayjs(i.host.value).format("YYYY-MM-DDTHH:mm:ssZ"),i.host.value=t,i.value(i.host.value)}catch(t){return t}}),this.host.addEventListener("change",n),this.host.addEventListener("input",n)),this.host&&this.host.value)try{this.host.value=dayjs(this.host.value).format("YYYY-MM-DDTHH:mm:ssZ"),this.value(this.host.value)}catch(t){0}else this.update();return this}).prototype=((t,e)=>{var s,n={}.hasOwnProperty;for(s in e)n.call(e,s)&&(t[s]=e[s]);return t})(Object.create(Object.prototype),{on:function(t,s){var n=this;return(Array.isArray(t)?t:[t]).map(function(t){var e;return((e=n.evthdr)[t]||(e[t]=[])).push(s)})},fire:function(t){for(var e,s,n,i,o=[],d=[],r=1,l=arguments.length;r<l;++r)d.push(arguments[r]);for(e=d,r=0,n=(s=this.evthdr[t]||[]).length;r<n;++r)i=s[r],o.push(i.apply(this,e));return o},isOn:function(){return this.root.classList.contains("active")},_toggle:function(t){t=t||!(null!=t)&&!this.isOn();return this._zmgr&&(t?this.root.style.zIndex=this._zmgr.add():this._zmgr.remove(this.root.style.zIndex)),this.root.classList.toggle("active",t)},toggle:function(t){var e,s,n,i,o,d,r,l,a,h,u,c,p,m,v;if(t=0===arguments.length?!this.isOn():t){if(this.isOn()||(document.addEventListener("mouseup",this.hdr.mouseup),document.addEventListener("keydown",this.hdr.keydown)),this._toggle(!0),"fixed"!==this._mode){for(t=this.root,e=(s=this.host).parentNode,s=s.getBoundingClientRect(),n=t.getBoundingClientRect(),o=(i=[0,0])[0],d=(i=[null,null])[0],r=i[1],l=!0;e&&e.getAttribute&&(a=getComputedStyle(e),"BODY"===e.nodeName&&(d=d||document.scrollingElement),["overflow","overflow-y","overflow-x"].filter(y).length&&(d=d||e),"BODY"!==e.nodeName&&"static"===a.position||r||(r=e,d)||(l=!1),!d||!r);)e=e.parentNode;return(h=r.getBoundingClientRect(),v=d.getBoundingClientRect(),u={left:d.scrollLeft,top:d.scrollTop},m="fixed"===this._mode?{left:0,top:0}:{left:document.scrollingElement.scrollLeft,top:document.scrollingElement.scrollTop},p=this._container?this._container.getBoundingClientRect():n,c=s.y+s.height+p.height>window.innerHeight+m.top?s.y-p.height+m.top-2:s.y+s.height+m.top+2,p=s.x+p.width>window.innerWidth+m.left?s.x+s.width-+m.left+p.width:s.x+m.left,m=s.y+s.height+n.height>v.y+v.height+u.top?s.y-h.y-n.height+(l?u.top:0)-2:s.y-h.y+s.height+(l?u.top:0)+2,v=s.x+n.width>v.x+v.width+u.left?s.x-h.x+s.width-n.width+(l?u.left:0):s.x-h.x+(l?u.left:0),this._pos)?this._pos({x:p,y:c,vx:p,vy:c,ix:v,iy:m}):(o=(i="out-place"===this._mode?(o=(i=[p,c])[0],i[1],i):[v,m])[0],t.style.transform="translate("+o+"px, "+i[1]+"px)",(i=t.style).top=0,i.left=0,this.render())}}else this._toggle(!1),document.removeEventListener("mouseup",this.hdr.mouseup),document.removeEventListener("keydown",this.hdr.keydown);function y(t){return"visible"!==a[t]}},update:function(t){s=[(t=t||this.cur).year(),t.month()];var o,e,d,r,l,a,h,u,s,n,c=s[1];if(t=dayjs(new Date(t.year(),t.month(),1)),o=t.subtract(t.day(),"day"),t=(s=[t.year(),t.month(),t.date()])[0],e=s[1],s=[this.today.year(),this.today.month(),this.today.date()],d=s[0],r=s[1],l=s[2],s=this.sel?[this.sel.year(),this.sel.month(),this.sel.date()]:[null,null,null],a=s[0],h=s[1],u=s[2],this.n.sel.month.value=this.months[e],this.n.sel.year.value=t,this.n.sel.minute.value=this.sel.minute(),this.n.sel.hour.value=this.sel.hour(),this.n.dc.map(function(t,e){var e=o.add(e,"day"),s=[e.year(),e.month(),e.date()],n=s[0],i=s[1],s=s[2];return t.date={year:n,month:i,date:s},t.innerText=e.date(),t.classList.toggle("dim",e.month()!==c),t.classList.toggle("today",d===n&&r===i&&l===s),t.classList.toggle("selected",a===n&&h===i&&u===s)}),this.host&&(s=this.host.value,n=this.value(),s!==(this.host.value=n)))return this.fire("change",n)},value:function(t){return arguments.length?((t=dayjs(t)).isValid()||(t=this._last||dayjs()),this._last=this.cur,this.sel=this.cur=t,this.update()):this._enabled.time?dayjs(new Date(this.sel.year(),this.sel.month(),this.sel.date(),this.sel.hour(),this.sel.minute())).format("YYYY-MM-DDTHH:mm:ssZ"):dayjs(new Date(this.sel.year(),this.sel.month(),this.sel.date())).format("YYYY-MM-DD")},config:function(t){if(null!=(t=null==t?{}:t).suppress&&(this._suppress=t.suppress),null!=t.time)return this._enabled.time=t.time,this.render()},render:function(){return this.n.t.style.display=this._enabled.time?"":"none"}}),"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.lddatetimepicker=t)}.call(this);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"lddatetimepicker","version":"0.0.
|
|
1
|
+
{"name":"lddatetimepicker","version":"0.0.12","description":"vanilla date/time picker","browser":"index.min.js","main":"index.js","scripts":{"start":"npx server -r web -o true"},"homepage":"https://github.com/loadingio/lddatetimepicker","repository":{"type":"git","url":"https://github.com/loadingio/lddatetimepicker"},"keywords":["date","time","datetime","datepicker","datetimepicker"],"author":"zbryikt","license":"MIT","devDependencies":{"@loadingio/bootstrap.ext":"^0.0.12","@loadingio/debounce.js":"^1.0.1","@zbryikt/template":"^2.4.1","bootstrap":"^4.6.1","dayjs":"^1.11.0","fedep":"^1.6.0","ldcover":"^3.5.6","ldview":"^1.7.1","livescript":"^1.6.0","proxise":"^1.0.1","stylus":"^0.57.0","uglify-js":"^3.15.3","uglifycss":"^0.0.29","zmgr":"^2.2.3"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["@loadingio/bootstrap.ext","@loadingio/debounce.js","@loadingio/ldquery","dayjs","bootstrap","ldcover","ldview","zmgr","proxise"]},"dependencies":{"@loadingio/ldquery":"^3.0.6"}}
|