← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 19:05:14 2015
Reported on Fri Jul 31 19:08:10 2015

Filename/var/www/foswiki11/lib/Foswiki/Contrib/JSCalendarContrib.pm
StatementsExecuted 23 statements in 640µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11159µs265µsFoswiki::Contrib::JSCalendarContrib::::addHEADFoswiki::Contrib::JSCalendarContrib::addHEAD
11114µs27µsFoswiki::Contrib::JSCalendarContrib::::BEGIN@16Foswiki::Contrib::JSCalendarContrib::BEGIN@16
11111µs16µsFoswiki::Contrib::JSCalendarContrib::::BEGIN@17Foswiki::Contrib::JSCalendarContrib::BEGIN@17
1119µs27µsFoswiki::Contrib::JSCalendarContrib::::BEGIN@21Foswiki::Contrib::JSCalendarContrib::BEGIN@21
1113µs3µsFoswiki::Contrib::JSCalendarContrib::::BEGIN@19Foswiki::Contrib::JSCalendarContrib::BEGIN@19
0000s0sFoswiki::Contrib::JSCalendarContrib::::renderDateForEditFoswiki::Contrib::JSCalendarContrib::renderDateForEdit
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# See bottom of file for license and copyright information
2
3=begin TML
4
5Read [[%ATTACHURL%/doc/html/reference.html][the Mishoo documentation]] or
6[[%ATTACHURL%][visit the demo page]] for detailed information on using the
7calendar widget.
8
9This package also includes a small Perl module to make using the calendar
10easier from Foswiki plugins. This module includes the functions:
11
12=cut
13
14package Foswiki::Contrib::JSCalendarContrib;
15
16229µs239µs
# spent 27µs (14+12) within Foswiki::Contrib::JSCalendarContrib::BEGIN@16 which was called: # once (14µs+12µs) by Foswiki::Plugins::ActionTrackerPlugin::BEGIN@33 at line 16
use strict;
# spent 27µs making 1 call to Foswiki::Contrib::JSCalendarContrib::BEGIN@16 # spent 12µs making 1 call to strict::import
17224µs221µs
# spent 16µs (11+5) within Foswiki::Contrib::JSCalendarContrib::BEGIN@17 which was called: # once (11µs+5µs) by Foswiki::Plugins::ActionTrackerPlugin::BEGIN@33 at line 17
use warnings;
# spent 16µs making 1 call to Foswiki::Contrib::JSCalendarContrib::BEGIN@17 # spent 5µs making 1 call to warnings::import
18
19220µs13µs
# spent 3µs within Foswiki::Contrib::JSCalendarContrib::BEGIN@19 which was called: # once (3µs+0s) by Foswiki::Plugins::ActionTrackerPlugin::BEGIN@33 at line 19
use Foswiki::Func (); # The plugins API
# spent 3µs making 1 call to Foswiki::Contrib::JSCalendarContrib::BEGIN@19
20
213505µs351µs
# spent 27µs (9+19) within Foswiki::Contrib::JSCalendarContrib::BEGIN@21 which was called: # once (9µs+19µs) by Foswiki::Plugins::ActionTrackerPlugin::BEGIN@33 at line 21
use version; our $VERSION = version->declare("v1.5.4");
# spent 27µs making 1 call to Foswiki::Contrib::JSCalendarContrib::BEGIN@21 # spent 19µs making 1 call to version::import # spent 5µs making 1 call to version::vxs::declare
221400nsour $RELEASE = '1.5.4';
231300nsour $SHORTDESCRIPTION =
24"[[http://dynarch.com/mishoo/calendar.epl][Mishoo JSCalendar]] date and time picker, packaged for use by plugins, skins and add-ons";
25
26# Max width of different mishoo format components
27114µsmy %w = (
28 'a' => 3, # abbreviated weekday name
29 'A' => 9, # full weekday name
30 'b' => 3, # abbreviated month name
31 'B' => 9, # full month name
32 'C' => 2, # century number
33 'd' => 2, # the day of the month ( 00 .. 31 )
34 'e' => 2, # the day of the month ( 0 .. 31 )
35 'H' => 2, # hour ( 00 .. 23 )
36 'I' => 2, # hour ( 01 .. 12 )
37 'j' => 3, # day of the year ( 000 .. 366 )
38 'k' => 2, # hour ( 0 .. 23 )
39 'l' => 2, # hour ( 1 .. 12 )
40 'm' => 2, # month ( 01 .. 12 )
41 'M' => 2, # minute ( 00 .. 59 )
42 'n' => 1, # a newline character
43 'p' => 2, # 'PM' or 'AM'
44 'P' => 2, # 'pm' or 'am'
45 'S' => 2, # second ( 00 .. 59 )
46 's' => 12, # number of seconds since Epoch
47 't' => 1, # a tab character
48 'U' => 2, # the week number
49 'u' => 1, # the day of the week ( 1 .. 7, 1 = MON )
50 'W' => 2, # the week number
51 'w' => 1, # the day of the week ( 0 .. 6, 0 = SUN )
52 'V' => 2, # the week number
53 'y' => 2, # year without the century ( 00 .. 99 )
54 'Y' => 4, # year including the century ( ex. 1979 )
55);
56
57=begin TML
58
59---+++ Foswiki::Contrib::JSCalendarContrib::renderDateForEdit($name, $value, $format [, \%cssClass]) -> $html
60
61This is the simplest way to use calendars from a plugin.
62 * =$name= is the name of the CGI parameter for the calendar
63 (it should be unique),
64 * =$value= is the current value of the parameter (may be undef)
65 * =$format= is the format to use (optional; the default is set
66 in =configure=). The HTML returned will display a date field
67 and a drop-down calendar.
68 * =\%options= is an optional hash containing base options for
69 the textfield.
70Example:
71<verbatim>
72use Foswiki::Contrib::JSCalendarContrib ();
73...
74my $fromDate = Foswiki::Contrib::JSCalendarContrib::renderDateForEdit(
75 'from', '1 April 1999');
76my $toDate = Foswiki::Contrib::JSCalendarContrib::renderDateForEdit(
77 'to', undef, '%Y');
78</verbatim>
79
80=cut
81
82sub renderDateForEdit {
83 my ( $name, $value, $format, $options ) = @_;
84
85 $format ||=
86 Foswiki::Func::getPreferencesValue('JSCALENDARCONTRIB_FORMAT')
87 || $Foswiki::cfg{JSCalendarContrib}{format}
88 || '%e %b %Y';
89
90 addHEAD('foswiki');
91
92 # Work out how wide it has to be from the format
93 # SMELL: add a space because pattern skin default fonts on FF make the
94 # box half a character too narrow if the exact size is used
95 my $wide = $format . ' ';
96 $wide =~ s/(%(.))/$w{$2} ? ('_' x $w{$2}) : $1/ge;
97 $options ||= {};
98 $options->{name} = $name;
99 $options->{id} = 'id_' . $name;
100 $options->{value} = $value || '';
101 $options->{size} ||= length($wide);
102
103 return CGI::textfield($options)
104 . CGI::image_button(
105 -name => 'img_' . $name,
106 -onclick => "javascript: return showCalendar('id_$name','$format')",
107 -src => Foswiki::Func::getPubUrlPath() . '/'
108 . $Foswiki::cfg{SystemWebName}
109 . '/JSCalendarContrib/img.gif',
110 -alt => 'Calendar',
111 -align => 'middle'
112 );
113}
114
115=begin TML
116
117---+++ Foswiki::Contrib::JSCalendarContrib::addHEAD($setup)
118
119This function will automatically add the headers for the calendar to the page
120being rendered. It's intended for use when you want more control over the
121formatting of your calendars than =renderDateForEdit= affords. =$setup= is
122the name of
123the calendar setup module; it can either be omitted, in which case the method
124described in the Mishoo documentation can be used to create calendars, or it
125can be ='foswiki'=, in which case a Javascript helper function called
126'showCalendar' is added that simplifies using calendars to set a value in a
127text field. For example, say we wanted to display the date with the calendar
128icon _before_ the text field, using the format =%Y %b %e=
129<verbatim>
130# Add styles and javascript for the calendar
131use Foswiki::Contrib::JSCalendarContrib ();
132...
133
134sub commonTagsHandler {
135 ....
136 # Enable 'showCalendar'
137 Foswiki::Contrib::JSCalendarContrib::addHEAD( 'foswiki' );
138
139 my $cal = CGI::image_button(
140 -name => 'img_datefield',
141 -onclick =>
142 "return showCalendar('id_datefield','%Y %b %e')",
143 -src=> Foswiki::Func::getPubUrlPath() . '/' .
144 $Foswiki::cfg{SystemWebName} .
145 '/JSCalendarContrib/img.gif',
146 -alt => 'Calendar',
147 -align => 'middle' )
148 . CGI::textfield(
149 { name => 'date', id => "id_datefield" });
150 ....
151}
152</verbatim>
153The first parameter to =showCalendar= is the id of the textfield, and the second parameter is the date format. Default format is '%e %B %Y'.
154
155#FormatSpecifiers
156All available date specifiers:
157<verbatim>
158%a - abbreviated weekday name
159%A - full weekday name
160%b - abbreviated month name
161%B - full month name
162%C - century number
163%d - the day of the month ( 00 .. 31 )
164%e - the day of the month ( 0 .. 31 )
165%H - hour ( 00 .. 23 )
166%I - hour ( 01 .. 12 )
167%j - day of the year ( 000 .. 366 )
168%k - hour ( 0 .. 23 )
169%l - hour ( 1 .. 12 )
170%m - month ( 01 .. 12 )
171%M - minute ( 00 .. 59 )
172%n - a newline character
173%p - "PM" or "AM"
174%P - "pm" or "am"
175%S - second ( 00 .. 59 )
176%s - number of seconds since Epoch (since Jan 01 1970 00:00:00 UTC)
177%t - a tab character
178%U, %W, %V - the week number
179 The week 01 is the week that has the Thursday in the current year,
180 which is equivalent to the week that contains the fourth day of January.
181 Weeks start on Monday.
182%u - the day of the week ( 1 .. 7, 1 = MON )
183%w - the day of the week ( 0 .. 6, 0 = SUN )
184%y - year without the century ( 00 .. 99 )
185%Y - year including the century ( ex. 1979 )
186%% - a literal % character
187</verbatim>
188
189=addHEAD= can be called from =commonTagsHandler= for adding the header to all pages, or from =beforeEditHandler= just for edit pages etc.
190
191An alternative to =commonTagsHandler= is =postRenderingHandler= which is more efficient since it is called less often.
192
193=cut
194
195
# spent 265µs (59+207) within Foswiki::Contrib::JSCalendarContrib::addHEAD which was called: # once (59µs+207µs) by Foswiki::Plugins::ActionTrackerPlugin::initPlugin at line 38 of /var/www/foswiki11/lib/Foswiki/Plugins/ActionTrackerPlugin.pm
sub addHEAD {
19611µs my $setup = shift;
1971500ns $setup ||= 'calendar-setup';
19815µs145µs my $style =
# spent 45µs making 1 call to Foswiki::Func::getPreferencesValue
199 Foswiki::Func::getPreferencesValue('JSCALENDARCONTRIB_STYLE')
200 || $Foswiki::cfg{JSCalendarContrib}{style}
201 || 'large';
20213µs135µs my $lang =
# spent 35µs making 1 call to Foswiki::Func::getPreferencesValue
203 Foswiki::Func::getPreferencesValue('JSCALENDARCONTRIB_LANG')
204 || $Foswiki::cfg{JSCalendarContrib}{lang}
205 || 'en';
2061900ns my $base = '%PUBURLPATH%/%SYSTEMWEB%/JSCalendarContrib';
207
20814µs my $css = <<HERE;
209<style type='text/css' media='all'>
210 \@import url('$base/calendar-$style.css');
211 .calendar {z-index:2000;}
212</style>
213HERE
21417µs152µs Foswiki::Func::addToZone( 'head', 'JSCalendarContrib/css', $css );
# spent 52µs making 1 call to Foswiki::Func::addToZone
215
21613µs123µs Foswiki::Func::addToZone( 'script', 'JSCalendarContrib/calendar',
# spent 23µs making 1 call to Foswiki::Func::addToZone
217 "<script type='text/javascript' src='$base/calendar.js'></script>" );
218
21916µs128µs Foswiki::Func::addToZone(
# spent 28µs making 1 call to Foswiki::Func::addToZone
220 'script',
221 'JSCalendarContrib/calendar-lang',
222"<script type='text/javascript' src='$base/lang/calendar-$lang.js'></script>",
223 'JSCalendarContrib/calendar'
224 );
225
226 # Add the setup separately; there might be different setups required
227 # in a single HTML page.
228111µs124µs Foswiki::Func::addToZone( 'script', "JSCalendarContrib/$setup",
# spent 24µs making 1 call to Foswiki::Func::addToZone
229 "<script type='text/javascript' src='$base/$setup.js'></script>",
230 'JSCalendarContrib/calendar' );
231}
232
23318µs1;
234__END__