From ca9ebe482c111ffa7d2512d33770be3ff448ac21 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 8 Feb 2012 16:34:26 +0800 Subject: [PATCH 1/5] fix the "jquery.date_input.zh_CN.js" short_day_names show error. --- translations/jquery.date_input.zh_CN.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translations/jquery.date_input.zh_CN.js b/translations/jquery.date_input.zh_CN.js index 92ff482..a56d456 100644 --- a/translations/jquery.date_input.zh_CN.js +++ b/translations/jquery.date_input.zh_CN.js @@ -1,5 +1,5 @@ jQuery.extend(DateInput.DEFAULT_OPTS, { month_names: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], short_month_names: ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"], - short_day_names: ["一", "二", "三", "四", "五", "六", "日"] + short_day_names: ["日", "一", "二", "三", "四", "五", "六"] }); From 087c07b94d2224c7b67071c074f648fc6f6abe37 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 8 Feb 2012 16:38:49 +0800 Subject: [PATCH 2/5] Chinese translation. Change the Chinese characters for unicode character encoding. --- translations/jquery.date_input.zh_CN.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/translations/jquery.date_input.zh_CN.js b/translations/jquery.date_input.zh_CN.js index a56d456..a3b4726 100644 --- a/translations/jquery.date_input.zh_CN.js +++ b/translations/jquery.date_input.zh_CN.js @@ -1,5 +1,5 @@ jQuery.extend(DateInput.DEFAULT_OPTS, { - month_names: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], - short_month_names: ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"], - short_day_names: ["日", "一", "二", "三", "四", "五", "六"] + month_names: ["\u4e00\u6708", "\u4e8c\u6708", "\u4e09\u6708", "\u56db\u6708", "\u4e94\u6708", "\u516d\u6708", "\u4e03\u6708", "\u516b\u6708", "\u4e5d\u6708", "\u5341\u6708", "\u5341\u4e00\u6708", "\u5341\u4e8c\u6708"], + short_month_names: ["\u4e00", "\u4e8c", "\u4e09", "\u56db", "\u4e94", "\u516d", "\u4e03", "\u516b", "\u4e5d", "\u5341", "\u5341\u4e00", "\u5341\u4e8c"], + short_day_names: ["\u65e5", "\u4e00", "\u4e8c", "\u4e09", "\u56db", "\u4e94", "\u516d"] }); From 38a0a881760eb440ef67a1d446ae7138dbc652de Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 8 Feb 2012 17:49:01 +0800 Subject: [PATCH 3/5] change the setPosition function. this.input.offset() to this.input.position(); --- jquery.date_input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.date_input.js b/jquery.date_input.js index 84ae311..d85aa17 100644 --- a/jquery.date_input.js +++ b/jquery.date_input.js @@ -216,7 +216,7 @@ DateInput.prototype = { }, setPosition: function() { - var offset = this.input.offset(); + var offset = this.input.position(); this.rootLayers.css({ top: offset.top + this.input.outerHeight(), left: offset.left From 57007ce83977ae6182f566f57cbf88a213003504 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 8 Feb 2012 19:36:02 +0800 Subject: [PATCH 4/5] fix the insideSelector error. --- jquery.date_input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.date_input.js b/jquery.date_input.js index d85aa17..0afb448 100644 --- a/jquery.date_input.js +++ b/jquery.date_input.js @@ -156,7 +156,7 @@ DateInput.prototype = { // Returns true if the given event occurred inside the date selector insideSelector: function(event) { - var offset = this.dateSelector.position(); + var offset = this.dateSelector.offset(); offset.right = offset.left + this.dateSelector.outerWidth(); offset.bottom = offset.top + this.dateSelector.outerHeight(); From 250eacbc75d75503cc883ba1d955c7f154fec2af Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 9 Feb 2012 09:22:37 +0800 Subject: [PATCH 5/5] Identify the date of the current input box, and plug-in date is set to the date of the input box. The date format is replaced by yyyy-mm - dd --- jquery.date_input.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/jquery.date_input.js b/jquery.date_input.js index 0afb448..75cbd47 100644 --- a/jquery.date_input.js +++ b/jquery.date_input.js @@ -133,6 +133,7 @@ DateInput.prototype = { }, show: function() { + this.setShowDate(); this.rootLayers.css("display", "block"); $([window, document.body]).click(this.hideIfClickOutside); this.input.unbind("focus", this.show); @@ -140,6 +141,26 @@ DateInput.prototype = { this.setPosition(); }, + //defalut set Date + setShowDate: function(){ + var _val = this.input.val(); + if(this.isDate(_val)){ + var regex = /^(\d{4})-(\d{2})-(\d{2})$/; + var r = _val.replace(regex, '$1/$2/$3'); + var y = parseInt(RegExp.$1, 10), m = parseInt(RegExp.$2, 10) - 1, d = parseInt(RegExp.$3, 10); + var _Date = new Date(y, m, d); + this.selectDate(_Date); + } + }, + + isEmpty: function(v){ + return ((v == null) || (v.length == 0)); + }, + + isDate: function(v){ + return !this.isEmpty(v) && /^(\d+)-(\d{1,2})-(\d{1,2})$/.test(v); + }, + hide: function() { this.rootLayers.css("display", "none"); $([window, document.body]).unbind("click", this.hideIfClickOutside); @@ -212,7 +233,15 @@ DateInput.prototype = { }, dateToString: function(date) { - return date.getDate() + " " + this.short_month_names[date.getMonth()] + " " + date.getFullYear(); + //return date.getDate() + " " + this.short_month_names[date.getMonth()] + " " + date.getFullYear(); + var y = date.getFullYear().toString(), m = (date.getMonth() + 1).toString(), d = date.getDate().toString(); + if(m.length == 1){ + m = "0"+ m; + } + if(d.length == 1){ + d = "0" + d; + } + return y + "-" + m + "-" + d; }, setPosition: function() {