Skip to content
Browse files

datepicker now has a year advance buttons

  • Loading branch information...
1 parent 7f60d44 commit 5e35fd66bb91bb16d72b6e8e25e2ccd153f1c983 Jason Dooley committed with etgryphon Apr 5, 2011
Showing with 17 additions and 12 deletions.
  1. +17 −12 frameworks/calendar/views/calendar.js
View
29 frameworks/calendar/views/calendar.js
@@ -19,26 +19,29 @@ SCUI.CalendarView = SC.View.extend({
mouseDown: function(evt) {
var date = this._parseSelectedDate(evt.target.id);
if (date) this.set('selectedDate', date);
+ var target = evt.target;
+ var className = target.className;
+
+ if (className.match('button')) { this.$(target).addClass('active'); }
- if (evt.target.className === 'button previous') {
- this.$('.button.previous').addClass('active');
- } else if (evt.target.className === 'button next') {
- this.$('.button.next').addClass('active');
- }
return YES;
},
mouseUp: function(evt) {
var monthStartOn = this.get('monthStartOn');
- if (evt.target.className === 'button previous active') {
- this.set('monthStartOn', monthStartOn.advance({month: -1}));
- this.$('.button.previous').removeClass('active');
- } else if (evt.target.className === 'button next active') {
- this.set('monthStartOn', monthStartOn.advance({month: 1}));
- this.$('.button.next').removeClass('active');
-
+ var className = evt.target.className, param;
+ var unit = className.match('previous') ? -1 : 1;
+
+ if (className.match('year')) {
+ param = {year: unit};
+ } else {
+ param = {month: unit};
}
+
+ this.set('monthStartOn', monthStartOn.advance(param));
+ this.$('.button.active').removeClass('active');
+
return YES;
},
@@ -55,6 +58,8 @@ SCUI.CalendarView = SC.View.extend({
.begin('div').addClass('month').text(monthStartOn.toFormattedString('%B %Y')).end()
.begin('div').addClass('button previous').end()
.begin('div').addClass('button next').end()
+ .begin('div').addClass('button previous year').end()
+ .begin('div').addClass('button next year').end()
.end()
.begin('div').addClass('body');

0 comments on commit 5e35fd6

Please sign in to comment.
Something went wrong with that request. Please try again.