event-calendar 2.3.2 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -0
- data/VERSION +1 -1
- data/event-calendar.gemspec +2 -2
- data/generators/event_calendar/templates/stylesheet.css +4 -0
- data/lib/event_calendar.rb +1 -1
- data/lib/event_calendar/calendar_helper.rb +75 -65
- data/lib/generators/event_calendar/templates/javascript.js +5 -3
- data/lib/generators/event_calendar/templates/jq_javascript.js +5 -3
- data/lib/generators/event_calendar/templates/stylesheet.css +4 -0
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -180,6 +180,7 @@ The default options for the calendar are:
|
|
180
180
|
:abbrev => true,
|
181
181
|
:first_day_of_week => 0, # See note below when setting this
|
182
182
|
:show_today => true,
|
183
|
+
:show_header => true,
|
183
184
|
:month_name_text => Time.zone.now.strftime("%B %Y"),
|
184
185
|
:previous_month_text => nil,
|
185
186
|
:next_month_text => nil,
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3.
|
1
|
+
2.3.3
|
data/event-calendar.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{event-calendar}
|
8
|
-
s.version = "2.3.
|
8
|
+
s.version = "2.3.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeff Schuil"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-03-03}
|
13
13
|
s.description = %q{Rails helper for showing multiple, overlapping events across calendar days and rows.}
|
14
14
|
s.email = %q{}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/event_calendar.rb
CHANGED
@@ -57,7 +57,7 @@ module EventCalendar
|
|
57
57
|
)
|
58
58
|
end
|
59
59
|
|
60
|
-
# Create the various strips that show
|
60
|
+
# Create the various strips that show events.
|
61
61
|
def create_event_strips(strip_start, strip_end, events)
|
62
62
|
# create an inital event strip, with a nil entry for every day of the displayed days
|
63
63
|
event_strips = [[nil] * (strip_end - strip_start + 1)]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module EventCalendar
|
2
2
|
module CalendarHelper
|
3
|
-
|
3
|
+
|
4
4
|
# Returns an HTML calendar which can show multiple, overlapping events across calendar days and rows.
|
5
5
|
# Customize using CSS, the below options, and by passing in a code block.
|
6
6
|
#
|
@@ -11,6 +11,7 @@ module EventCalendar
|
|
11
11
|
# :abbrev => true # Abbreviate day names. Reads from the abbr_day_names key in the localization file.
|
12
12
|
# :first_day_of_week => 0 # Renders calendar starting on Sunday. Use 1 for Monday, and so on.
|
13
13
|
# :show_today => true # Highlights today on the calendar using CSS class.
|
14
|
+
# :show_header => true # Show the calendar's header. (month name, next, & previous links)
|
14
15
|
# :month_name_text => nil # Displayed center in header row.
|
15
16
|
# Defaults to current month name from Date::MONTHNAMES hash.
|
16
17
|
# :previous_month_text => nil # Displayed left of the month name if set
|
@@ -30,7 +31,7 @@ module EventCalendar
|
|
30
31
|
# If it is an all day event, or the event is multiple days, then it will display as usual.
|
31
32
|
# Otherwise it will display without a background color bar.
|
32
33
|
# :use_javascript => true # Outputs HTML with inline javascript so events spanning multiple days will be highlighted.
|
33
|
-
# If this option is false, cleaner HTML will be output, but events spanning multiple days will
|
34
|
+
# If this option is false, cleaner HTML will be output, but events spanning multiple days will
|
34
35
|
# not be highlighted correctly on hover, so it is only really useful if you know your calendar
|
35
36
|
# will only have single-day events. Defaults to true.
|
36
37
|
# :link_to_day_action => false # If controller action is passed,
|
@@ -47,37 +48,40 @@ module EventCalendar
|
|
47
48
|
#
|
48
49
|
def calendar(options = {}, &block)
|
49
50
|
block ||= Proc.new {|d| nil}
|
50
|
-
|
51
|
+
|
51
52
|
defaults = {
|
52
53
|
:year => (Time.zone || Time).now.year,
|
53
54
|
:month => (Time.zone || Time).now.month,
|
54
55
|
:abbrev => true,
|
55
56
|
:first_day_of_week => 0,
|
56
57
|
:show_today => true,
|
58
|
+
:show_header => true,
|
57
59
|
:month_name_text => (Time.zone || Time).now.strftime("%B %Y"),
|
58
60
|
:previous_month_text => nil,
|
59
61
|
:next_month_text => nil,
|
60
62
|
:event_strips => [],
|
61
|
-
|
63
|
+
|
62
64
|
# it would be nice to have these in the CSS file
|
63
65
|
# but they are needed to perform height calculations
|
64
66
|
:width => nil,
|
65
|
-
:height => 500,
|
67
|
+
:height => 500,
|
66
68
|
:day_names_height => 18,
|
67
69
|
:day_nums_height => 18,
|
68
70
|
:event_height => 18,
|
69
71
|
:event_margin => 1,
|
70
72
|
:event_padding_top => 2,
|
71
|
-
|
73
|
+
|
72
74
|
:use_all_day => false,
|
73
75
|
:use_javascript => true,
|
74
76
|
:link_to_day_action => false
|
75
77
|
}
|
76
78
|
options = defaults.merge options
|
77
|
-
|
79
|
+
|
78
80
|
# default month name for the given number
|
79
|
-
|
80
|
-
|
81
|
+
if options[:show_header]
|
82
|
+
options[:month_name_text] ||= I18n.translate(:'date.month_names')[options[:month]]
|
83
|
+
end
|
84
|
+
|
81
85
|
# make the height calculations
|
82
86
|
# tricky since multiple events in a day could force an increase in the set height
|
83
87
|
height = options[:day_names_height]
|
@@ -85,7 +89,7 @@ module EventCalendar
|
|
85
89
|
row_heights.each do |row_height|
|
86
90
|
height += row_height
|
87
91
|
end
|
88
|
-
|
92
|
+
|
89
93
|
# the first and last days of this calendar month
|
90
94
|
if options[:dates].is_a?(Range)
|
91
95
|
first = options[:dates].begin
|
@@ -94,7 +98,7 @@ module EventCalendar
|
|
94
98
|
first = Date.civil(options[:year], options[:month], 1)
|
95
99
|
last = Date.civil(options[:year], options[:month], -1)
|
96
100
|
end
|
97
|
-
|
101
|
+
|
98
102
|
# create the day names array [Sunday, Monday, etc...]
|
99
103
|
day_names = []
|
100
104
|
if options[:abbrev]
|
@@ -105,70 +109,73 @@ module EventCalendar
|
|
105
109
|
options[:first_day_of_week].times do
|
106
110
|
day_names.push(day_names.shift)
|
107
111
|
end
|
108
|
-
|
112
|
+
|
109
113
|
# Build the HTML string
|
110
114
|
cal = ""
|
111
|
-
|
115
|
+
|
112
116
|
# outer calendar container
|
113
117
|
cal << %(<div class="ec-calendar")
|
114
118
|
cal << %(style="width: #{options[:width]}px;") if options[:width]
|
115
119
|
cal << %(>)
|
116
|
-
|
120
|
+
|
117
121
|
# table header, including the monthname and links to prev & next month
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
122
|
+
if options[:show_header]
|
123
|
+
cal << %(<table class="ec-calendar-header" cellpadding="0" cellspacing="0">)
|
124
|
+
cal << %(<thead><tr>)
|
125
|
+
if options[:previous_month_text] or options[:next_month_text]
|
126
|
+
cal << %(<th colspan="2" class="ec-month-nav ec-previous-month">#{options[:previous_month_text]}</th>)
|
127
|
+
colspan = 3
|
128
|
+
else
|
129
|
+
colspan = 7
|
130
|
+
end
|
131
|
+
cal << %(<th colspan="#{colspan}" class="ec-month-name">#{options[:month_name_text]}</th>)
|
132
|
+
if options[:next_month_text]
|
133
|
+
cal << %(<th colspan="2" class="ec-month-nav ec-next-month">#{options[:next_month_text]}</th>)
|
134
|
+
end
|
135
|
+
cal << %(</tr></thead></table>)
|
129
136
|
end
|
130
|
-
|
131
|
-
|
137
|
+
|
132
138
|
# body container (holds day names and the calendar rows)
|
133
139
|
cal << %(<div class="ec-body" style="height: #{height}px;">)
|
134
|
-
|
135
|
-
# day names
|
140
|
+
|
141
|
+
# day names
|
136
142
|
cal << %(<table class="ec-day-names" style="height: #{options[:day_names_height]}px;" cellpadding="0" cellspacing="0">)
|
137
143
|
cal << %(<tbody><tr>)
|
138
144
|
day_names.each do |day_name|
|
139
145
|
cal << %(<th class="ec-day-name" title="#{day_name}">#{day_name}</th>)
|
140
146
|
end
|
141
147
|
cal << %(</tr></tbody></table>)
|
142
|
-
|
148
|
+
|
143
149
|
# container for all the calendar rows
|
144
150
|
cal << %(<div class="ec-rows" style="top: #{options[:day_names_height]}px; )
|
145
151
|
cal << %(height: #{height - options[:day_names_height]}px;">)
|
146
|
-
|
152
|
+
|
147
153
|
# initialize loop variables
|
148
154
|
first_day_of_week = beginning_of_week(first, options[:first_day_of_week])
|
149
155
|
last_day_of_week = end_of_week(first, options[:first_day_of_week])
|
150
156
|
last_day_of_cal = end_of_week(last, options[:first_day_of_week])
|
151
157
|
row_num = 0
|
152
158
|
top = 0
|
153
|
-
|
159
|
+
|
154
160
|
# go through a week at a time, until we reach the end of the month
|
155
161
|
while(last_day_of_week <= last_day_of_cal)
|
156
162
|
cal << %(<div class="ec-row" style="top: #{top}px; height: #{row_heights[row_num]}px;">)
|
157
163
|
top += row_heights[row_num]
|
158
|
-
|
164
|
+
|
159
165
|
# this weeks background table
|
160
166
|
cal << %(<table class="ec-row-bg" cellpadding="0" cellspacing="0">)
|
161
167
|
cal << %(<tbody><tr>)
|
162
168
|
first_day_of_week.upto(first_day_of_week+6) do |day|
|
163
169
|
today_class = (day == Date.today) ? "ec-today-bg" : ""
|
164
|
-
|
170
|
+
other_month_class = (day < first) || (day > last) ? 'ec-other-month-bg' : ''
|
171
|
+
cal << %(<td class="ec-day-bg #{today_class} #{other_month_class}"> </td>)
|
165
172
|
end
|
166
173
|
cal << %(</tr></tbody></table>)
|
167
|
-
|
174
|
+
|
168
175
|
# calendar row
|
169
176
|
cal << %(<table class="ec-row-table" cellpadding="0" cellspacing="0">)
|
170
177
|
cal << %(<tbody>)
|
171
|
-
|
178
|
+
|
172
179
|
# day numbers row
|
173
180
|
cal << %(<tr>)
|
174
181
|
first_day_of_week.upto(last_day_of_week) do |day|
|
@@ -185,7 +192,7 @@ module EventCalendar
|
|
185
192
|
cal << %(</td>)
|
186
193
|
end
|
187
194
|
cal << %(</tr>)
|
188
|
-
|
195
|
+
|
189
196
|
# event rows for this day
|
190
197
|
# for each event strip, create a new table row
|
191
198
|
options[:event_strips].each do |strip|
|
@@ -193,7 +200,7 @@ module EventCalendar
|
|
193
200
|
# go through through the strip, for the entries that correspond to the days of this week
|
194
201
|
strip[row_num*7, 7].each_with_index do |event, index|
|
195
202
|
day = first_day_of_week + index
|
196
|
-
|
203
|
+
|
197
204
|
if event
|
198
205
|
# get the dates of this event that fit into this week
|
199
206
|
dates = event.clip_range(first_day_of_week, last_day_of_week)
|
@@ -202,10 +209,11 @@ module EventCalendar
|
|
202
209
|
if dates[0] == day.to_date
|
203
210
|
# check if we should display the bg color or not
|
204
211
|
no_bg = no_event_bg?(event, options)
|
205
|
-
|
212
|
+
class_name = event.class.name.tableize.singularize
|
213
|
+
|
206
214
|
cal << %(<td class="ec-event-cell" colspan="#{(dates[1]-dates[0]).to_i + 1}" )
|
207
215
|
cal << %(style="padding-top: #{options[:event_margin]}px;">)
|
208
|
-
cal << %(<div class="ec-event ec
|
216
|
+
cal << %(<div class="ec-event ec-#{class_name}-#{event.id} )
|
209
217
|
if no_bg
|
210
218
|
cal << %(ec-event-no-bg" )
|
211
219
|
cal << %(style="color: #{event.color}; )
|
@@ -213,14 +221,15 @@ module EventCalendar
|
|
213
221
|
cal << %(ec-event-bg" )
|
214
222
|
cal << %(style="background-color: #{event.color}; )
|
215
223
|
end
|
224
|
+
|
216
225
|
cal << %(padding-top: #{options[:event_padding_top]}px; )
|
217
226
|
cal << %(height: #{options[:event_height] - options[:event_padding_top]}px;" )
|
218
227
|
if options[:use_javascript]
|
219
228
|
# custom attributes needed for javascript event highlighting
|
220
|
-
cal << %(data-event-id="#{event.id}" data-color="#{event.color}" )
|
229
|
+
cal << %(data-event-id="#{event.id}" data-event-class="#{class_name}" data-color="#{event.color}" )
|
221
230
|
end
|
222
231
|
cal << %(>)
|
223
|
-
|
232
|
+
|
224
233
|
# add a left arrow if event is clipped at the beginning
|
225
234
|
if event.start_at.to_date < dates[0]
|
226
235
|
cal << %(<div class="ec-left-arrow"></div>)
|
@@ -229,25 +238,25 @@ module EventCalendar
|
|
229
238
|
if event.end_at.to_date > dates[1]
|
230
239
|
cal << %(<div class="ec-right-arrow"></div>)
|
231
240
|
end
|
232
|
-
|
241
|
+
|
233
242
|
if no_bg
|
234
243
|
cal << %(<div class="ec-bullet" style="background-color: #{event.color};"></div>)
|
235
244
|
# make sure anchor text is the event color
|
236
245
|
# here b/c CSS 'inherit' color doesn't work in all browsers
|
237
|
-
cal << %(<style type="text/css">.ec
|
246
|
+
cal << %(<style type="text/css">.ec-#{class_name}-#{event.id} a { color: #{event.color}; }</style>)
|
238
247
|
end
|
239
|
-
|
248
|
+
|
240
249
|
if block_given?
|
241
250
|
# add the additional html that was passed as a block to this helper
|
242
251
|
cal << block.call({:event => event, :day => day.to_date, :options => options})
|
243
252
|
else
|
244
253
|
# default content in case nothing is passed in
|
245
|
-
cal << %(<a href="
|
254
|
+
cal << %(<a href="/#{class_name.pluralize}/#{event.id}" title="#{h(event.name)}">#{h(event.name)}</a>)
|
246
255
|
end
|
247
|
-
|
256
|
+
|
248
257
|
cal << %(</div></td>)
|
249
258
|
end
|
250
|
-
|
259
|
+
|
251
260
|
else
|
252
261
|
# there wasn't an event, so create an empty cell and container
|
253
262
|
cal << %(<td class="ec-event-cell ec-no-event-cell" )
|
@@ -261,39 +270,40 @@ module EventCalendar
|
|
261
270
|
end
|
262
271
|
cal << %(</tr>)
|
263
272
|
end
|
264
|
-
|
273
|
+
|
265
274
|
cal << %(</tbody></table>)
|
266
275
|
cal << %(</div>)
|
267
|
-
|
276
|
+
|
268
277
|
# increment the calendar row we are on, and the week
|
269
278
|
row_num += 1
|
270
279
|
first_day_of_week += 7
|
271
280
|
last_day_of_week += 7
|
272
|
-
end
|
273
|
-
|
274
|
-
cal << %(</div>)
|
281
|
+
end
|
282
|
+
|
283
|
+
cal << %(</div>)
|
275
284
|
cal << %(</div>)
|
276
285
|
cal << %(</div>)
|
277
286
|
end
|
278
|
-
|
287
|
+
|
279
288
|
# override this in your own helper for greater control
|
280
289
|
def day_link(text, date, day_action)
|
281
290
|
link_to(text, params.merge(:action => day_action, :year => date.year, :month => date.month, :day => date.day), :class => 'ec-day-link')
|
282
291
|
end
|
283
|
-
|
292
|
+
|
284
293
|
# check if we should display without a background color
|
285
294
|
def no_event_bg?(event, options)
|
286
295
|
options[:use_all_day] && !event.all_day && event.days == 0
|
287
296
|
end
|
288
|
-
|
297
|
+
|
289
298
|
# default html for displaying an event's time
|
290
299
|
# to customize: override, or do something similar, in your helper
|
300
|
+
# for instance, you may want to add localization
|
291
301
|
def display_event_time(event, day)
|
292
302
|
time = event.start_at
|
293
303
|
if !event.all_day and time.to_date == day
|
294
304
|
# try to make it display as short as possible
|
295
|
-
|
296
|
-
t = time.strftime(
|
305
|
+
format = (time.min == 0) ? "%l" : "%l:%M"
|
306
|
+
t = time.strftime(format)
|
297
307
|
am_pm = time.strftime("%p") == "PM" ? "p" : ""
|
298
308
|
t += am_pm
|
299
309
|
%(<span class="ec-event-time">#{t}</span>)
|
@@ -301,9 +311,9 @@ module EventCalendar
|
|
301
311
|
""
|
302
312
|
end
|
303
313
|
end
|
304
|
-
|
314
|
+
|
305
315
|
private
|
306
|
-
|
316
|
+
|
307
317
|
# calculate the height of each row
|
308
318
|
# by default, it will be the height option minus the day names height,
|
309
319
|
# divided by the total number of calendar rows
|
@@ -336,11 +346,11 @@ module EventCalendar
|
|
336
346
|
end
|
337
347
|
row_heights
|
338
348
|
end
|
339
|
-
|
349
|
+
|
340
350
|
#
|
341
351
|
# helper methods for working with a calendar week
|
342
352
|
#
|
343
|
-
|
353
|
+
|
344
354
|
def days_between(first, second)
|
345
355
|
if first > second
|
346
356
|
second + (7 - first)
|
@@ -348,17 +358,17 @@ module EventCalendar
|
|
348
358
|
second - first
|
349
359
|
end
|
350
360
|
end
|
351
|
-
|
361
|
+
|
352
362
|
def beginning_of_week(date, start = 0)
|
353
363
|
days_to_beg = days_between(start, date.wday)
|
354
364
|
date - days_to_beg
|
355
365
|
end
|
356
|
-
|
366
|
+
|
357
367
|
def end_of_week(date, start = 0)
|
358
368
|
beg = beginning_of_week(date, start)
|
359
369
|
beg + 6
|
360
370
|
end
|
361
|
-
|
371
|
+
|
362
372
|
def weekend?(date)
|
363
373
|
[0, 6].include?(date.wday)
|
364
374
|
end
|
@@ -9,14 +9,16 @@ Event.observe(window, "load", function() {
|
|
9
9
|
$$(".ec-event-bg").each(function(ele) {
|
10
10
|
ele.observe("mouseover", function(evt) {
|
11
11
|
event_id = ele.readAttribute("data-event-id");
|
12
|
-
|
12
|
+
event_class_name = ele.readAttribute("data-event-class");
|
13
|
+
$$(".ec-"+event_class_name+"-"+event_id).each(function(el) {
|
13
14
|
el.setStyle({ backgroundColor: highlight_color });
|
14
15
|
});
|
15
16
|
});
|
16
17
|
ele.observe("mouseout", function(evt) {
|
17
|
-
event_color = ele.readAttribute("data-color");
|
18
18
|
event_id = ele.readAttribute("data-event-id");
|
19
|
-
|
19
|
+
event_class_name = ele.readAttribute("data-event-class");
|
20
|
+
event_color = ele.readAttribute("data-color");
|
21
|
+
$$(".ec-"+event_class_name+"-"+event_id).each(function(el) {
|
20
22
|
el.setStyle({ backgroundColor: event_color });
|
21
23
|
});
|
22
24
|
});
|
@@ -2,18 +2,20 @@
|
|
2
2
|
* Smart event highlighting
|
3
3
|
* Handles when events span rows, or don't have a background color
|
4
4
|
*/
|
5
|
-
|
5
|
+
jQuery(document).ready(function($) {
|
6
6
|
var highlight_color = "#2EAC6A";
|
7
7
|
|
8
8
|
// highlight events that have a background color
|
9
9
|
$(".ec-event-bg").live("mouseover", function() {
|
10
10
|
event_id = $(this).attr("data-event-id");
|
11
|
-
|
11
|
+
event_class_name = $(this).attr("data-event-class");
|
12
|
+
$(".ec-"+event_class_name+"-"+event_id).css("background-color", highlight_color);
|
12
13
|
});
|
13
14
|
$(".ec-event-bg").live("mouseout", function() {
|
14
15
|
event_id = $(this).attr("data-event-id");
|
16
|
+
event_class_name = $(this).attr("data-event-class");
|
15
17
|
event_color = $(this).attr("data-color");
|
16
|
-
$(".ec-
|
18
|
+
$(".ec-"+event_class_name+"-"+event_id).css("background-color", event_color);
|
17
19
|
});
|
18
20
|
|
19
21
|
// highlight events that don't have a background color
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event-calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 2.3.
|
9
|
+
- 3
|
10
|
+
version: 2.3.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeff Schuil
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-03-03 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|