Never been to DZone Snippets before?

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

About this user

Rob Dupuis

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Code to disable YUI calendar previous and next month links icons

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

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


2) add the following function:

   1  
   2  YAHOO.your_app.calendar = function() {
   3  	
   4  	var addDays = function(date, days) {
   5  		return YAHOO.widget.DateMath.add(date, YAHOO.widget.DateMath.DAY, days);
   6  	};
   7  	
   8  	var showPreviousArrow = function(cal) {
   9  		return showArrow(cal, cal.toDate(cal.cellDates[0]), 1);
  10  	};
  11  
  12  	var showNextArrow = function(cal) {
  13  		return showArrow(cal, cal.toDate(cal.cellDates[cal.cellDates.length-1]), -1);
  14  	};
  15  	
  16  	var showArrow = function(cal, startingDate, step) {
  17  		if (!cal.isDateOOM(startingDate)) { //ie not overlapping
  18  			return !cal.isDateOOB(addDays(startingDate, (-1 * step)));
  19  		}
  20  		for (var i=0; (i * step) < 7; i += step) { //iterate forwards for previous month check, backwards for next month check
  21  			var date = addDays(startingDate, i);
  22  			if (!cal.isDateOOM(date)) { //shortcut exit; as soon as we find an in month date we can supress the arrow
  23  				return false;
  24  			} else if (!cal.isDateOOB(date)) {
  25  				return true;
  26  			}
  27  		}
  28  		return false;
  29  	};
  30  	
  31  	return {
  32  		initArrows: function(type, args, cal) {
  33  			if (!showPreviousArrow(cal)) {
  34  				hideArrow(cal, cal.Style.CSS_NAV_LEFT);
  35  			}
  36  
  37  			if (!showNextArrow(cal)) {
  38  				hideArrow(cal, cal.Style.CSS_NAV_RIGHT);
  39  			}
  40  		}
  41  	};
  42  };
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS