Skip to content

Commit 01161f3

Browse files
committed
More class fixes and fix lost data attributes from original input
1 parent b838639 commit 01161f3

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/dateinput/dateinput.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
trigger,
183183
pm, nm,
184184
currYear, currMonth, currDay,
185-
value = input.attr("data-value") || conf.value || input.val(),
185+
value = input.data("value") || conf.value || input.val(),
186186
min = input.attr("min") || conf.min,
187187
max = input.attr("max") || conf.max,
188188
opened;
@@ -206,8 +206,12 @@
206206
$.each("class,disabled,id,maxlength,name,readonly,required,size,style,tabindex,title,value".split(","), function(i, attr) {
207207
tmp.attr(attr, input.attr(attr));
208208
});
209+
var data = input.data();
209210
input.replaceWith(tmp);
210211
input = tmp;
212+
for (var key in data) {
213+
input.data(key, data[key]);
214+
}
211215
}
212216
input.addClass(css.input);
213217

@@ -268,7 +272,6 @@
268272
//{{{ pick
269273

270274
function select(date, conf, e) {
271-
272275
// current value
273276
value = date;
274277
currYear = date.getFullYear();
@@ -284,8 +287,9 @@
284287
if (e.isDefaultPrevented()) { return; }
285288

286289
// formatting
287-
input.val(format(date, conf.format, conf.lang));
288-
290+
var val = format(date, conf.format, conf.lang);
291+
input.val(val).data("value", val);
292+
289293
// store value into input
290294
input.data("date", date);
291295

@@ -469,7 +473,7 @@
469473
}
470474

471475
root.css({
472-
top: pos.top + input.outerHeight({margins: true}) + conf.offset[0],
476+
top: pos.top + input.outerHeight(true) + conf.offset[0],
473477
left: pos.left + conf.offset[1]
474478
});
475479

@@ -489,7 +493,6 @@
489493
//{{{ setValue
490494

491495
setValue: function(year, month, day) {
492-
493496
var date = integer(month) >= -1 ? new Date(integer(year), integer(month), integer(day == undefined || isNaN(day) ? 1 : day)) :
494497
year || value;
495498

@@ -500,7 +503,6 @@
500503
month = date.getMonth();
501504
day = date.getDate();
502505

503-
504506
// roll year & month
505507
if (month == -1) {
506508
month = 11;
@@ -592,11 +594,11 @@
592594

593595
// current date
594596
if (isSameDay(value, date)) {
595-
a.attr("id", css.current).addClass(css.focus);
597+
a.attr("id", css.current).addClass(css.focus).addClass("calcurrent");
596598

597599
// today
598600
} else if (isSameDay(now, date)) {
599-
a.attr("id", css.today);
601+
a.attr("id", css.today).addClass("caltoday");
600602
}
601603
}
602604

@@ -618,8 +620,8 @@
618620
weeks.find("a").click(function(e) {
619621
var el = $(this);
620622
if (!el.hasClass(css.disabled)) {
621-
$("#" + css.current).removeAttr("id");
622-
el.attr("id", css.current);
623+
$("#" + css.current).removeAttr("id").removeClass("calcurrent");
624+
el.attr("id", css.current).addClass("calcurrent");
623625
select(el.data("date"), conf, e);
624626
}
625627
return false;
@@ -768,7 +770,6 @@
768770
conf.css[key] = (conf.css.prefix || '') + (val || key);
769771
}
770772
});
771-
772773
var els;
773774

774775
this.each(function() {

0 commit comments

Comments
 (0)