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

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 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

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

oCal.renderEvent.subscribe(hideOOBArrows, oCal);


2) add the following function:

function hideOOBArrows(type, args, oCal) {
	var firstDateOnNextPane = oCal.toDate(oCal.cellDates[oCal.cellDates.length-1])
	firstDateOnNextPane.setDate(firstDateOnNextPane.getDate()+1)
		
	if (oCal.isDateOOB(firstDateOnNextPane)) {
		var rightArrow = YAHOO.util.Dom.getElementsByClassName(oCal.Style.CSS_NAV_RIGHT, "a", oCal.oDomContainer)
		YAHOO.util.Dom.setStyle(rightArrow, "display", "none")
	}

	var lastDateOnNextPane = oCal.toDate(oCal.cellDates[0])
	lastDateOnNextPane.setDate(lastDateOnNextPane.getDate()-1)
		
	if (oCal.isDateOOB(lastDateOnNextPane)) {
		var leftArrow = YAHOO.util.Dom.getElementsByClassName(oCal.Style.CSS_NAV_LEFT, "a", oCal.oDomContainer)
		YAHOO.util.Dom.setStyle(leftArrow, "display", "none")
	}
}

OnlyOneOfClass: Extension to prototype library allowing AJAX calls to supercede / abort / cancel previous calls within a given class.

// Extension to Ajax allowing for classes of requests of which only one (the latest) is ever active at a time
// - stops queues of now-redundant requests building up / allows you to supercede one request with another easily.

// just pass in onlyLatestOfClass: 'classname' in the options of the request

Ajax.currentRequests = {};

Ajax.Responders.register({
	onCreate: function(request) {
		if (request.options.onlyLatestOfClass && Ajax.currentRequests[request.options.onlyLatestOfClass]) {
			// if a request of this class is already in progress, attempt to abort it before launching this new request
			try { Ajax.currentRequests[request.options.onlyLatestOfClass].transport.abort(); } catch(e) {}
		}
		// keep note of this request object so we can cancel it if superceded
		Ajax.currentRequests[request.options.onlyLatestOfClass] = request;
	},
	onComplete: function(request) {
		if (request.options.onlyLatestOfClass) {
			// remove the request from our cache once completed so it can be garbage collected
			Ajax.currentRequests[request.options.onlyLatestOfClass] = null;
		}
	}
});
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS