DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Code To Disable YUI Calendar Previous And Next Month Links Icons

03.03.2008
| 7311 views |
  • submit to reddit
        This solution does not require modifying the yui source and works on YUI version 2.5.0. It will disable the next and previous arrows based on the out of bounds dates you specify with mindate and maxdate when you configure the calendar. Requires YUI dom and a namespace called your_app.

1) attach an onRender event when you configure the calendar and before you call render

calendar.renderEvent.subscribe(YAHOO.your_app.calendar().initArrows, calendar);

2) add the following function:

YAHOO.your_app.calendar = function() {
	
	var addDays = function(date, days) {
		return YAHOO.widget.DateMath.add(date, YAHOO.widget.DateMath.DAY, days);
	};
	
	var showPreviousArrow = function(cal) {
		return showArrow(cal, cal.toDate(cal.cellDates[0]), 1);
	};

	var showNextArrow = function(cal) {
		return showArrow(cal, cal.toDate(cal.cellDates[cal.cellDates.length-1]), -1);
	};
	
	var showArrow = function(cal, startingDate, step) {
		if (!cal.isDateOOM(startingDate)) { //ie not overlapping
			return !cal.isDateOOB(addDays(startingDate, (-1 * step)));
		}
		for (var i=0; (i * step) < 7; i += step) { //iterate forwards for previous month check, backwards for next month check
			var date = addDays(startingDate, i);
			if (!cal.isDateOOM(date)) { //shortcut exit; as soon as we find an in month date we can supress the arrow
				return false;
			} else if (!cal.isDateOOB(date)) {
				return true;
			}
		}
		return false;
	};
	
	return {
		initArrows: function(type, args, cal) {
			if (!showPreviousArrow(cal)) {
				hideArrow(cal, cal.Style.CSS_NAV_LEFT);
			}

			if (!showNextArrow(cal)) {
				hideArrow(cal, cal.Style.CSS_NAV_RIGHT);
			}
		}
	};
};