Debian Codegraph @

tests/manual/old/slot_event_overlap.html

raw
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <link href='../../dist/fullcalendar.css' rel='stylesheet' />
5 <link href='../../dist/fullcalendar.print.css' rel='stylesheet' media='print' />
6 <script src='../../node_modules/jquery/dist/jquery.js'></script>
7 <script src='../../node_modules/moment/moment.js'></script>
8 <script src='../../dist/fullcalendar.js'></script>
9 <script>
10
11 $(document).ready(function() {
12
13 $('#calendar').fullCalendar({
14 headerToolbar: {
15 left: 'prev,next today',
16 center: 'title',
17 right: 'month,week,dayGridWeek,day,dayGridDay'
18 },
19 editable: true,
20 initialView: 'day',
21 firstHour: 0,
22 year: 2013,
23 month: 6, // July
24 date: 31,
25 events: 'slot_event_overlap.json',
26 _eventsPositioned: function() {
27 testOverlap($('#calendar'), true, false);
28 }
29 });
30
31 $('#calendar-nooverlap').fullCalendar({
32 headerToolbar: {
33 left: 'prev,next today',
34 center: 'title',
35 right: 'month,week,dayGridWeek,day,dayGridDay'
36 },
37 editable: true,
38 initialView: 'day',
39 firstHour: 0,
40 year: 2013,
41 month: 6, // July
42 date: 31,
43 events: 'slot_event_overlap.json',
44 slotEventOverlap: false,
45 _eventsPositioned: function() {
46 testOverlap($('#calendar-nooverlap'), false, false);
47 }
48 });
49
50 $('#calendar-rtl').fullCalendar({
51 headerToolbar: {
52 left: 'prev,next today',
53 center: 'title',
54 right: 'month,week,dayGridWeek,day,dayGridDay'
55 },
56 editable: true,
57 initialView: 'day',
58 firstHour: 0,
59 year: 2013,
60 month: 6, // July
61 date: 31,
62 events: 'slot_event_overlap.json',
63 direction: 'rtl',
64 _eventsPositioned: function() {
65 testOverlap($('#calendar-rtl'), true, true);
66 }
67 });
68
69 $('#calendar-rtl-nooverlap').fullCalendar({
70 headerToolbar: {
71 left: 'prev,next today',
72 center: 'title',
73 right: 'month,week,dayGridWeek,day,dayGridDay'
74 },
75 editable: true,
76 initialView: 'day',
77 firstHour: 0,
78 year: 2013,
79 month: 6, // July
80 date: 31,
81 events: 'slot_event_overlap.json',
82 direction: 'rtl',
83 slotEventOverlap: false,
84 _eventsPositioned: function() {
85 testOverlap($('#calendar-rtl-nooverlap'), false, true);
86 }
87 });
88
89 });
90
91 function testOverlap(el, allowOverlap, isRtl) {
92 if (_testOverlap(el, allowOverlap, isRtl)) {
93 el.prev('h2').find('span').css('color', 'green').text('passed');
94 }
95 else {
96 el.prev('h2').find('span').css('color', 'red').text('failed');
97 }
98 }
99
100 function _testOverlap(el, allowOverlap, isRtl) {
101
102 var events = el.find('.fc-event');
103
104 var cell = el.find('.fc-slot0 td');
105 var cellLeft = Math.round(cell.offset().left);
106 var cellWidth = Math.round(cell.outerWidth());
107
108 if (!events.length) { // json events probably couldn't load
109 console.log('need to run this from a real web server');
110 return false;
111 }
112
113 for (var i=0; i<events.length; i++) {
114
115 var event = $(events[i]);
116 var offset = event.offset();
117 var top = Math.ceil(offset.top);
118 var left = Math.ceil(offset.left);
119 var width = Math.floor(event.outerWidth());
120 var height = Math.floor(event.outerHeight());
121
122 if (left < cellLeft || left + width > cellLeft + cellWidth) {
123 console.log('event is out of bounds', event[0]);
124 return false;
125 }
126
127 if (width < 10 || height < 10) {
128 console.log('event is suprisingly small', event[0]);
129 return false;
130 }
131
132 if (allowOverlap) {
133 width /= 2; // make sure nothing overlaps the first half of the event
134 if (isRtl) {
135 left += width;
136 }
137 }
138
139 for (var j=i+1; j<events.length; j++) {
140 // only test again events that are ahead in the DOM, meaning they have a higher
141 // implicit z-index and an top of the current event
142
143 var otherEvent = $(events[j]);
144 var otherOffset = otherEvent.offset();
145 var otherTop = Math.ceil(otherOffset.top);
146 var otherLeft = Math.ceil(otherOffset.left);
147 var otherWidth = Math.floor(otherEvent.outerWidth());
148 var otherHeight = Math.floor(otherEvent.outerHeight());
149
150 if (
151 top < otherTop + otherHeight &&
152 top + height > otherTop &&
153 left < otherLeft + otherWidth &&
154 left + width > otherLeft
155 ) {
156 console.log('failed on', event[0], otherEvent[0]);
157 return false; // a collision
158 }
159 }
160 }
161
162 if (!allowOverlap) {
163 // we know of certain events that should have the same width
164 // because they share a liquid area...
165
166 var equalwidth1 = events.filter('.equalwidth1');
167 if (equalwidth1.eq(0).outerWidth() - equalwidth1.eq(1).outerWidth() > 1) {
168 console.log('not equal width', equalwidth1.toArray());
169 return false;
170 }
171
172 var equalwidth2 = events.filter('.equalwidth2');
173 if (equalwidth2.eq(0).outerWidth() - equalwidth2.eq(1).outerWidth() > 1) {
174 console.log('not equal width', equalwidth2.toArray());
175 return false;
176 }
177
178 }
179
180 return true;
181 }
182
183 // TODO: add tests for viewing events in week-mode also
184
185 </script>
186 <style>
187
188 body {
189 font-size: 13px;
190 font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
191 }
192
193 .calendar {
194 width: 900px;
195 margin: 50px auto;
196 }
197
198 </style>
199 </head>
200 <body>
201
202 <h2>Default: <span></span></h2>
203 <div id='calendar' class='calendar'></div>
204
205 <h2>No overlap: <span></span></h2>
206 <div id='calendar-nooverlap' class='calendar'></div>
207
208 <h2>RTL: <span></span></h2>
209 <div id='calendar-rtl' class='calendar'></div>
210
211 <h2>RTL, no overlap: <span></span></h2>
212 <div id='calendar-rtl-nooverlap' class='calendar'></div>
213
214 </body>
215 </html>