1 YUI.add('moodle-calendar-eventmanager', function(Y) {
3 var ENAME = 'Calendar event',
7 EVENTCONTENT = 'content',
9 SHOWTIMEOUT = 'showTimeout',
10 HIDETIMEOUT = 'hideTimeout';
12 var EVENT = function(config) {
13 EVENT.superclass.constructor.apply(this, arguments);
15 Y.extend(EVENT, Y.Base, {
16 initpanelcalled : false,
17 initializer : function(config){
18 var id = this.get(EVENTID), node = this.get(EVENTNODE);
22 var td = node.ancestor('td');
23 this.publish('showevent');
24 this.publish('hideevent');
25 td.on('mouseenter', this.startShow, this);
26 td.on('mouseleave', this.startHide, this);
27 td.on('focus', this.startShow, this);
28 td.on('blur', this.startHide, this);
31 initPanel : function() {
32 if (!this.initpanelcalled) {
33 this.initpanelcalled = true;
34 var node = this.get(EVENTNODE),
35 td = node.ancestor('td'),
36 constraint = td.ancestor('div'),
38 panel = new Y.Overlay({
39 constrain : constraint,
42 points:[Y.WidgetPositionAlign.TL, Y.WidgetPositionAlign.BC]
44 headerContent : Y.Node.create('<h2 class="eventtitle">'+this.get(EVENTTITLE)+'</h2>'),
45 bodyContent : Y.Node.create('<div class="eventcontent">'+this.get(EVENTCONTENT)+'</div>'),
47 id : this.get(EVENTID)+'_panel',
48 width : Math.floor(constraint.get('offsetWidth')*0.9)+"px"
51 panel.get('boundingBox').addClass('calendar-event-panel');
52 panel.get('boundingBox').setAttribute('aria-live', 'off');
53 this.on('showevent', panel.show, panel);
54 this.on('showevent', this.setAriashow, panel);
55 this.on('hideevent', this.setAriahide, panel);
56 this.on('hideevent', panel.hide, panel);
59 startShow : function() {
60 if (this.get(SHOWTIMEOUT) !== null) {
64 this.set(SHOWTIMEOUT, setTimeout(function(){self.show();}, this.get(EVENTDELAY)));
66 cancelShow : function() {
67 clearTimeout(this.get(SHOWTIMEOUT));
69 setAriashow : function() {
70 this.get('boundingBox').setAttribute('aria-live', 'assertive');
72 setAriahide : function() {
73 this.get('boundingBox').setAttribute('aria-live', 'off');
77 this.fire('showevent');
79 startHide : function() {
80 if (this.get(HIDETIMEOUT) !== null) {
84 this.set(HIDETIMEOUT, setTimeout(function(){self.hide();}, this.get(EVENTDELAY)));
87 this.fire('hideevent');
89 cancelHide : function() {
90 clearTimeout(this.get(HIDETIMEOUT));
96 setter : function(nodeid) {
97 this.set(EVENTNODE, Y.one('#'+nodeid));
100 validator : Y.Lang.isString
103 setter : function(node) {
106 Y.fail(ENAME+': invalid event node set');
112 validator : Y.Lang.isString
115 validator : Y.Lang.isString
119 validator : Y.Lang.isNumber
129 Y.augment(EVENT, Y.EventTarget);
132 add_event : function(config) {
137 M.core_calendar = M.core_calendar || {}
138 Y.mix(M.core_calendar, EVENTMANAGER);
140 }, '@VERSION@', {requires:['base', 'node', 'event-mouseenter', 'overlay', 'moodle-calendar-eventmanager-skin', 'test']});