Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Latest changes to calendar and calendar tests

  • Loading branch information...
commit e814c617a097896c9bcd3a5552549ee060eecdb7 1 parent 6b691fb
@allenrabinovich authored
View
86 build/calendar/calendar-debug.js
@@ -85,7 +85,7 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
var contentBox = this.get('contentBox'),
pane = contentBox.one("." + CAL_PANE);
pane.on("selectstart", function (ev) { ev.preventDefault();});
- pane.delegate("click", this._clickCalendar, "." + CAL_DAY, this);
+ pane.delegate("click", this._clickCalendar, "." + CAL_DAY + ", ." + CAL_PREVMONTH_DAY + ", ." + CAL_NEXTMONTH_DAY, this);
pane.delegate("keydown", this._keydownCalendar, "." + CAL_GRID, this);
pane.delegate("focus", this._focusCalendarGrid, "." + CAL_GRID, this);
pane.delegate("focus", this._focusCalendarCell, "." + CAL_DAY, this);
@@ -283,47 +283,49 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
}
break;
case("multiple"):
- if (!ev.metaKey && !ev.ctrlKey && !ev.shiftKey) {
- this._clearSelection(true);
- this._lastSelectedDate = this._nodeToDate(clickedCell);
- this._addDateToSelection(this._lastSelectedDate);
- }
- else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && !ev.shiftKey) {
- if (clickedCellIsSelected) {
- this._removeDateFromSelection(this._nodeToDate(clickedCell));
- this._lastSelectedDate = null;
- }
- else {
- this._lastSelectedDate = this._nodeToDate(clickedCell);
- this._addDateToSelection(this._lastSelectedDate);
- }
- }
- else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && ev.shiftKey) {
- if (this._lastSelectedDate) {
- var selectedDate = this._nodeToDate(clickedCell);
- this._addDateRangeToSelection(selectedDate, this._lastSelectedDate);
- this._lastSelectedDate = selectedDate;
- }
- else {
- this._lastSelectedDate = this._nodeToDate(clickedCell);
- this._addDateToSelection(this._lastSelectedDate);
- }
-
- }
- else if (ev.shiftKey) {
+ if (clickedCellIsDay) {
+ if (!ev.metaKey && !ev.ctrlKey && !ev.shiftKey) {
+ this._clearSelection(true);
+ this._lastSelectedDate = this._nodeToDate(clickedCell);
+ this._addDateToSelection(this._lastSelectedDate);
+ }
+ else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && !ev.shiftKey) {
+ if (clickedCellIsSelected) {
+ this._removeDateFromSelection(this._nodeToDate(clickedCell));
+ this._lastSelectedDate = null;
+ }
+ else {
+ this._lastSelectedDate = this._nodeToDate(clickedCell);
+ this._addDateToSelection(this._lastSelectedDate);
+ }
+ }
+ else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && ev.shiftKey) {
if (this._lastSelectedDate) {
var selectedDate = this._nodeToDate(clickedCell);
- this._clearSelection(true);
this._addDateRangeToSelection(selectedDate, this._lastSelectedDate);
this._lastSelectedDate = selectedDate;
}
else {
- this._clearSelection(true);
this._lastSelectedDate = this._nodeToDate(clickedCell);
- this._addDateToSelection(this._lastSelectedDate);
+ this._addDateToSelection(this._lastSelectedDate);
}
- }
- break;
+
+ }
+ else if (ev.shiftKey) {
+ if (this._lastSelectedDate) {
+ var selectedDate = this._nodeToDate(clickedCell);
+ this._clearSelection(true);
+ this._addDateRangeToSelection(selectedDate, this._lastSelectedDate);
+ this._lastSelectedDate = selectedDate;
+ }
+ else {
+ this._clearSelection(true);
+ this._lastSelectedDate = this._nodeToDate(clickedCell);
+ this._addDateToSelection(this._lastSelectedDate);
+ }
+ }
+ }
+ break;
}
if (clickedCellIsDay) {
@@ -362,7 +364,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
*/
subtractMonth : function (e) {
this.set("date", ydate.addMonths(this.get("date"), -1));
- e.halt();
+ if (e) {
+ e.halt();
+ }
},
/**
@@ -371,7 +375,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
*/
subtractYear : function (e) {
this.set("date", ydate.addYears(this.get("date"), -1));
- e.halt();
+ if (e) {
+ e.halt();
+ }
},
/**
@@ -380,7 +386,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
*/
addMonth : function (e) {
this.set("date", ydate.addMonths(this.get("date"), 1));
- e.halt();
+ if (e) {
+ e.halt();
+ }
},
/**
@@ -389,7 +397,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
*/
addYear : function (e) {
this.set("date", ydate.addYears(this.get("date"), 1));
- e.halt();
+ if (e) {
+ e.halt();
+ }
}
},
View
2  build/calendar/calendar-min.js
@@ -1 +1 @@
-YUI.add("calendar",function(c){var s=c.ClassNameManager.getClassName,n="calendar",e=40,p=38,t=37,i=39,f=13,g=32,m=s(n,"header"),d=s(n,"day-selected"),b=s(n,"day-highlighted"),r=s(n,"day"),a=s(n,"prevmonth-day"),o=s(n,"nextmonth-day"),j=s(n,"grid"),k=c.DataType.Date,q=c.delegate,u=s(n,"pane"),h=c.UA.os;function l(v){l.superclass.constructor.apply(this,arguments);}c.Calendar=c.extend(l,c.CalendarBase,{_keyEvents:[],_highlightedDateNode:null,_lastSelectedDate:null,initializer:function(){this.plug(c.Plugin.CalendarNavigator);this._keyEvents=[];this._highlightedDateNode=null;this._lastSelectedDate=null;},_bindCalendarEvents:function(){var v=this.get("contentBox"),w=v.one("."+u);w.on("selectstart",function(x){x.preventDefault();});w.delegate("click",this._clickCalendar,"."+r,this);w.delegate("keydown",this._keydownCalendar,"."+j,this);w.delegate("focus",this._focusCalendarGrid,"."+j,this);w.delegate("focus",this._focusCalendarCell,"."+r,this);w.delegate("blur",this._blurCalendarGrid,"."+j+",."+r,this);},_highlightDateNode:function(w){this._unhighlightCurrentDateNode();var v=this._dateToNode(w);v.focus();v.addClass(b);},_unhighlightCurrentDateNode:function(){var v=this.get("contentBox").all("."+b);if(v){v.removeClass(b);}},_getGridNumber:function(w){var v=w.get("id").split("_").reverse();return parseInt(v[0],10);},_blurCalendarGrid:function(v){this._unhighlightCurrentDateNode();},_focusCalendarCell:function(v){this._highlightedDateNode=v.target;v.stopPropagation();},_focusCalendarGrid:function(v){this._unhighlightCurrentDateNode();this._highlightedDateNode=null;},_keydownCalendar:function(D){var x=this._getGridNumber(D.target),z=!this._highlightedDateNode?null:this._nodeToDate(this._highlightedDateNode),F=D.keyCode,w=0,y="";switch(F){case e:w=7;y="s";break;case p:w=-7;y="n";break;case t:w=-1;y="w";break;case i:w=1;y="e";break;case g:case f:D.preventDefault();if(this._highlightedDateNode){var C=this.get("selectionMode");if(C==="single"&&!this._highlightedDateNode.hasClass(d)){this._clearSelection(true);this._addDateToSelection(z);}else{if(C==="multiple"||C==="multiple-sticky"){if(this._highlightedDateNode.hasClass(d)){this._removeDateFromSelection(z);}else{this._addDateToSelection(z);}}}}break;}if(F==e||F==p||F==t||F==i){if(!z){z=k.addMonths(this.get("date"),x);w=0;}D.preventDefault();var E=k.addDays(z,w),v=this.get("date"),B=k.addMonths(this.get("date"),this._paneNumber-1),A=new Date(B);B.setDate(k.daysInMonth(B));if(k.isInRange(E,v,B)){this._highlightDateNode(E);}else{if(k.isGreater(v,E)){if(!k.isGreaterOrEqual(this.get("minimumDate"),v)){this.set("date",k.addMonths(v,-1));this._highlightDateNode(E);}}else{if(k.isGreater(E,B)){if(!k.isGreaterOrEqual(A,this.get("maximumDate"))){this.set("date",k.addMonths(v,1));this._highlightDateNode(E);}}}}}},_clickCalendar:function(y){var z=y.target,w=z.hasClass(r)&&!z.hasClass(a)&&!z.hasClass(o),v=z.hasClass(d);switch(this.get("selectionMode")){case ("single"):if(w){if(!v){this._clearSelection(true);this._addDateToSelection(this._nodeToDate(z));}}break;case ("multiple-sticky"):if(w){if(v){this._removeDateFromSelection(this._nodeToDate(z));}else{this._addDateToSelection(this._nodeToDate(z));}}break;case ("multiple"):if(!y.metaKey&&!y.ctrlKey&&!y.shiftKey){this._clearSelection(true);this._lastSelectedDate=this._nodeToDate(z);this._addDateToSelection(this._lastSelectedDate);}else{if(((h=="macintosh"&&y.metaKey)||(h!="macintosh"&&y.ctrlKey))&&!y.shiftKey){if(v){this._removeDateFromSelection(this._nodeToDate(z));this._lastSelectedDate=null;}else{this._lastSelectedDate=this._nodeToDate(z);this._addDateToSelection(this._lastSelectedDate);}}else{if(((h=="macintosh"&&y.metaKey)||(h!="macintosh"&&y.ctrlKey))&&y.shiftKey){if(this._lastSelectedDate){var x=this._nodeToDate(z);this._addDateRangeToSelection(x,this._lastSelectedDate);this._lastSelectedDate=x;}else{this._lastSelectedDate=this._nodeToDate(z);this._addDateToSelection(this._lastSelectedDate);}}else{if(y.shiftKey){if(this._lastSelectedDate){var x=this._nodeToDate(z);this._clearSelection(true);this._addDateRangeToSelection(x,this._lastSelectedDate);this._lastSelectedDate=x;}else{this._clearSelection(true);this._lastSelectedDate=this._nodeToDate(z);this._addDateToSelection(this._lastSelectedDate);}}}}}break;}if(w){this.fire("dateClick",{cell:z,date:this._nodeToDate(z)});}else{if(z.hasClass(a)){this.fire("prevMonthClick");}else{if(z.hasClass(o)){this.fire("nextMonthClick");}}}},subtractMonth:function(v){this.set("date",k.addMonths(this.get("date"),-1));v.halt();},subtractYear:function(v){this.set("date",k.addYears(this.get("date"),-1));v.halt();},addMonth:function(v){this.set("date",k.addMonths(this.get("date"),1));v.halt();},addYear:function(v){this.set("date",k.addYears(this.get("date"),1));v.halt();}},{NAME:"calendar",ATTRS:{selectionMode:{value:"single"},date:{value:new Date(),lazyAdd:false,setter:function(A){var w=this._normalizeDate(A),x=k.addMonths(w,this._paneNumber-1);var y=this.get("minimumDate");var z=this.get("maximumDate");if((!y||k.isGreaterOrEqual(w,y))&&(!z||k.isGreaterOrEqual(z,x))){return w;}else{if(y&&k.isGreater(y,w)){return y;}else{if(z&&k.isGreater(x,z)){var v=k.addMonths(z,-1*(this._paneNumber-1));return v;}}}}},minimumDate:{value:null,setter:function(x){if(x){var w=this.get("date"),v=this._normalizeDate(x);if(w&&!k.isGreaterOrEqual(w,v)){this.set("date",v);}return v;}else{return this._normalizeDate(x);}}},maximumDate:{value:null,setter:function(x){if(x){var v=this.get("date"),w=this._normalizeDate(x);if(v&&!k.isGreaterOrEqual(x,k.addMonths(v,this._paneNumber-1))){this.set("date",k.addMonths(w,-1*(this._paneNumber-1)));}return w;}else{return x;}}}}});},"@VERSION@",{requires:["calendar-base","calendarnavigator"],lang:["de","en","fr","ja","nb-NO","pt-BR","ru","zh-HANT-TW"]});
+YUI.add("calendar",function(c){var s=c.ClassNameManager.getClassName,n="calendar",e=40,p=38,t=37,i=39,f=13,g=32,m=s(n,"header"),d=s(n,"day-selected"),b=s(n,"day-highlighted"),r=s(n,"day"),a=s(n,"prevmonth-day"),o=s(n,"nextmonth-day"),j=s(n,"grid"),k=c.DataType.Date,q=c.delegate,u=s(n,"pane"),h=c.UA.os;function l(v){l.superclass.constructor.apply(this,arguments);}c.Calendar=c.extend(l,c.CalendarBase,{_keyEvents:[],_highlightedDateNode:null,_lastSelectedDate:null,initializer:function(){this.plug(c.Plugin.CalendarNavigator);this._keyEvents=[];this._highlightedDateNode=null;this._lastSelectedDate=null;},_bindCalendarEvents:function(){var v=this.get("contentBox"),w=v.one("."+u);w.on("selectstart",function(x){x.preventDefault();});w.delegate("click",this._clickCalendar,"."+r+", ."+a+", ."+o,this);w.delegate("keydown",this._keydownCalendar,"."+j,this);w.delegate("focus",this._focusCalendarGrid,"."+j,this);w.delegate("focus",this._focusCalendarCell,"."+r,this);w.delegate("blur",this._blurCalendarGrid,"."+j+",."+r,this);},_highlightDateNode:function(w){this._unhighlightCurrentDateNode();var v=this._dateToNode(w);v.focus();v.addClass(b);},_unhighlightCurrentDateNode:function(){var v=this.get("contentBox").all("."+b);if(v){v.removeClass(b);}},_getGridNumber:function(w){var v=w.get("id").split("_").reverse();return parseInt(v[0],10);},_blurCalendarGrid:function(v){this._unhighlightCurrentDateNode();},_focusCalendarCell:function(v){this._highlightedDateNode=v.target;v.stopPropagation();},_focusCalendarGrid:function(v){this._unhighlightCurrentDateNode();this._highlightedDateNode=null;},_keydownCalendar:function(D){var x=this._getGridNumber(D.target),z=!this._highlightedDateNode?null:this._nodeToDate(this._highlightedDateNode),F=D.keyCode,w=0,y="";switch(F){case e:w=7;y="s";break;case p:w=-7;y="n";break;case t:w=-1;y="w";break;case i:w=1;y="e";break;case g:case f:D.preventDefault();if(this._highlightedDateNode){var C=this.get("selectionMode");if(C==="single"&&!this._highlightedDateNode.hasClass(d)){this._clearSelection(true);this._addDateToSelection(z);}else{if(C==="multiple"||C==="multiple-sticky"){if(this._highlightedDateNode.hasClass(d)){this._removeDateFromSelection(z);}else{this._addDateToSelection(z);}}}}break;}if(F==e||F==p||F==t||F==i){if(!z){z=k.addMonths(this.get("date"),x);w=0;}D.preventDefault();var E=k.addDays(z,w),v=this.get("date"),B=k.addMonths(this.get("date"),this._paneNumber-1),A=new Date(B);B.setDate(k.daysInMonth(B));if(k.isInRange(E,v,B)){this._highlightDateNode(E);}else{if(k.isGreater(v,E)){if(!k.isGreaterOrEqual(this.get("minimumDate"),v)){this.set("date",k.addMonths(v,-1));this._highlightDateNode(E);}}else{if(k.isGreater(E,B)){if(!k.isGreaterOrEqual(A,this.get("maximumDate"))){this.set("date",k.addMonths(v,1));this._highlightDateNode(E);}}}}}},_clickCalendar:function(y){var z=y.target,w=z.hasClass(r)&&!z.hasClass(a)&&!z.hasClass(o),v=z.hasClass(d);switch(this.get("selectionMode")){case ("single"):if(w){if(!v){this._clearSelection(true);this._addDateToSelection(this._nodeToDate(z));}}break;case ("multiple-sticky"):if(w){if(v){this._removeDateFromSelection(this._nodeToDate(z));}else{this._addDateToSelection(this._nodeToDate(z));}}break;case ("multiple"):if(w){if(!y.metaKey&&!y.ctrlKey&&!y.shiftKey){this._clearSelection(true);this._lastSelectedDate=this._nodeToDate(z);this._addDateToSelection(this._lastSelectedDate);}else{if(((h=="macintosh"&&y.metaKey)||(h!="macintosh"&&y.ctrlKey))&&!y.shiftKey){if(v){this._removeDateFromSelection(this._nodeToDate(z));this._lastSelectedDate=null;}else{this._lastSelectedDate=this._nodeToDate(z);this._addDateToSelection(this._lastSelectedDate);}}else{if(((h=="macintosh"&&y.metaKey)||(h!="macintosh"&&y.ctrlKey))&&y.shiftKey){if(this._lastSelectedDate){var x=this._nodeToDate(z);this._addDateRangeToSelection(x,this._lastSelectedDate);this._lastSelectedDate=x;}else{this._lastSelectedDate=this._nodeToDate(z);this._addDateToSelection(this._lastSelectedDate);}}else{if(y.shiftKey){if(this._lastSelectedDate){var x=this._nodeToDate(z);this._clearSelection(true);this._addDateRangeToSelection(x,this._lastSelectedDate);this._lastSelectedDate=x;}else{this._clearSelection(true);this._lastSelectedDate=this._nodeToDate(z);this._addDateToSelection(this._lastSelectedDate);}}}}}}break;}if(w){this.fire("dateClick",{cell:z,date:this._nodeToDate(z)});}else{if(z.hasClass(a)){this.fire("prevMonthClick");}else{if(z.hasClass(o)){this.fire("nextMonthClick");}}}},subtractMonth:function(v){this.set("date",k.addMonths(this.get("date"),-1));if(v){v.halt();}},subtractYear:function(v){this.set("date",k.addYears(this.get("date"),-1));if(v){v.halt();}},addMonth:function(v){this.set("date",k.addMonths(this.get("date"),1));if(v){v.halt();}},addYear:function(v){this.set("date",k.addYears(this.get("date"),1));if(v){v.halt();}}},{NAME:"calendar",ATTRS:{selectionMode:{value:"single"},date:{value:new Date(),lazyAdd:false,setter:function(A){var w=this._normalizeDate(A),x=k.addMonths(w,this._paneNumber-1);var y=this.get("minimumDate");var z=this.get("maximumDate");if((!y||k.isGreaterOrEqual(w,y))&&(!z||k.isGreaterOrEqual(z,x))){return w;}else{if(y&&k.isGreater(y,w)){return y;}else{if(z&&k.isGreater(x,z)){var v=k.addMonths(z,-1*(this._paneNumber-1));return v;}}}}},minimumDate:{value:null,setter:function(x){if(x){var w=this.get("date"),v=this._normalizeDate(x);if(w&&!k.isGreaterOrEqual(w,v)){this.set("date",v);}return v;}else{return this._normalizeDate(x);}}},maximumDate:{value:null,setter:function(x){if(x){var v=this.get("date"),w=this._normalizeDate(x);if(v&&!k.isGreaterOrEqual(x,k.addMonths(v,this._paneNumber-1))){this.set("date",k.addMonths(w,-1*(this._paneNumber-1)));}return w;}else{return x;}}}}});},"@VERSION@",{requires:["calendar-base","calendarnavigator"],lang:["de","en","fr","ja","nb-NO","pt-BR","ru","zh-HANT-TW"]});
View
86 build/calendar/calendar.js
@@ -85,7 +85,7 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
var contentBox = this.get('contentBox'),
pane = contentBox.one("." + CAL_PANE);
pane.on("selectstart", function (ev) { ev.preventDefault();});
- pane.delegate("click", this._clickCalendar, "." + CAL_DAY, this);
+ pane.delegate("click", this._clickCalendar, "." + CAL_DAY + ", ." + CAL_PREVMONTH_DAY + ", ." + CAL_NEXTMONTH_DAY, this);
pane.delegate("keydown", this._keydownCalendar, "." + CAL_GRID, this);
pane.delegate("focus", this._focusCalendarGrid, "." + CAL_GRID, this);
pane.delegate("focus", this._focusCalendarCell, "." + CAL_DAY, this);
@@ -283,47 +283,49 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
}
break;
case("multiple"):
- if (!ev.metaKey && !ev.ctrlKey && !ev.shiftKey) {
- this._clearSelection(true);
- this._lastSelectedDate = this._nodeToDate(clickedCell);
- this._addDateToSelection(this._lastSelectedDate);
- }
- else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && !ev.shiftKey) {
- if (clickedCellIsSelected) {
- this._removeDateFromSelection(this._nodeToDate(clickedCell));
- this._lastSelectedDate = null;
- }
- else {
- this._lastSelectedDate = this._nodeToDate(clickedCell);
- this._addDateToSelection(this._lastSelectedDate);
- }
- }
- else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && ev.shiftKey) {
- if (this._lastSelectedDate) {
- var selectedDate = this._nodeToDate(clickedCell);
- this._addDateRangeToSelection(selectedDate, this._lastSelectedDate);
- this._lastSelectedDate = selectedDate;
- }
- else {
- this._lastSelectedDate = this._nodeToDate(clickedCell);
- this._addDateToSelection(this._lastSelectedDate);
- }
-
- }
- else if (ev.shiftKey) {
+ if (clickedCellIsDay) {
+ if (!ev.metaKey && !ev.ctrlKey && !ev.shiftKey) {
+ this._clearSelection(true);
+ this._lastSelectedDate = this._nodeToDate(clickedCell);
+ this._addDateToSelection(this._lastSelectedDate);
+ }
+ else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && !ev.shiftKey) {
+ if (clickedCellIsSelected) {
+ this._removeDateFromSelection(this._nodeToDate(clickedCell));
+ this._lastSelectedDate = null;
+ }
+ else {
+ this._lastSelectedDate = this._nodeToDate(clickedCell);
+ this._addDateToSelection(this._lastSelectedDate);
+ }
+ }
+ else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && ev.shiftKey) {
if (this._lastSelectedDate) {
var selectedDate = this._nodeToDate(clickedCell);
- this._clearSelection(true);
this._addDateRangeToSelection(selectedDate, this._lastSelectedDate);
this._lastSelectedDate = selectedDate;
}
else {
- this._clearSelection(true);
this._lastSelectedDate = this._nodeToDate(clickedCell);
- this._addDateToSelection(this._lastSelectedDate);
+ this._addDateToSelection(this._lastSelectedDate);
}
- }
- break;
+
+ }
+ else if (ev.shiftKey) {
+ if (this._lastSelectedDate) {
+ var selectedDate = this._nodeToDate(clickedCell);
+ this._clearSelection(true);
+ this._addDateRangeToSelection(selectedDate, this._lastSelectedDate);
+ this._lastSelectedDate = selectedDate;
+ }
+ else {
+ this._clearSelection(true);
+ this._lastSelectedDate = this._nodeToDate(clickedCell);
+ this._addDateToSelection(this._lastSelectedDate);
+ }
+ }
+ }
+ break;
}
if (clickedCellIsDay) {
@@ -362,7 +364,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
*/
subtractMonth : function (e) {
this.set("date", ydate.addMonths(this.get("date"), -1));
- e.halt();
+ if (e) {
+ e.halt();
+ }
},
/**
@@ -371,7 +375,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
*/
subtractYear : function (e) {
this.set("date", ydate.addYears(this.get("date"), -1));
- e.halt();
+ if (e) {
+ e.halt();
+ }
},
/**
@@ -380,7 +386,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
*/
addMonth : function (e) {
this.set("date", ydate.addMonths(this.get("date"), 1));
- e.halt();
+ if (e) {
+ e.halt();
+ }
},
/**
@@ -389,7 +397,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
*/
addYear : function (e) {
this.set("date", ydate.addYears(this.get("date"), 1));
- e.halt();
+ if (e) {
+ e.halt();
+ }
}
},
View
86 src/calendar/js/calendar.js
@@ -83,7 +83,7 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
var contentBox = this.get('contentBox'),
pane = contentBox.one("." + CAL_PANE);
pane.on("selectstart", function (ev) { ev.preventDefault();});
- pane.delegate("click", this._clickCalendar, "." + CAL_DAY, this);
+ pane.delegate("click", this._clickCalendar, "." + CAL_DAY + ", ." + CAL_PREVMONTH_DAY + ", ." + CAL_NEXTMONTH_DAY, this);
pane.delegate("keydown", this._keydownCalendar, "." + CAL_GRID, this);
pane.delegate("focus", this._focusCalendarGrid, "." + CAL_GRID, this);
pane.delegate("focus", this._focusCalendarCell, "." + CAL_DAY, this);
@@ -281,47 +281,49 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
}
break;
case("multiple"):
- if (!ev.metaKey && !ev.ctrlKey && !ev.shiftKey) {
- this._clearSelection(true);
- this._lastSelectedDate = this._nodeToDate(clickedCell);
- this._addDateToSelection(this._lastSelectedDate);
- }
- else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && !ev.shiftKey) {
- if (clickedCellIsSelected) {
- this._removeDateFromSelection(this._nodeToDate(clickedCell));
- this._lastSelectedDate = null;
- }
- else {
- this._lastSelectedDate = this._nodeToDate(clickedCell);
- this._addDateToSelection(this._lastSelectedDate);
- }
- }
- else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && ev.shiftKey) {
- if (this._lastSelectedDate) {
- var selectedDate = this._nodeToDate(clickedCell);
- this._addDateRangeToSelection(selectedDate, this._lastSelectedDate);
- this._lastSelectedDate = selectedDate;
- }
- else {
- this._lastSelectedDate = this._nodeToDate(clickedCell);
- this._addDateToSelection(this._lastSelectedDate);
- }
-
- }
- else if (ev.shiftKey) {
+ if (clickedCellIsDay) {
+ if (!ev.metaKey && !ev.ctrlKey && !ev.shiftKey) {
+ this._clearSelection(true);
+ this._lastSelectedDate = this._nodeToDate(clickedCell);
+ this._addDateToSelection(this._lastSelectedDate);
+ }
+ else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && !ev.shiftKey) {
+ if (clickedCellIsSelected) {
+ this._removeDateFromSelection(this._nodeToDate(clickedCell));
+ this._lastSelectedDate = null;
+ }
+ else {
+ this._lastSelectedDate = this._nodeToDate(clickedCell);
+ this._addDateToSelection(this._lastSelectedDate);
+ }
+ }
+ else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && ev.shiftKey) {
if (this._lastSelectedDate) {
var selectedDate = this._nodeToDate(clickedCell);
- this._clearSelection(true);
this._addDateRangeToSelection(selectedDate, this._lastSelectedDate);
this._lastSelectedDate = selectedDate;
}
else {
- this._clearSelection(true);
this._lastSelectedDate = this._nodeToDate(clickedCell);
- this._addDateToSelection(this._lastSelectedDate);
+ this._addDateToSelection(this._lastSelectedDate);
}
- }
- break;
+
+ }
+ else if (ev.shiftKey) {
+ if (this._lastSelectedDate) {
+ var selectedDate = this._nodeToDate(clickedCell);
+ this._clearSelection(true);
+ this._addDateRangeToSelection(selectedDate, this._lastSelectedDate);
+ this._lastSelectedDate = selectedDate;
+ }
+ else {
+ this._clearSelection(true);
+ this._lastSelectedDate = this._nodeToDate(clickedCell);
+ this._addDateToSelection(this._lastSelectedDate);
+ }
+ }
+ }
+ break;
}
if (clickedCellIsDay) {
@@ -360,7 +362,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
*/
subtractMonth : function (e) {
this.set("date", ydate.addMonths(this.get("date"), -1));
- e.halt();
+ if (e) {
+ e.halt();
+ }
},
/**
@@ -369,7 +373,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
*/
subtractYear : function (e) {
this.set("date", ydate.addYears(this.get("date"), -1));
- e.halt();
+ if (e) {
+ e.halt();
+ }
},
/**
@@ -378,7 +384,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
*/
addMonth : function (e) {
this.set("date", ydate.addMonths(this.get("date"), 1));
- e.halt();
+ if (e) {
+ e.halt();
+ }
},
/**
@@ -387,7 +395,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
*/
addYear : function (e) {
this.set("date", ydate.addYears(this.get("date"), 1));
- e.halt();
+ if (e) {
+ e.halt();
+ }
}
},
View
102 src/calendar/tests/calendar.html
@@ -85,7 +85,6 @@
Y.Assert.areEqual(false, this.firstcalendar.get("showNextMonth"));
},
-
testBasicCalendar : function() {
var cfg = {
contentBox: "#firstcontainer",
@@ -112,6 +111,104 @@
},
+ testAddMonths : function() {
+ var cfg = {
+ contentBox: "#firstcontainer",
+ date: new Date(2011,11,5)
+ };
+
+ this.firstcalendar = new Y.Calendar(cfg);
+ this.firstcalendar.render();
+
+ //calendar is visible
+ Y.Assert.areEqual(this.firstcalendar.get('visible'), true);
+
+ //calendar date is normalized correctly
+ var calendarDate = this.firstcalendar.get("date");
+ Y.Assert.areEqual(2011, calendarDate.getFullYear());
+ Y.Assert.areEqual(11, calendarDate.getMonth());
+ Y.Assert.areEqual(1, calendarDate.getDate());
+
+ this.firstcalendar.subtractMonth();
+ this.firstcalendar.subtractMonth();
+
+ calendarDate = this.firstcalendar.get("date");
+ Y.Assert.areEqual(2011, calendarDate.getFullYear());
+ Y.Assert.areEqual(9, calendarDate.getMonth());
+ Y.Assert.areEqual(1, calendarDate.getDate());
+
+ this.firstcalendar.addMonth();
+
+ calendarDate = this.firstcalendar.get("date");
+ Y.Assert.areEqual(2011, calendarDate.getFullYear());
+ Y.Assert.areEqual(10, calendarDate.getMonth());
+ Y.Assert.areEqual(1, calendarDate.getDate());
+
+ this.firstcalendar.addYear();
+
+ calendarDate = this.firstcalendar.get("date");
+ Y.Assert.areEqual(2012, calendarDate.getFullYear());
+ Y.Assert.areEqual(10, calendarDate.getMonth());
+ Y.Assert.areEqual(1, calendarDate.getDate());
+
+ this.firstcalendar.subtractYear();
+ this.firstcalendar.subtractYear();
+
+ calendarDate = this.firstcalendar.get("date");
+ Y.Assert.areEqual(2010, calendarDate.getFullYear());
+ Y.Assert.areEqual(10, calendarDate.getMonth());
+ Y.Assert.areEqual(1, calendarDate.getDate());
+ },
+
+ testMaxMinDates : function() {
+ var cfg = {
+ contentBox: "#firstcontainer",
+ date: new Date(2011,5,1),
+ minimumDate: new Date (2011,6,1),
+ maximumDate: new Date (2011,7,1)
+ };
+
+ this.firstcalendar = new Y.Calendar(cfg);
+ this.firstcalendar.render();
+
+ //calendar is visible
+ Y.Assert.areEqual(this.firstcalendar.get('visible'), true);
+
+ //calendar date is reset correclty when minimum date is set
+ var calendarDate = this.firstcalendar.get("date");
+ Y.Assert.areEqual(2011, calendarDate.getFullYear());
+ Y.Assert.areEqual(6, calendarDate.getMonth());
+ Y.Assert.areEqual(1, calendarDate.getDate());
+
+ this.firstcalendar.set("minimumDate", new Date (2011,2,1));
+ this.firstcalendar.set("maximumDate", new Date (2011,5,1));
+
+ calendarDate = this.firstcalendar.get("date");
+ Y.Assert.areEqual(2011, calendarDate.getFullYear());
+ Y.Assert.areEqual(5, calendarDate.getMonth());
+ Y.Assert.areEqual(1, calendarDate.getDate());
+
+ this.firstcalendar.set("maximumDate", new Date (2011,8,1));
+ this.firstcalendar.set("minimumDate", new Date (2011,7,1));
+
+ calendarDate = this.firstcalendar.get("date");
+ Y.Assert.areEqual(2011, calendarDate.getFullYear());
+ Y.Assert.areEqual(7, calendarDate.getMonth());
+ Y.Assert.areEqual(1, calendarDate.getDate());
+
+ this.firstcalendar.set("date", new Date (2011, 9, 1));
+ calendarDate = this.firstcalendar.get("date");
+ Y.Assert.areEqual(2011, calendarDate.getFullYear());
+ Y.Assert.areEqual(8, calendarDate.getMonth());
+ Y.Assert.areEqual(1, calendarDate.getDate());
+
+ this.firstcalendar.set("date", new Date (2011, 6, 1));
+ calendarDate = this.firstcalendar.get("date");
+ Y.Assert.areEqual(2011, calendarDate.getFullYear());
+ Y.Assert.areEqual(7, calendarDate.getMonth());
+ Y.Assert.areEqual(1, calendarDate.getDate());
+ },
+
testSelection : function() {
var cfg = {
contentBox: "#firstcontainer",
@@ -272,6 +369,9 @@
Y.Assert.areEqual("6", Y.one("#firstcontainer").one(".calendar_col7.yui3-calendar-nextmonth-day").getContent());
Y.Assert.areEqual("7", Y.one("#firstcontainer").one(".calendar_col8.yui3-calendar-nextmonth-day").getContent());
+
+ Y.one(".calendar_col2.yui3-calendar-prevmonth-day").simulate("click");
+ Y.one(".calendar_col2.yui3-calendar-nextmonth-day").simulate("click");
},
testTwoCalendars : function () {
Please sign in to comment.
Something went wrong with that request. Please try again.