= 0){ _this._adjustDisplay(dateProp, adj); }
}, 0.8, 500)
);
};
typematic("incrementMonth", "month", 1);
typematic("decrementMonth", "month", -1);
typematic("nextYearLabelNode", "year", 1);
typematic("previousYearLabelNode", "year", -1);
},
_adjustDisplay: function(/*String*/ part, /*int*/ amount){
// summary:
// Moves calendar forwards or backwards by months or years
// part:
// "month" or "year"
// amount:
// Number of months or years
// tags:
// private
this._setCurrentFocusAttr(this.dateFuncObj.add(this.currentFocus, part, amount));
},
_setCurrentFocusAttr: function(/*Date*/ date, /*Boolean*/ forceFocus){
// summary:
// If the calendar currently has focus, then focuses specified date,
// changing the currently displayed month/year if necessary.
// If the calendar doesn't have focus, updates currently
// displayed month/year, and sets the cell that will get focus.
// forceFocus:
// If true, will focus() the cell even if calendar itself doesn't have focus
var oldFocus = this.currentFocus,
oldCell = oldFocus ? dojo.query("[dijitDateValue=" + oldFocus.valueOf() + "]", this.domNode)[0] : null;
// round specified value to nearest day (1am to avoid issues when DST shift occurs at midnight, see #8521, #9366)
date = new this.dateClassObj(date);
date.setHours(1, 0, 0, 0);
this._set("currentFocus", date);
var currentMonth = dojo.date.stamp.toISOString(date).substring(0,7);
//We only redraw the grid if we're in a new month
if(currentMonth != this.previousMonth){
this._populateGrid();
this.previousMonth = currentMonth;
}
// set tabIndex=0 on new cell, and focus it (but only if Calendar itself is focused)
var newCell = dojo.query("[dijitDateValue='" + date.valueOf() + "']", this.domNode)[0];
newCell.setAttribute("tabIndex", this.tabIndex);
if(this._focused || forceFocus){
newCell.focus();
}
// set tabIndex=-1 on old focusable cell
if(oldCell && oldCell != newCell){
if(dojo.isWebKit){ // see #11064 about webkit bug
oldCell.setAttribute("tabIndex", "-1");
}else{
oldCell.removeAttribute("tabIndex");
}
}
},
focus: function(){
// summary:
// Focus the calendar by focusing one of the calendar cells
this._setCurrentFocusAttr(this.currentFocus, true);
},
_onMonthSelect: function(/*Number*/ newMonth){
// summary:
// Handler for when user selects a month from the drop down list
// tags:
// protected
// move to selected month, bounding by the number of days in the month
// (ex: dec 31 --> jan 28, not jan 31)
this.currentFocus = this.dateFuncObj.add(this.currentFocus, "month",
newMonth - this.currentFocus.getMonth());
this._populateGrid();
},
toggleDate : function(/*date*/ dateToToggle, /*array of dates*/ selectedDates, /*array of dates*/ unselectedDates){
//Obtain CSS class before toggling if necessary
var dateIndex = dojo.date.stamp.toISOString(dateToToggle).substring(0,10);
//If previously selected we unselect and vice-versa
if(this.value[dateIndex]){
this.unselectDate(dateToToggle, unselectedDates);
}else{
this.selectDate(dateToToggle, selectedDates);
}
},
selectDate : function(/*date*/ dateToSelect, /*array of dates*/ selectedDates){
//Selects the passed iso date, changes its class and records it in the selected dates array
var node = this._getNodeByDate(dateToSelect);
var clazz = node.className;
var dateIndex = dojo.date.stamp.toISOString(dateToSelect).substring(0,10);
this.value[dateIndex] = 1;
selectedDates.push(dateIndex);
clazz = "dijitCalendarSelectedDate " + clazz;
//We update CSS class
node.className = clazz;
},
unselectDate : function(/*date*/ dateToUnselect, /*array of dates*/ unselectedDates){
//Unselects the passed iso date, changes its class and records it in the unselected dates array
var node = this._getNodeByDate(dateToUnselect);
var clazz = node.className;
var dateIndex = dojo.date.stamp.toISOString(dateToUnselect).substring(0,10);
delete(this.value[dateIndex]);
unselectedDates.push(dateIndex);
clazz = clazz.replace("dijitCalendarSelectedDate ","");
//We update CSS class
node.className = clazz;
},
_getNodeByDate : function(/*ISO date*/ dateNode){
//return the node that corresponds to the passed ISO date
var firstDate = new this.dateClassObj(this.listOfNodes[0].dijitDateValue);
var difference = Math.abs(dojo.date.difference(firstDate, dateNode, "day"));
return this.listOfNodes[difference];
},
_onDayClick: function(/*Event*/ evt){
// summary:
// Handler for day clicks, selects the date if appropriate
// tags:
// protected
//If we coming out of selecting a range, we need to skip this onDayClick or else we
//are going to deselect a date that has just been selected or deselect one that just was
//selected
dojo.stopEvent(evt);
for(var node = evt.target; node && !node.dijitDateValue; node = node.parentNode);
if(node && !dojo.hasClass(node, "dijitCalendarDisabledDate")){
value = new this.dateClassObj(node.dijitDateValue);
if(!this.rangeJustSelected){
this.toggleDate(value,[],[]);
//To record the date that was selected prior to the one currently selected
//needed in the event we are selecting a range of dates
this.previouslySelectedDay = value;
this.set("currentFocus", value);
this.onValueSelected([dojo.date.stamp.toISOString(value).substring(0,10)]);
}else{
this.rangeJustSelected = false;
this.set("currentFocus", value);
}
}
},
_onDayMouseOver: function(/*Event*/ evt){
// summary:
// Handler for mouse over events on days, sets hovered style
// tags:
// protected
// event can occur on or the inside the td,
// set node to the | .
var node =
dojo.hasClass(evt.target, "dijitCalendarDateLabel") ?
evt.target.parentNode :
evt.target;
if(node && (node.dijitDateValue || node == this.previousYearLabelNode || node == this.nextYearLabelNode) ){
dojo.addClass(node, "dijitCalendarHoveredDate");
this._currentNode = node;
}
},
_setEndRangeAttr: function(/*Date*/ value){
// description:
// records the end of a date range
// tags:
// protected
value = new this.dateClassObj(value);
value.setHours(1); // to avoid issues when DST shift occurs at midnight, see #8521, #9366
this.endRange = value;
},
_getEndRangeAttr: function(){
// Returns the EndRange date that is set when selecting a range
var value = new this.dateClassObj(this.endRange);
value.setHours(0, 0, 0, 0); // return midnight, local time for back-compat
// If daylight savings pushes midnight to the previous date, fix the Date
// object to point at 1am so it will represent the correct day. See #9366
if(value.getDate() < this.endRange.getDate()){
value = this.dateFuncObj.add(value, "hour", 1);
}
return value;
},
_onDayMouseOut: function(/*Event*/ evt){
// summary:
// Handler for mouse out events on days, clears hovered style
// tags:
// protected
if(!this._currentNode){ return; }
// if mouse out occurs moving from | to inside | , ignore it
if(evt.relatedTarget && evt.relatedTarget.parentNode == this._currentNode){ return; }
var cls = "dijitCalendarHoveredDate";
if(dojo.hasClass(this._currentNode, "dijitCalendarActiveDate")) {
cls += " dijitCalendarActiveDate";
}
dojo.removeClass(this._currentNode, cls);
this._currentNode = null;
},
_onDayMouseDown: function(/*Event*/ evt){
var node = evt.target.parentNode;
if(node && node.dijitDateValue){
dojo.addClass(node, "dijitCalendarActiveDate");
this._currentNode = node;
}
//if shift is pressed, we know the user is selecting a range,
//in which case we are going to select a range of date
if(evt.shiftKey && this.previouslySelectedDay){
//necessary to know whether or not we are in the process of selecting a range of dates
this.selectingRange = true;
this.set('endRange', node.dijitDateValue);
this._selectRange();
}else{
this.selectingRange = false;
this.previousRangeStart = null;
this.previousRangeEnd = null;
}
},
_onDayMouseUp: function(/*Event*/ evt){
var node = evt.target.parentNode;
if(node && node.dijitDateValue){
dojo.removeClass(node, "dijitCalendarActiveDate");
}
},
//TODO: use typematic
handleKey: function(/*Event*/ evt){
// summary:
// Provides keyboard navigation of calendar.
// description:
// Called from _onKeyDown() to handle keypress on a stand alone Calendar,
// and also from `dijit.form._DateTimeTextBox` to pass a keypress event
// from the `dijit.form.DateTextBox` to be handled in this widget
// returns:
// False if the key was recognized as a navigation key,
// to indicate that the event was handled by Calendar and shouldn't be propogated
// tags:
// protected
var dk = dojo.keys,
increment = -1,
interval,
newValue = this.currentFocus;
switch(evt.keyCode){
case dk.RIGHT_ARROW:
increment = 1;
//fallthrough...
case dk.LEFT_ARROW:
interval = "day";
if(!this.isLeftToRight()){ increment *= -1; }
break;
case dk.DOWN_ARROW:
increment = 1;
//fallthrough...
case dk.UP_ARROW:
interval = "week";
break;
case dk.PAGE_DOWN:
increment = 1;
//fallthrough...
case dk.PAGE_UP:
interval = evt.ctrlKey || evt.altKey ? "year" : "month";
break;
case dk.END:
// go to the next month
newValue = this.dateFuncObj.add(newValue, "month", 1);
// subtract a day from the result when we're done
interval = "day";
//fallthrough...
case dk.HOME:
newValue = new this.dateClassObj(newValue);
newValue.setDate(1);
break;
case dk.ENTER:
case dk.SPACE:
if(evt.shiftKey && this.previouslySelectedDay){
this.selectingRange = true;
this.set('endRange', newValue);
this._selectRange();
}else{
this.selectingRange = false;
this.toggleDate(newValue,[],[]);
//We record the selected date as the previous one
//In case we are selecting the first date of a range
this.previouslySelectedDay = newValue;
this.previousRangeStart = null;
this.previousRangeEnd = null;
this.onValueSelected([dojo.date.stamp.toISOString(newValue).substring(0,10)]);
}
break;
default:
return true;
}
if(interval){
newValue = this.dateFuncObj.add(newValue, interval, increment);
}
this.set("currentFocus", newValue);
return false;
},
_onKeyDown: function(/*Event*/ evt){
// summary:
// For handling keypress events on a stand alone calendar
if(!this.handleKey(evt)){
dojo.stopEvent(evt);
}
},
_removeFromRangeLTR : function(/*date*/ beginning, /*date*/ end, /*array*/selectedDates, /*array*/unselectedDates){
//In this method we remove some dates from a range from left to right
difference = Math.abs(dojo.date.difference(beginning, end, "day"));
for(var i = 0; i <= difference; i++){
var nextDay = dojo.date.add(beginning, 'day',i);
this.toggleDate(nextDay, selectedDates, unselectedDates);
}
if(this.previousRangeEnd == null){
//necessary to keep track of the previous range's end date
this.previousRangeEnd = end;
}else{
if(dojo.date.compare(end, this.previousRangeEnd, 'date') > 0 )
this.previousRangeEnd = end;
}
if(this.previousRangeStart == null){
//necessary to keep track of the previous range's start date
this.previousRangeStart = end;
}else{
if(dojo.date.compare(end, this.previousRangeStart, 'date') > 0 )
this.previousRangeStart = end;
}
this.previouslySelectedDay = dojo.date.add(nextDay, 'day',1);
},
_removeFromRangeRTL : function(/*date*/ beginning, /*date*/ end, /*array*/selectedDates, /*array*/unselectedDates){
//If the end of the range is earlier than the beginning (back in time),
//we are going to start from the end and move backward
difference = Math.abs(dojo.date.difference(beginning, end, "day"));
for(var i = 0; i <= difference; i++){
var nextDay = dojo.date.add(beginning, 'day',-i);
this.toggleDate(nextDay, selectedDates, unselectedDates);
}
if(this.previousRangeEnd == null){
this.previousRangeEnd = end;
}else{
if(dojo.date.compare(end, this.previousRangeEnd, 'date') < 0 ){
this.previousRangeEnd = end;
}
}
if(this.previousRangeStart == null){
this.previousRangeStart = end;
}else{
if(dojo.date.compare(end, this.previousRangeStart, 'date') < 0 ){
this.previousRangeStart = end;
}
}
this.previouslySelectedDay = dojo.date.add(nextDay, 'day',-1);
},
_addToRangeRTL : function(/*date*/ beginning, /*date*/ end, /*array*/selectedDates, /*array*/unselectedDates){
difference = Math.abs(dojo.date.difference(beginning, end, "day"));
//If the end of the range is earlier than the beginning (back in time),
//we are going to start from the end and move backward
for(var i = 1; i <= difference; i++){
var nextDay = dojo.date.add(beginning, 'day',-i);
this.toggleDate(nextDay, selectedDates, unselectedDates);
}
if(this.previousRangeStart == null){
this.previousRangeStart = end;
}else{
if(dojo.date.compare(end, this.previousRangeStart, 'date') < 0 ){
this.previousRangeStart = end;
}
}
if(this.previousRangeEnd == null){
this.previousRangeEnd = beginning;
}else{
if(dojo.date.compare(beginning, this.previousRangeEnd, 'date') > 0 ){
this.previousRangeEnd = beginning;
}
}
this.previouslySelectedDay = nextDay;
},
_addToRangeLTR : function(/*date*/ beginning, /*date*/ end, /*array*/selectedDates, /*array*/unselectedDates){
//If the end of the range is later than the beginning,
//adding dates from left to right
difference = Math.abs(dojo.date.difference(beginning, end, "day"));
for(var i = 1; i <= difference; i++){
var nextDay = dojo.date.add(beginning, 'day',i);
this.toggleDate(nextDay, selectedDates, unselectedDates);
}
if(this.previousRangeStart == null){
this.previousRangeStart = beginning;
}else{
if(dojo.date.compare(beginning, this.previousRangeStart, 'date') < 0 ){
this.previousRangeStart = beginning;
}
}
if(this.previousRangeEnd == null){
this.previousRangeEnd = end;
}else{
if(dojo.date.compare(end, this.previousRangeEnd, 'date') > 0 ){
this.previousRangeEnd = end;
}
}
this.previouslySelectedDay = nextDay;
},
_selectRange : function(){
//This method will toggle the dates in the selected range.
var selectedDates = []; //Will gather the list of ISO dates that are selected
var unselectedDates = []; //Will gather the list of ISO dates that are unselected
var beginning = this.previouslySelectedDay;
var end = this.get('endRange');
if(!this.previousRangeStart && !this.previousRangeEnd){
removingFromRange = false;
}else{
if((dojo.date.compare(end, this.previousRangeStart, 'date') < 0) || (dojo.date.compare(end, this.previousRangeEnd, 'date') > 0)){
//We are adding to range
removingFromRange = false;
}else{// Otherwise we are removing from the range
removingFromRange = true;
}
}
if(removingFromRange == true){
if(dojo.date.compare(end, beginning, 'date') < 0){
//We are removing from the range, starting from the end (Right to left)
this._removeFromRangeRTL(beginning, end, selectedDates, unselectedDates);
}else{
//The end of the range is later in time than the beginning: We go from left to right
this._removeFromRangeLTR(beginning, end, selectedDates, unselectedDates);
}
}else{
//We are adding to the range
if(dojo.date.compare(end, beginning, 'date') < 0){
this._addToRangeRTL(beginning, end, selectedDates, unselectedDates);
}else{
this._addToRangeLTR(beginning, end, selectedDates, unselectedDates);
}
}
//We call the extension point with the changed dates
if(selectedDates.length > 0){
this.onValueSelected(selectedDates);
}
if(unselectedDates.length > 0){
this.onValueUnselected(unselectedDates);
}
this.rangeJustSelected = true; //Indicates that we just selected a range.
},
onValueSelected: function(/*array of ISO dates*/ dates){
// summary:
// Notification that a date cell or more were selected.
// description:
// Passes on the list of ISO dates that are selected
// tags:
// protected
},
onValueUnselected: function(/*array of ISO dates*/ dates){
// summary:
// Notification that a date cell or more were unselected.
// description:
// Passes on the list of ISO dates that are unselected
// tags:
// protected
},
onChange: function(/*Date*/ date){
// summary:
// Called only when the selected date has changed
},
_isSelectedDate: function(/*Date*/ dateObject, /*String?*/ locale){
// summary:
// Returns true if the passed date is part of the selected dates of the calendar
dateIndex = dojo.date.stamp.toISOString(dateObject).substring(0,10);
return this.value[dateIndex];
},
isDisabledDate: function(/*Date*/ dateObject, /*String?*/ locale){
// summary:
// May be overridden to disable certain dates in the calendar e.g. `isDisabledDate=dojo.date.locale.isWeekend`
// tags:
// extension
/*=====
return false; // Boolean
=====*/
},
getClassForDate: function(/*Date*/ dateObject, /*String?*/ locale){
// summary:
// May be overridden to return CSS classes to associate with the date entry for the given dateObject,
// for example to indicate a holiday in specified locale.
// tags:
// extension
/*=====
return ""; // String
=====*/
},
_sort : function(){
//This function returns a sorted version of the value array that represents the selected dates.
if(this.value == {}){return [];}
//We create an array of date objects with the dates that were selected by the user.
var selectedDates = [];
for (var selDate in this.value){
selectedDates.push(selDate);
}
//Actual sorting
selectedDates.sort(function(a, b){
var dateA=new Date(a), dateB=new Date(b);
return dateA-dateB;
});
return selectedDates;
},
_returnDatesWithIsoRanges : function(selectedDates /*Array of sorted ISO dates*/){
//this method receives a sorted array of dates and returns an array of dates and date ranges where
//such range exist. For instance when passed with selectedDates = ['2010-06-14', '2010-06-15', '2010-12-25']
//it would return [2010-06-14/2010-06-15, '2010-12-25']
var returnDates = [];
if(selectedDates.length > 1){
//initialisation
var weHaveRange = false,
rangeCount = 0,
startRange = null,
lastDayRange = null,
previousDate = dojo.date.stamp.fromISOString(selectedDates[0]);
for(var i = 1; i < selectedDates.length+1; i++){
currentDate = dojo.date.stamp.fromISOString(selectedDates[i]);
if(weHaveRange){
//We are in the middle of a range
difference = Math.abs(dojo.date.difference(previousDate, currentDate, "day"));
if(difference == 1){
//we continue with the range
lastDayRange = currentDate;
}else{
//end of the range, reset variables for maybe the next range..
range = dojo.date.stamp.toISOString(startRange).substring(0,10)
+ "/" + dojo.date.stamp.toISOString(lastDayRange).substring(0,10);
returnDates.push(range);
weHaveRange = false;
}
}else{
//We are not in a range to begin with
difference = Math.abs(dojo.date.difference(previousDate, currentDate, "day"));
if(difference == 1){
//These are two consecutive dates: This is a range!
weHaveRange = true;
startRange = previousDate;
lastDayRange = currentDate;
}else{
//this is a standalone date
returnDates.push(dojo.date.stamp.toISOString(previousDate).substring(0,10));
}
}
previousDate = currentDate;
}
return returnDates;
}else{
//If there's only one selected date we return only it
return selectedDates;
}
}
}
);
//FIXME: can we use dijit.Calendar._MonthDropDown directly?
var MonthDropDown = MultiSelectCalendar._MonthDropDown = dojo.declare("dojox.widget._MonthDropDown",
[_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], {
// summary:
// The month drop down
// months: String[]
// List of names of months, possibly w/some undefined entries for Hebrew leap months
// (ex: ["January", "February", undefined, "April", ...])
months: [],
templateString: "",
_setMonthsAttr: function(/*String[]*/ months){
this.domNode.innerHTML = dojo.map(months, function(month, idx){
return month ? " " + month + " " : "";
}).join("");
},
_onClick: function(/*Event*/ evt){
this.onChange(dojo.attr(evt.target, "month"));
},
onChange: function(/*Number*/ month){
// summary:
// Callback when month is selected from drop down
},
_onMenuHover: function(evt){
dojo.toggleClass(evt.target, "dijitCalendarMonthLabelHover", evt.type == "mouseover");
}
});
return MultiSelectCalendar;
});
|