Search

7/22/2009

calendar and calendar overlay


var cal = null;
var calOverlay = new YAHOO.widget.Overlay('cal-overlay', {
xy: [-5000, -5000],
visible: false,
width: '200px'
});

// align thte cal-overlay
calOverlay.beforeShowEvent.subscribe(function () {
calOverlay.cfg.setProperty('context', [
Dom.get('cal-context'), 'tl', 'bl'
]);
});

calOverlay.setBody('
');

// render the calendar
calOverlay.renderEvent.subscribe(function () {
cal = new YAHOO.widget.Calendar("cal-container");
cal.selectEvent.subscribe(function (type, args, obj) {
Dom.get('cal-context').value = args[0][0].join('/');
calOverlay.hide();
}, cal, true);
cal.render();
});

calOverlay.render(document.body);

Event.on('cal-toggle', 'click', function () {
if (!Dom.get('cal-context').disabled) {
calOverlay.show();
}
});

// hide the cal-overlay if blur
var onCalOverlayBlur = function (e) {
var target = Event.getTarget(e);

if (!Dom.isAncestor('cal-overlay', target) && target.id != 'cal-toggle') {
calOverlay.hide();
}
};

Event.on(document.body, 'click', onCalOverlayBlur);

沒有留言: