-
Notifications
You must be signed in to change notification settings - Fork 25
/
fullcalendar-rightclick.js
104 lines (103 loc) · 3.35 KB
/
fullcalendar-rightclick.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*!
* fullcalendar-rightclick v2.2
* Docs & License: https://github.com/mherrmann/fullcalendar-rightclick
* (c) 2015 Michael Herrmann
*/
(function($) {
function monkeyPatchViewClass(View) {
View = View.class || View;
var renderFn = 'render' in View.prototype ? 'render' : 'renderSkeleton';
var originalRender = View.prototype[renderFn];
View.prototype[renderFn] = function() {
originalRender.call(this);
if (! this.el.data('fullcalendar-rightclick')) {
this.registerRightclickListener();
this.el.data('fullcalendar-rightclick', true);
}
};
function trigger() {
throw new Error("trigger not detected");
}
function oldTrigger(triggerFn) {
return function trigger(that, jsEventName, view, dateOrEvent, jsEvent) {
return that[triggerFn](jsEventName, view, dateOrEvent, jsEvent)
};
}
if (typeof View.prototype.publiclyTrigger === 'function') {
if (View.prototype.publiclyTrigger.toString().match(/name, thisObj/)) {
// FullCalendar >= 3.1.0 && < 3.5.0:
trigger = oldTrigger('publiclyTrigger');
}
else {
// FullCalendar >= 3.5.0:
trigger = function (that, jsEventName, view, dateOrEvent, jsEvent) {
return that.publiclyTrigger(jsEventName, [ dateOrEvent, jsEvent, view ]);
};
}
} else {
// FullCalendar < 3.1.0:
trigger = oldTrigger('trigger');
}
View.prototype.registerRightclickListener = function() {
var that = this;
// FullCalendar > 3.0.1:
this.el.on('contextmenu', function(ev) {
var eventElt = $(ev.target).closest('.fc-event');
if (eventElt.length) {
var seg = eventElt.data('fc-seg');
var event;
if (typeof seg.event === 'object') {
event = seg.event;
} else {
event = seg.footprint.eventDef;
}
return trigger(that, 'eventRightclick', this, event, ev);
} else {
// Users of this library may add custom content inside
// FullCalendar's DOM structure, eg. popovers. We don't want
// to catch rightclicks on these custom elements, so we
// check that the clicked element actually lies inside one
// of FullCalendars default containers:
var fcContainer = $(ev.target).closest(
'.fc-bg, .fc-slats, .fc-content-skeleton, ' +
'.fc-bgevent-skeleton, .fc-highlight-skeleton, .fc-widget-content'
);
if (fcContainer.length) {
var cell;
if (that.coordMap) {
// FullCalendar < 2.5.0:
that.coordMap.build();
cell = that.coordMap.getCell(ev.pageX, ev.pageY);
} else {
// FullCalendar >= 2.5.0:
that.prepareHits();
var hit = that.queryHit(ev.pageX, ev.pageY);
if (typeof that.getHitSpan === 'function') {
// FullCalendar >= 2.5.0 && < 3.5.0:
cell = that.getHitSpan(hit);
} else {
// FullCalendar >= 3.5.0:
if (hit.row) {
cell = hit.component.getCellRange(hit.row, hit.col);
} else {
var componentFootprint = hit.component.getSafeHitFootprint(hit);
if (componentFootprint) {
cell = that.calendar.footprintToDateProfile(componentFootprint);
}
}
}
}
if (cell)
return trigger(that, 'dayRightclick', null, cell.start, ev);
}
}
});
};
}
var fc = $.fullCalendar;
monkeyPatchViewClass(fc.views.agenda);
monkeyPatchViewClass(fc.views.basic);
if(fc.views.timeline){
monkeyPatchViewClass(fc.views.timeline);
}
})(jQuery);