Skip to content

Commit 35fa801

Browse files
committed
Highlight selected date and current day.
1 parent 7b360ce commit 35fa801

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

datepicker-rewrite/date.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,29 @@ $.date = function ( datestring, formatstring ) {
7575
for (var day = 0; day < 7; day++) {
7676
week.days.push({
7777
lead: printDate.getMonth() != month,
78-
date: printDate.getDate()
78+
date: printDate.getDate(),
79+
current: this.selected && this.selected.equal(printDate),
80+
today: today.equal(printDate)
7981
});
8082
// use adjust("D", 1)?
8183
printDate.setDate(printDate.getDate() + 1);
8284
}
8385
}
8486
return result;
8587
},
88+
select: function() {
89+
this.selected = this.clone();
90+
return this;
91+
},
92+
clone: function() {
93+
return $.date(this.format(), format);
94+
},
95+
equal: function(other) {
96+
function format(date) {
97+
return $.global.format(date, "d");
98+
}
99+
return format(date) == format(other);
100+
},
86101
date: function() {
87102
return date;
88103
},
@@ -99,4 +114,6 @@ $.date = function ( datestring, formatstring ) {
99114
}
100115
}
101116

117+
var today = $.date();
118+
102119
}( jQuery ));

datepicker-rewrite/index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
</script>
4444

4545
<script id="ui-datepicker-tmpl" type="text/x-jquery-tmpl">
46-
<div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">
46+
<div class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">
4747
<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all">
4848
<a class="ui-datepicker-prev ui-corner-all" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a>
4949
<a class="ui-datepicker-next ui-corner-all" title="Next"><span class="ui-icon ui-icon-circle-triangle-e">Next</span></a>
@@ -63,9 +63,11 @@
6363
{{each(index, week) date.days()}}
6464
<tr>
6565
{{each(index, day) week.days}}
66-
<td class="">
66+
<td>
6767
{{if !day.lead}}
68-
<a class="ui-state-default" href="#">${day.date}</a>
68+
<a class="ui-state-default{{if day.current}} ui-state-active{{/if}}{{if day.today}} ui-state-highlight{{/if}}" href="#">
69+
${day.date}
70+
</a>
6971
{{/if}}
7072
</td>
7173
{{/each}}

datepicker-rewrite/picker.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ $.widget( "ui.datepicker", {
3838
this.picker.delegate( ".ui-datepicker-calendar a", "click", function( event ) {
3939
event.preventDefault();
4040
// TODO exclude clicks on lead days or handle them correctly
41-
self.date.setDay( +$( this ).text() );
41+
self.date.setDay( +$( this ).text() ).select();
4242
if ( !self.inline ) {
4343
self.element.val( self.date.format() );
4444
self.close();
45+
} else {
46+
self.refresh();
4547
}
4648
self._trigger( "select", event, {
4749
date: self.date.format(),
@@ -58,7 +60,10 @@ $.widget( "ui.datepicker", {
5860
date: this.date
5961
}).appendTo( this.picker )
6062
.find( "button" ).button().end()
61-
63+
64+
if ( this.inline ) {
65+
this.picker.children().addClass( "ui-datepicker-inline" );
66+
}
6267
// against display:none in datepicker.css
6368
this.picker.find( ".ui-datepicker" ).css( "display", "block" );
6469
this._hoverable( this.picker.find( ".ui-datepicker-header a" ) );

0 commit comments

Comments
 (0)