Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

about the "date_input" #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions jquery.date_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,34 @@ DateInput.prototype = {
},

show: function() {
this.setShowDate();
this.rootLayers.css("display", "block");
$([window, document.body]).click(this.hideIfClickOutside);
this.input.unbind("focus", this.show);
$(document.body).keydown(this.keydownHandler);
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);
Expand All @@ -156,7 +177,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();

Expand Down Expand Up @@ -212,11 +233,19 @@ 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() {
var offset = this.input.offset();
var offset = this.input.position();
this.rootLayers.css({
top: offset.top + this.input.outerHeight(),
left: offset.left
Expand Down
6 changes: 3 additions & 3 deletions translations/jquery.date_input.zh_CN.js
Original file line number Diff line number Diff line change
@@ -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"]
});