mirror of
https://github.com/frappe/air-datepicker.git
synced 2026-01-14 11:01:22 +08:00
add format method
This commit is contained in:
parent
41b938eaf8
commit
ca94663d4a
48
dist/js/datepicker.js
vendored
48
dist/js/datepicker.js
vendored
@ -15,11 +15,14 @@ var Datepicker;
|
|||||||
start: '', // Start date
|
start: '', // Start date
|
||||||
weekends: [6, 0],
|
weekends: [6, 0],
|
||||||
defaultView: 'days',
|
defaultView: 'days',
|
||||||
format: 'dd.mm.yyyy',
|
dateFormat: 'dd.mm.yyyy',
|
||||||
|
|
||||||
// navigation
|
// navigation
|
||||||
prevHtml: '«',
|
prevHtml: '«',
|
||||||
nextHtml: '»'
|
nextHtml: '»',
|
||||||
|
|
||||||
|
// events
|
||||||
|
onChange: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
Datepicker = function (el, options) {
|
Datepicker = function (el, options) {
|
||||||
@ -87,6 +90,12 @@ var Datepicker;
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_triggerOnChange: function (cellType) {
|
||||||
|
var dateString = this.formatDate(this.opts.dateFormat, this.date);
|
||||||
|
|
||||||
|
this.opts.onChange(dateString, this.date, this);
|
||||||
|
},
|
||||||
|
|
||||||
next: function () {
|
next: function () {
|
||||||
var d = this.parsedDate;
|
var d = this.parsedDate;
|
||||||
switch (this.view) {
|
switch (this.view) {
|
||||||
@ -118,6 +127,30 @@ var Datepicker;
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
formatDate: function (string, date) {
|
||||||
|
var result = string,
|
||||||
|
d = this.parsedDate;
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case /dd/.test(result):
|
||||||
|
result = result.replace('dd', d.fullDate);
|
||||||
|
case /d/.test(result):
|
||||||
|
result = result.replace('d', d.date);
|
||||||
|
case /mm/.test(result):
|
||||||
|
result = result.replace('mm',d.fullMonth);
|
||||||
|
case /m/.test(result):
|
||||||
|
result = result.replace('m',d.month + 1);
|
||||||
|
case /MM/.test(result):
|
||||||
|
result = result.replace('MM', this.loc.months[d.month]);
|
||||||
|
case /yyyy/.test(result):
|
||||||
|
result = result.replace('yyyy', d.year);
|
||||||
|
case /yy/.test(result):
|
||||||
|
result = result.replace('yy', d.year.toString().slice(-2));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
get parsedDate() {
|
get parsedDate() {
|
||||||
return Datepicker.getParsedDate(this.date);
|
return Datepicker.getParsedDate(this.date);
|
||||||
},
|
},
|
||||||
@ -161,7 +194,6 @@ var Datepicker;
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Datepicker.getDaysCount = function (date) {
|
Datepicker.getDaysCount = function (date) {
|
||||||
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
||||||
};
|
};
|
||||||
@ -170,6 +202,9 @@ var Datepicker;
|
|||||||
return {
|
return {
|
||||||
year: date.getFullYear(),
|
year: date.getFullYear(),
|
||||||
month: date.getMonth(),
|
month: date.getMonth(),
|
||||||
|
fullMonth: (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1, // One based
|
||||||
|
date: date.getDate(),
|
||||||
|
fullDate: date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
|
||||||
day: date.getDay()
|
day: date.getDay()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -473,7 +508,14 @@ Datepicker.Cell = function () {
|
|||||||
|
|
||||||
_handleClick: {
|
_handleClick: {
|
||||||
days: function (el) {
|
days: function (el) {
|
||||||
|
var date = el.data('date'),
|
||||||
|
d = this.d.parsedDate;
|
||||||
|
|
||||||
|
this.d.date = new Date(d.year, d.month, date);
|
||||||
|
|
||||||
|
if (this.d.opts.onChange) {
|
||||||
|
this.d._triggerOnChange()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
months: function (el) {
|
months: function (el) {
|
||||||
var month = el.data('month'),
|
var month = el.data('month'),
|
||||||
|
|||||||
@ -15,7 +15,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<script type="text/javascript" src="dist/js/datepicker.js"></script>
|
<script type="text/javascript" src="dist/js/datepicker.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$('.calendar').datepicker();
|
$('.calendar').datepicker({
|
||||||
|
onChange: function (dateString, date, inst) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -185,7 +185,14 @@
|
|||||||
|
|
||||||
_handleClick: {
|
_handleClick: {
|
||||||
days: function (el) {
|
days: function (el) {
|
||||||
|
var date = el.data('date'),
|
||||||
|
d = this.d.parsedDate;
|
||||||
|
|
||||||
|
this.d.date = new Date(d.year, d.month, date);
|
||||||
|
|
||||||
|
if (this.d.opts.onChange) {
|
||||||
|
this.d._triggerOnChange()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
months: function (el) {
|
months: function (el) {
|
||||||
var month = el.data('month'),
|
var month = el.data('month'),
|
||||||
|
|||||||
@ -15,11 +15,14 @@ var Datepicker;
|
|||||||
start: '', // Start date
|
start: '', // Start date
|
||||||
weekends: [6, 0],
|
weekends: [6, 0],
|
||||||
defaultView: 'days',
|
defaultView: 'days',
|
||||||
format: 'dd.mm.yyyy',
|
dateFormat: 'dd.mm.yyyy',
|
||||||
|
|
||||||
// navigation
|
// navigation
|
||||||
prevHtml: '«',
|
prevHtml: '«',
|
||||||
nextHtml: '»'
|
nextHtml: '»',
|
||||||
|
|
||||||
|
// events
|
||||||
|
onChange: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
Datepicker = function (el, options) {
|
Datepicker = function (el, options) {
|
||||||
@ -87,6 +90,12 @@ var Datepicker;
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_triggerOnChange: function (cellType) {
|
||||||
|
var dateString = this.formatDate(this.opts.dateFormat, this.date);
|
||||||
|
|
||||||
|
this.opts.onChange(dateString, this.date, this);
|
||||||
|
},
|
||||||
|
|
||||||
next: function () {
|
next: function () {
|
||||||
var d = this.parsedDate;
|
var d = this.parsedDate;
|
||||||
switch (this.view) {
|
switch (this.view) {
|
||||||
@ -118,6 +127,30 @@ var Datepicker;
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
formatDate: function (string, date) {
|
||||||
|
var result = string,
|
||||||
|
d = this.parsedDate;
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case /dd/.test(result):
|
||||||
|
result = result.replace('dd', d.fullDate);
|
||||||
|
case /d/.test(result):
|
||||||
|
result = result.replace('d', d.date);
|
||||||
|
case /mm/.test(result):
|
||||||
|
result = result.replace('mm',d.fullMonth);
|
||||||
|
case /m/.test(result):
|
||||||
|
result = result.replace('m',d.month + 1);
|
||||||
|
case /MM/.test(result):
|
||||||
|
result = result.replace('MM', this.loc.months[d.month]);
|
||||||
|
case /yyyy/.test(result):
|
||||||
|
result = result.replace('yyyy', d.year);
|
||||||
|
case /yy/.test(result):
|
||||||
|
result = result.replace('yy', d.year.toString().slice(-2));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
get parsedDate() {
|
get parsedDate() {
|
||||||
return Datepicker.getParsedDate(this.date);
|
return Datepicker.getParsedDate(this.date);
|
||||||
},
|
},
|
||||||
@ -161,7 +194,6 @@ var Datepicker;
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Datepicker.getDaysCount = function (date) {
|
Datepicker.getDaysCount = function (date) {
|
||||||
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
||||||
};
|
};
|
||||||
@ -170,6 +202,9 @@ var Datepicker;
|
|||||||
return {
|
return {
|
||||||
year: date.getFullYear(),
|
year: date.getFullYear(),
|
||||||
month: date.getMonth(),
|
month: date.getMonth(),
|
||||||
|
fullMonth: (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1, // One based
|
||||||
|
date: date.getDate(),
|
||||||
|
fullDate: date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
|
||||||
day: date.getDay()
|
day: date.getDay()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -15,5 +15,4 @@ html {
|
|||||||
article {
|
article {
|
||||||
margin: 60px 0 30px;
|
margin: 60px 0 30px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user