lddatetimepicker 0.0.3 → 0.0.6
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 +15 -0
- package/index.js +30 -20
- package/index.min.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v0.0.6
|
|
4
|
+
|
|
5
|
+
- even if `count-scroll = false` we should still consider scroll position to keep picker in viewport as possible.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## v0.0.5
|
|
9
|
+
|
|
10
|
+
- support `change` event when value changed.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## v0.0.4
|
|
14
|
+
|
|
15
|
+
- update widget based on initial value of host if available
|
|
16
|
+
|
|
17
|
+
|
|
3
18
|
## v0.0.3
|
|
4
19
|
|
|
5
20
|
- add `isOn` API for checking if dialog is active or not
|
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
var html, lddatetimepicker;
|
|
3
3
|
html = '<div class="lddtp">\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>';
|
|
4
4
|
lddatetimepicker = function(opt){
|
|
5
|
-
var div, r, ref$, x$, _handler, this$ = this;
|
|
5
|
+
var div, r, ref$, x$, _handler, e, this$ = this;
|
|
6
6
|
opt == null && (opt = {});
|
|
7
7
|
this.opt = opt;
|
|
8
8
|
this._enabled = {
|
|
@@ -145,7 +145,12 @@
|
|
|
145
145
|
this.host.addEventListener('input', _handler);
|
|
146
146
|
}
|
|
147
147
|
if (this.host && this.host.value) {
|
|
148
|
-
|
|
148
|
+
try {
|
|
149
|
+
this.host.value = dayjs(this.host.value).format('YYYY-MM-DDTHH:mm:ssZ');
|
|
150
|
+
this.value(this.host.value);
|
|
151
|
+
} catch (e$) {
|
|
152
|
+
e = e$;
|
|
153
|
+
}
|
|
149
154
|
} else {
|
|
150
155
|
this.update();
|
|
151
156
|
}
|
|
@@ -203,7 +208,12 @@
|
|
|
203
208
|
countScroll = true;
|
|
204
209
|
while (n && n.getAttribute) {
|
|
205
210
|
s = getComputedStyle(n);
|
|
206
|
-
if (n.nodeName === 'BODY'
|
|
211
|
+
if (n.nodeName === 'BODY') {
|
|
212
|
+
if (!nscroll) {
|
|
213
|
+
nscroll = document.scrollingElement;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (['overflow', 'overflow-y', 'overflow-x'].filter(fn$).length) {
|
|
207
217
|
if (!nscroll) {
|
|
208
218
|
nscroll = n;
|
|
209
219
|
}
|
|
@@ -223,24 +233,19 @@
|
|
|
223
233
|
}
|
|
224
234
|
stackb = nstack.getBoundingClientRect();
|
|
225
235
|
scrollb = nscroll.getBoundingClientRect();
|
|
226
|
-
scroll =
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
:
|
|
232
|
-
left: 0,
|
|
233
|
-
top: 0
|
|
234
|
-
};
|
|
235
|
-
if (hb.y + hb.height + cb.height > scrollb.y + scrollb.height) {
|
|
236
|
-
y = hb.y - stackb.y - cb.height + scroll.top - 2;
|
|
236
|
+
scroll = {
|
|
237
|
+
left: nscroll.scrollLeft,
|
|
238
|
+
top: nscroll.scrollTop
|
|
239
|
+
};
|
|
240
|
+
if (hb.y + hb.height + cb.height > scrollb.y + scrollb.height + scroll.top) {
|
|
241
|
+
y = hb.y - stackb.y - cb.height + (countScroll ? scroll.top : 0) - 2;
|
|
237
242
|
} else {
|
|
238
|
-
y = hb.y - stackb.y + hb.height + scroll.top + 2;
|
|
243
|
+
y = hb.y - stackb.y + hb.height + (countScroll ? scroll.top : 0) + 2;
|
|
239
244
|
}
|
|
240
|
-
if (hb.x + cb.width > scrollb.x + scrollb.width) {
|
|
241
|
-
x = hb.x - stackb.x + hb.width - cb.width + scroll.left;
|
|
245
|
+
if (hb.x + cb.width > scrollb.x + scrollb.width + scroll.left) {
|
|
246
|
+
x = hb.x - stackb.x + hb.width - cb.width + (countScroll ? scroll.left : 0);
|
|
242
247
|
} else {
|
|
243
|
-
x = hb.x - stackb.x + scroll.left;
|
|
248
|
+
x = hb.x - stackb.x + (countScroll ? scroll.left : 0);
|
|
244
249
|
}
|
|
245
250
|
c.style.transform = "translate(" + x + "px, " + y + "px)";
|
|
246
251
|
return ref$ = c.style, ref$.top = 0, ref$.left = 0, ref$;
|
|
@@ -249,7 +254,7 @@
|
|
|
249
254
|
}
|
|
250
255
|
},
|
|
251
256
|
update: function(now){
|
|
252
|
-
var ref$, y, m, start, ny, nm, nd, ty, tm, td, sy, sm, sd;
|
|
257
|
+
var ref$, y, m, start, ny, nm, nd, ty, tm, td, sy, sm, sd, ov, nv;
|
|
253
258
|
now = now || this.cur;
|
|
254
259
|
ref$ = [now.year(), now.month()], y = ref$[0], m = ref$[1];
|
|
255
260
|
now = dayjs(new Date(now.year(), now.month(), 1));
|
|
@@ -278,7 +283,12 @@
|
|
|
278
283
|
return n.classList.toggle('selected', sy === dy && sm === dm && sd === dd);
|
|
279
284
|
});
|
|
280
285
|
if (this.host) {
|
|
281
|
-
|
|
286
|
+
ov = this.host.value;
|
|
287
|
+
nv = this.value();
|
|
288
|
+
this.host.value = nv;
|
|
289
|
+
if (ov !== nv) {
|
|
290
|
+
return this.fire('change', nv);
|
|
291
|
+
}
|
|
282
292
|
}
|
|
283
293
|
},
|
|
284
294
|
value: function(v){
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var t;(t=function(t){var e,
|
|
1
|
+
!function(){var t;(t=function(t){var e,s=this;if(this.opt=t=null==t?{}:t,this._enabled={time:!(null!=t.time)||t.time},this.evthdr={},this.hdr={mouseup:function(t){if(t.target!==s.host)return s.root.classList.toggle("active",!1),document.removeEventListener("mouseup",s.hdr.mouseup),document.removeEventListener("keydown",s.hdr.keydown)},keydown:function(t){var e;if(s.isOn()&&(13===(e=t.keyCode)||27===e||37===e||38===e||39===e||40===e)&&s.sel)return 13===e||27===e?s.toggle(!1):(t.stopPropagation(),t.preventDefault(),s.sel=37===e?s.sel.subtract(1,"day"):39===e?s.sel.add(1,"day"):38===e?s.sel.subtract(7,"day"):40===e?s.sel.add(7,"day"):void 0,s.cur=s.sel,s.update())}},e=document.createElement("div"),t.host?(this.host="string"==typeof t.host?document.querySelector(t.host):t.host,this.host.parentNode.insertBefore(e,t.host.nextSibling),this.host.addEventListener("mouseup",function(t){return s.toggle()})):document.body.appendChild(e),e.innerHTML='<div class="lddtp">\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>',this.root=t=e.querySelector(".lddtp"),this.root.addEventListener("mouseup",function(t){return t.stopPropagation()}),this.n={ds:t.querySelector(".lddtp-ds"),t:t.querySelector(".lddtp-t"),sel:{year:t.querySelector(".lddtp-year-sel"),month:t.querySelector(".lddtp-month-sel"),hour:t.querySelector(".lddtp-hour-sel"),minute:t.querySelector(".lddtp-minute-sel")}},this.n.t.style.display=this._enabled.time?"":"none",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">'+s.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(t.querySelectorAll(".lddtp-w")),e.dc=Array.from(t.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){t=t.target;return t.classList.contains("lddtp-d")?(s.sel=dayjs(new Date(t.date.year,t.date.month,t.date.date,s.sel.hour(),s.sel.minute())),s.update(s.cur)):"-"===t.getAttribute("data-action")?(s.cur=s.cur.subtract(1,"month"),s.update(s.cur)):"+"===t.getAttribute("data-action")?(s.cur=s.cur.add(1,"month"),s.update(s.cur)):void 0}),this.n.sel.minute.addEventListener("change",function(t){return s.sel=s.sel.minute(t.target.value),s.update()}),this.n.sel.hour.addEventListener("change",function(t){return s.sel=s.sel.hour(t.target.value),s.update()}),this.n.sel.year.addEventListener("change",function(t){return s.cur=dayjs(new Date(s.n.sel.year.value,s.months.indexOf(s.n.sel.month.value),1)),s.update(s.cur)}),this.n.sel.month.addEventListener("change",function(t){return s.cur=dayjs(new Date(s.n.sel.year.value,s.months.indexOf(s.n.sel.month.value),1)),s.update(s.cur)}),this.host&&(e=debounce(function(){var t;try{return t=dayjs(s.host.value).format("YYYY-MM-DDTHH:mm:ssZ"),s.host.value=t,s.value(s.host.value)}catch(t){return t}}),this.host.addEventListener("change",e),this.host.addEventListener("input",e)),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=function(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=[],r=[],d=1,a=arguments.length;d<a;++d)r.push(arguments[d]);for(e=r,d=0,n=(s=this.evthdr[t]||[]).length;d<n;++d)i=s[d],o.push(i.apply(this,e));return o},isOn:function(){return this.root.classList.contains("active")},toggle:function(t){var e,s,n,i,o,r,d,a,l,u,h,c,p,v;if(!(t=0===arguments.length?!this.root.classList.contains("active"):t))return this.root.classList.toggle("active",!1),document.removeEventListener("mouseup",this.hdr.mouseup),void document.removeEventListener("keydown",this.hdr.keydown);for(this.isOn()||(document.addEventListener("mouseup",this.hdr.mouseup),document.addEventListener("keydown",this.hdr.keydown)),this.root.classList.toggle("active",!0),e=this.root,s=(n=this.host).parentNode,n=n.getBoundingClientRect(),i=e.getBoundingClientRect(),r=(o=[0,0])[0],d=o[1],a=(o=[null,null])[0],l=o[1],u=!0;s&&s.getAttribute&&(h=getComputedStyle(s),"BODY"===s.nodeName&&(a=a||document.scrollingElement),["overflow","overflow-y","overflow-x"].filter(m).length&&(a=a||s),"BODY"!==s.nodeName&&"static"===h.position||l||(l=s,a||(u=!1)),!a||!l);)s=s.parentNode;return c=l.getBoundingClientRect(),p=a.getBoundingClientRect(),v={left:a.scrollLeft,top:a.scrollTop},d=n.y+n.height+i.height>p.y+p.height+v.top?n.y-c.y-i.height+(u?v.top:0)-2:n.y-c.y+n.height+(u?v.top:0)+2,r=n.x+i.width>p.x+p.width+v.left?n.x-c.x+n.width-i.width+(u?v.left:0):n.x-c.x+(u?v.left:0),e.style.transform="translate("+r+"px, "+d+"px)",(o=e.style).top=0,o.left=0,o;function m(t){return"visible"!==h[t]}},update:function(t){s=[(t=t||this.cur).year(),t.month()];var o,e,r,d,a,l,u,h,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()],r=s[0],d=s[1],a=s[2],s=this.sel?[this.sel.year(),this.sel.month(),this.sel.date()]:[null,null,null],l=s[0],u=s[1],h=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",r===n&&d===i&&a===s),t.classList.toggle("selected",l===n&&u===i&&h===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?(this.sel=dayjs(t),this.cur=dayjs(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")}}),"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.6","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.6","@loadingio/debounce.js":"^1.0.1","@zbryikt/template":"^2.3.34","bootstrap":"^4.6.1","dayjs":"^1.11.0","fedep":"^1.1.7","ldcover":"^3.0.1","ldview":"^1.1.1","livescript":"^1.6.0","proxise":"^1.0.1","stylus":"^0.57.0","uglify-js":"^3.15.3","uglifycss":"^0.0.29"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["@loadingio/bootstrap.ext","@loadingio/debounce.js","@loadingio/ldquery","dayjs","bootstrap","ldcover","ldview","proxise"]},"dependencies":{"@loadingio/ldquery":"^3.0.3"}}
|