forked from fullcalendar/fullcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslot_event_overlap.html
215 lines (181 loc) · 5.24 KB
/
slot_event_overlap.html
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!DOCTYPE html>
<html>
<head>
<link href='../dist/fullcalendar.css' rel='stylesheet' />
<link href='../dist/fullcalendar.print.css' rel='stylesheet' media='print' />
<script src='../lib/jquery/dist/jquery.js'></script>
<script src='../lib/moment/moment.js'></script>
<script src='../dist/fullcalendar.js'></script>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,basicWeek,agendaDay,basicDay'
},
editable: true,
defaultView: 'agendaDay',
firstHour: 0,
year: 2013,
month: 6, // July
date: 31,
events: 'slot_event_overlap.json',
eventAfterAllRender: function() {
testOverlap($('#calendar'), true, false);
}
});
$('#calendar-nooverlap').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,basicWeek,agendaDay,basicDay'
},
editable: true,
defaultView: 'agendaDay',
firstHour: 0,
year: 2013,
month: 6, // July
date: 31,
events: 'slot_event_overlap.json',
slotEventOverlap: false,
eventAfterAllRender: function() {
testOverlap($('#calendar-nooverlap'), false, false);
}
});
$('#calendar-rtl').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,basicWeek,agendaDay,basicDay'
},
editable: true,
defaultView: 'agendaDay',
firstHour: 0,
year: 2013,
month: 6, // July
date: 31,
events: 'slot_event_overlap.json',
isRTL: true,
eventAfterAllRender: function() {
testOverlap($('#calendar-rtl'), true, true);
}
});
$('#calendar-rtl-nooverlap').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,basicWeek,agendaDay,basicDay'
},
editable: true,
defaultView: 'agendaDay',
firstHour: 0,
year: 2013,
month: 6, // July
date: 31,
events: 'slot_event_overlap.json',
isRTL: true,
slotEventOverlap: false,
eventAfterAllRender: function() {
testOverlap($('#calendar-rtl-nooverlap'), false, true);
}
});
});
function testOverlap(el, allowOverlap, isRTL) {
if (_testOverlap(el, allowOverlap, isRTL)) {
el.prev('h2').find('span').css('color', 'green').text('passed');
}
else {
el.prev('h2').find('span').css('color', 'red').text('failed');
}
}
function _testOverlap(el, allowOverlap, isRTL) {
var events = el.find('.fc-event');
var cell = el.find('.fc-slot0 td');
var cellLeft = Math.round(cell.offset().left);
var cellWidth = Math.round(cell.outerWidth());
if (!events.length) { // json events probably couldn't load
console.log('need to run this from a real web server');
return false;
}
for (var i=0; i<events.length; i++) {
var event = $(events[i]);
var offset = event.offset();
var top = Math.ceil(offset.top);
var left = Math.ceil(offset.left);
var width = Math.floor(event.outerWidth());
var height = Math.floor(event.outerHeight());
if (left < cellLeft || left + width > cellLeft + cellWidth) {
console.log('event is out of bounds', event[0]);
return false;
}
if (width < 10 || height < 10) {
console.log('event is suprisingly small', event[0]);
return false;
}
if (allowOverlap) {
width /= 2; // make sure nothing overlaps the first half of the event
if (isRTL) {
left += width;
}
}
for (var j=i+1; j<events.length; j++) {
// only test again events that are ahead in the DOM, meaning they have a higher
// implicit z-index and an top of the current event
var otherEvent = $(events[j]);
var otherOffset = otherEvent.offset();
var otherTop = Math.ceil(otherOffset.top);
var otherLeft = Math.ceil(otherOffset.left);
var otherWidth = Math.floor(otherEvent.outerWidth());
var otherHeight = Math.floor(otherEvent.outerHeight());
if (
top < otherTop + otherHeight &&
top + height > otherTop &&
left < otherLeft + otherWidth &&
left + width > otherLeft
) {
console.log('failed on', event[0], otherEvent[0]);
return false; // a collision
}
}
}
if (!allowOverlap) {
// we know of certain events that should have the same width
// because they share a liquid area...
var equalwidth1 = events.filter('.equalwidth1');
if (equalwidth1.eq(0).outerWidth() - equalwidth1.eq(1).outerWidth() > 1) {
console.log('not equal width', equalwidth1.toArray());
return false;
}
var equalwidth2 = events.filter('.equalwidth2');
if (equalwidth2.eq(0).outerWidth() - equalwidth2.eq(1).outerWidth() > 1) {
console.log('not equal width', equalwidth2.toArray());
return false;
}
}
return true;
}
// TODO: add tests for viewing events in week-mode also
</script>
<style>
body {
font-size: 13px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
.calendar {
width: 900px;
margin: 50px auto;
}
</style>
</head>
<body>
<h2>Default: <span></span></h2>
<div id='calendar' class='calendar'></div>
<h2>No overlap: <span></span></h2>
<div id='calendar-nooverlap' class='calendar'></div>
<h2>RTL: <span></span></h2>
<div id='calendar-rtl' class='calendar'></div>
<h2>RTL, no overlap: <span></span></h2>
<div id='calendar-rtl-nooverlap' class='calendar'></div>
</body>
</html>