3
Read [[%ATTACHURL%/doc/html/reference.html][the Mishoo documentation]] or
4
[[%ATTACHURL%][visit the demo page]] for detailed information on using the
7
This package also includes a small Perl module to make using the calendar
8
easier from Foswiki plugins. This module includes the functions:
12
package Foswiki::Contrib::JSCalendarContrib;
16
require Foswiki::Func; # The plugins API
18
use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION );
20
$VERSION = '$Rev: 3417 (2009-04-12) $';
21
$RELEASE = '03 Aug 2008';
22
$SHORTDESCRIPTION = "[[http://dynarch.com/mishoo/calendar.epl][Mishoo JSCalendar]], packaged for use by plugins, skins and add-ons";
24
# Max width of different mishoo format components
26
a => 3, # abbreviated weekday name
27
A => 9, # full weekday name
28
b => 3, # abbreviated month name
29
B => 9, # full month name
30
C => 2, # century number
31
d => 2, # the day of the month ( 00 .. 31 )
32
e => 2, # the day of the month ( 0 .. 31 )
33
H => 2, # hour ( 00 .. 23 )
34
I => 2, # hour ( 01 .. 12 )
35
j => 3, # day of the year ( 000 .. 366 )
36
k => 2, # hour ( 0 .. 23 )
37
l => 2, # hour ( 1 .. 12 )
38
m => 2, # month ( 01 .. 12 )
39
M => 2, # minute ( 00 .. 59 )
40
n => 1, # a newline character
41
p => 2, # 'PM' or 'AM'
42
P => 2, # 'pm' or 'am'
43
S => 2, # second ( 00 .. 59 )
44
s => 12,# number of seconds since Epoch
45
t => 1, # a tab character
46
U => 2, # the week number
47
u => 1, # the day of the week ( 1 .. 7, 1 = MON )
48
W => 2, # the week number
49
w => 1, # the day of the week ( 0 .. 6, 0 = SUN )
50
V => 2, # the week number
51
y => 2, # year without the century ( 00 .. 99 )
52
Y => 4, # year including the century ( ex. 1979 )
57
---+++ Foswiki::Contrib::JSCalendarContrib::renderDateForEdit($name, $value, $format [, \%cssClass]) -> $html
59
This is the simplest way to use calendars from a plugin.
60
* =$name= is the name of the CGI parameter for the calendar
61
(it should be unique),
62
* =$value= is the current value of the parameter (may be undef)
63
* =$format= is the format to use (optional; the default is set
64
in =configure=). The HTML returned will display a date field
65
and a drop-down calendar.
66
* =\%options= is an optional hash containing base options for
70
use Foswiki::Contrib::JSCalendarContrib;
72
my $fromDate = Foswiki::Contrib::JSCalendarContrib::renderDateForEdit(
73
'from', '1 April 1999');
74
my $toDate = Foswiki::Contrib::JSCalendarContrib::renderDateForEdit(
80
sub renderDateForEdit {
81
my ($name, $value, $format, $options) = @_;
83
$format ||= $Foswiki::cfg{JSCalendarContrib}{format} || '%e %B %Y';
87
# Work out how wide it has to be from the format
88
# SMELL: add a space because pattern skin default fonts on FF make the
89
# box half a character too narrow if the exact size is used
90
my $wide = $format.' ';
91
$wide =~ s/(%(.))/$w{$2} ? ('_' x $w{$2}) : $1/ge;
93
$options->{name} = $name;
94
$options->{id} = 'id_'.$name;
95
$options->{value} = $value || '';
96
$options->{size} ||= length($wide);
98
return CGI::textfield($options)
100
-name => 'img_'.$name,
102
"javascript: return showCalendar('id_$name','$format')",
103
-src=> Foswiki::Func::getPubUrlPath() . '/' .
104
$Foswiki::cfg{SystemWebName} .
105
'/JSCalendarContrib/img.gif',
112
---+++ Foswiki::Contrib::JSCalendarContrib::addHEAD($setup)
114
This function will automatically add the headers for the calendar to the page
115
being rendered. It's intended for use when you want more control over the
116
formatting of your calendars than =renderDateForEdit= affords. =$setup= is
118
the calendar setup module; it can either be omitted, in which case the method
119
described in the Mishoo documentation can be used to create calendars, or it
120
can be ='foswiki'=, in which case a Javascript helper function called
121
'showCalendar' is added that simplifies using calendars to set a value in a
122
text field. For example, say we wanted to display the date with the calendar
123
icon _before_ the text field, using the format =%Y %b %e=
125
# Add styles and javascript for the calendar
126
use Foswiki::Contrib::JSCalendarContrib;
129
sub commonTagsHandler {
131
# Enable 'showCalendar'
132
Foswiki::Contrib::JSCalendarContrib::addHEAD( 'foswiki' );
134
my $cal = CGI::image_button(
135
-name => 'img_datefield',
137
"return showCalendar('id_datefield','%Y %b %e')",
138
-src=> Foswiki::Func::getPubUrlPath() . '/' .
139
$Foswiki::cfg{SystemWebName} .
140
'/JSCalendarContrib/img.gif',
144
{ name => 'date', id => "id_datefield" });
148
The first parameter to =showCalendar= is the id of the textfield, and the second parameter is the date format. Default format is '%e %B %Y'.
150
All available date specifiers:
152
%a - abbreviated weekday name
153
%A - full weekday name
154
%b - abbreviated month name
157
%d - the day of the month ( 00 .. 31 )
158
%e - the day of the month ( 0 .. 31 )
159
%H - hour ( 00 .. 23 )
160
%I - hour ( 01 .. 12 )
161
%j - day of the year ( 000 .. 366 )
162
%k - hour ( 0 .. 23 )
163
%l - hour ( 1 .. 12 )
164
%m - month ( 01 .. 12 )
165
%M - minute ( 00 .. 59 )
166
%n - a newline character
169
%S - second ( 00 .. 59 )
170
%s - number of seconds since Epoch (since Jan 01 1970 00:00:00 UTC)
172
%U, %W, %V - the week number
173
The week 01 is the week that has the Thursday in the current year,
174
which is equivalent to the week that contains the fourth day of January.
175
Weeks start on Monday.
176
%u - the day of the week ( 1 .. 7, 1 = MON )
177
%w - the day of the week ( 0 .. 6, 0 = SUN )
178
%y - year without the century ( 00 .. 99 )
179
%Y - year including the century ( ex. 1979 )
180
%% - a literal % character
183
=addHEAD= can be called from =commonTagsHandler= for adding the header to all pages, or from =beforeEditHandler= just for edit pages etc.
185
An alternative to =commonTagsHandler= is =postRenderingHandler= which is more efficient since it is called less often.
191
$setup ||= 'calendar-setup';
192
my $style = $Foswiki::cfg{JSCalendarContrib}{style} || 'blue';
193
my $lang = $Foswiki::cfg{JSCalendarContrib}{lang} || 'en';
194
my $base = '%PUBURLPATH%/%SYSTEMWEB%/JSCalendarContrib';
196
require Foswiki::Contrib::BehaviourContrib;
197
if (defined(&Foswiki::Contrib::BehaviourContrib::addHEAD)) {
198
Foswiki::Contrib::BehaviourContrib::addHEAD();
200
Foswiki::Func::addToHEAD(
202
'<script type="text/javascript" src="%PUBURLPATH%/%SYSTEMWEB%/BehaviourContrib/behaviour.compressed.js"></script>');
206
<style type='text/css' media='all'>
207
\@import url('$base/calendar-$style.css');
208
.calendar {z-index:2000;}
210
<script type='text/javascript' src='$base/calendar.js'></script>
211
<script type='text/javascript' src='$base/lang/calendar-$lang.js'></script>
213
Foswiki::Func::addToHEAD( 'JSCALENDARCONTRIB', $head );
215
# Add the setup separately; there might be different setups required
216
# in a single HTML page.
218
<script type='text/javascript' src='$base/$setup.js'></script>
220
Foswiki::Func::addToHEAD( 'JSCALENDARCONTRIB_'.$setup, $head );