.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "HTML::Prototype 3pm"
.TH HTML::Prototype 3pm "2022-06-14" "perl v5.34.0" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
HTML::Prototype \- Generate HTML and Javascript for the Prototype library
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use HTML::Prototype;
\&
\& my $prototype = HTML::Prototype\->new;
\& print $prototype\->auto_complete_field(...);
\& print $prototype\->auto_complete_result(...);
\& print $prototype\->auto_complete_stylesheet(...);
\& print $prototype\->content_tag(...);
\& print $prototype\->define_javascript_functions;
\& print $prototype\->draggable_element(...);
\& print $prototype\->drop_receiving_element(...);
\& print $prototype\->evaluate_remote_response(...);
\& print $prototype\->form_remote_tag(...);
\& print $prototype\->in_place_editor(...);
\& print $prototype\->in_place_editor_field(...);
\& print $prototype\->in_place_editor_stylesheet(...);
\& print $prototype\->javascript_tag(...);
\& print $prototype\->link_to_function(...);
\& print $prototype\->link_to_remote(...);
\& print $prototype\->observe_field(...);
\& print $prototype\->observe_form(...);
\& print $prototype\->periodically_call_remote(...);
\& print $prototype\->sortable_element(...);
\& print $prototype\->submit_to_remote(...);
\& print $prototype\->tag(...);
\& print $prototype\->text_field_with_auto_complete(...);
\& print $prototype\->update_element_function(...);
\& print $prototype\->visual_effect(...);
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
The module contains some code generators for Prototype, the famous JavaScript
\&\s-1OO\s0 library and the script.aculous extensions.
.PP
The Prototype library (http://prototype.conio.net/) is designed to make
\&\s-1AJAX\s0 easy. Catalyst::Plugin::Prototype makes it easy to connect to the
Prototype library.
.PP
This is mostly a port of the Ruby on Rails helper tags for JavaScript
for use in Catalyst.
.SS "\s-1METHODS\s0"
.IX Subsection "METHODS"
.ie n .IP "$prototype\->in_place_editor( $field_id, \e%options )" 4
.el .IP "\f(CW$prototype\fR\->in_place_editor( \f(CW$field_id\fR, \e%options )" 4
.IX Item "$prototype->in_place_editor( $field_id, %options )"
Makes an \s-1HTML\s0 element specified by the \s-1DOM ID\s0 \f(CW$field_id\fR become an in-place
editor of a property.
.Sp
A form is automatically created and displayed when the user clicks the element,
something like this:
.Sp
.Vb 5
\&
.Ve
.Sp
The form is serialized and sent to the server using an Ajax call, the action
on the server should process the value and return the updated value in the
body of the reponse. The element will automatically be updated with the
changed value (as returned from the server).
.Sp
Required options are:
.Sp
\&\f(CW\*(C`url\*(C'\fR: Specifies the url where the updated value should be sent after the
user presses \*(L"ok\*(R".
.Sp
Addtional options are:
.Sp
\&\f(CW\*(C`rows\*(C'\fR: Number of rows (more than 1 will use a \s-1TEXTAREA\s0)
.Sp
\&\f(CW\*(C`cols\*(C'\fR: The number of columns the text area should span (works for both single line or multi line).
.Sp
\&\f(CW\*(C`size\*(C'\fR: Synonym for XcolsX when using single-line (rows=1) input
.Sp
\&\f(CW\*(C`cancel_text\*(C'\fR: The text on the cancel link. (default: \*(L"cancel\*(R")
.Sp
\&\f(CW\*(C`form_class_name\*(C'\fR: \s-1CSS\s0 class used for the in place edit form. (default: \*(L"inplaceeditor-form\*(R")
.Sp
\&\f(CW\*(C`save_text\*(C'\fR: The text on the save link. (default: \*(L"ok\*(R")
.Sp
\&\f(CW\*(C`saving_class_name\*(C'\fR: \s-1CSS\s0 class added to the element while displaying \*(L"Saving...\*(R"
(removed when server responds). (default: \*(L"inplaceeditor-saving\*(R")
.Sp
\&\f(CW\*(C`load_text_url\*(C'\fR: Will cause the text to be loaded from the server (useful if
your text is actually textile and formatted on the server)
.Sp
\&\f(CW\*(C`loading_text\*(C'\fR: If the \f(CW\*(C`load_text_url\*(C'\fR option is specified then this text is
displayed while the text is being loaded from the server. (default: \*(L"Loading...\*(R")
.Sp
\&\f(CW\*(C`click_to_edit_text\*(C'\fR: The text on the click-to-edit link. (default: \*(L"click to edit\*(R")
.Sp
\&\f(CW\*(C`external_control\*(C'\fR: The id of an external control used to enter edit mode.
.Sp
\&\f(CW\*(C`ajax_options\*(C'\fR: Pass through options to the \s-1AJAX\s0 call (see prototype's Ajax.Updater)
.Sp
\&\f(CW\*(C`with\*(C'\fR: JavaScript snippet that should return what is to be sent in the
Ajax call, \f(CW\*(C`form\*(C'\fR and \f(CW\*(C`value\*(C'\fR are implicit parameters
.ie n .IP "$prototype\->in_place_editor_field( $object, $method, \e%tag_options, \e%in_place_editor_options )" 4
.el .IP "\f(CW$prototype\fR\->in_place_editor_field( \f(CW$object\fR, \f(CW$method\fR, \e%tag_options, \e%in_place_editor_options )" 4
.IX Item "$prototype->in_place_editor_field( $object, $method, %tag_options, %in_place_editor_options )"
Renders the value of the specified object and method with in-place editing capabilities.
.ie n .IP "$prototype\->in_place_editor_stylesheet" 4
.el .IP "\f(CW$prototype\fR\->in_place_editor_stylesheet" 4
.IX Item "$prototype->in_place_editor_stylesheet"
Returns the in_place_editor stylesheet.
.ie n .IP "$prototype\->auto_complete_field( $field_id, \e%options )" 4
.el .IP "\f(CW$prototype\fR\->auto_complete_field( \f(CW$field_id\fR, \e%options )" 4
.IX Item "$prototype->auto_complete_field( $field_id, %options )"
Adds Ajax autocomplete functionality to the text input field with the
\&\s-1DOM ID\s0 specified by \f(CW$field_id\fR.
.Sp
This function expects that the called action returns a \s-1HTML\s0 list,
or nothing if no entries should be displayed for autocompletion.
.Sp
Required options are:
.Sp
\&\f(CW\*(C`url\*(C'\fR: Specifies the \s-1URL\s0 to be used in the \s-1AJAX\s0 call.
.Sp
Addtional options are:
.Sp
\&\f(CW\*(C`update\*(C'\fR: Specifies the \s-1DOM ID\s0 of the element whose innerHTML should
be updated with the autocomplete entries returned by the Ajax request.
Defaults to field_id + '_auto_complete'.
.Sp
\&\f(CW\*(C`with\*(C'\fR: A Javascript expression specifying the parameters for the
XMLHttpRequest.
This defaults to 'value', which in the evaluated context refers to the
new field value.
.Sp
\&\f(CW\*(C`indicator\*(C'\fR: Specifies the \s-1DOM ID\s0 of an elment which will be displayed
Here's an example using Catalyst::View::Mason with an indicator against the auto_complete_result example below on the server side. Notice the 'style=\*(L"display:none\*(R"' in the indicator .
.Sp
.Vb 1
\& <% $c\->prototype\->define_javascript_functions %>
\&
\&
\&
\&
\&
\& <% $c\->prototype\->auto_complete_field( \*(Aqacomp\*(Aq, { url => \*(Aq/autocomplete\*(Aq, indicator => \*(Aqacomp_stat\*(Aq } ) %>
.Ve
.Sp
while autocomplete is running.
.Sp
\&\f(CW\*(C`tokens\*(C'\fR: A string or an array of strings containing separator tokens for
tokenized incremental autocompletion. Example: \f(CW\*(C`> would
allow multiple autocompletion entries, separated by commas.
.Sp
\&\f(CW\*(C`min_chars\*(C'\fR: The minimum number of characters that should be in the input
field before an Ajax call is made to the server.
.Sp
\&\f(CW\*(C`on_hide\*(C'\fR: A Javascript expression that is called when the autocompletion
div is hidden. The expression should take two variables: element and update.
Element is a \s-1DOM\s0 element for the field, update is a \s-1DOM\s0 element for the div
from which the innerHTML is replaced.
.Sp
\&\f(CW\*(C`on_show\*(C'\fR: Like on_hide, only now the expression is called then the div
is shown.
.Sp
\&\f(CW\*(C`select\*(C'\fR: Pick the class of the element from which the value for
insertion should be extracted. If this is not specified,
the entire element is used
.ie n .IP "$prototype\->auto_complete_result(\e@items, $fieldname, [$phrase])" 4
.el .IP "\f(CW$prototype\fR\->auto_complete_result(\e@items, \f(CW$fieldname\fR, [$phrase])" 4
.IX Item "$prototype->auto_complete_result(@items, $fieldname, [$phrase])"
Returns a list, to communcate with the Autocompleter.
.Sp
Here's an example for Catalyst:
.Sp
.Vb 5
\& sub autocomplete : Global {
\& my ( $self, $c ) = @_;
\& my @items = qw/foo bar baz/;
\& $c\->res\->body( $c\->prototype\->auto_complete_result(\e@items) );
\& }
.Ve
.ie n .IP "$prototype\->text_field_with_auto_complete($method, [\e%tag_options], [\e%completion_options])" 4
.el .IP "\f(CW$prototype\fR\->text_field_with_auto_complete($method, [\e%tag_options], [\e%completion_options])" 4
.IX Item "$prototype->text_field_with_auto_complete($method, [%tag_options], [%completion_options])"
Wrapper for text_field with added Ajax autocompletion functionality.
.Sp
In your controller, you'll need to define an action called
auto_complete_for_object_method to respond the \s-1AJAX\s0 calls,
.ie n .IP "$prototype\->auto_complete_stylesheet" 4
.el .IP "\f(CW$prototype\fR\->auto_complete_stylesheet" 4
.IX Item "$prototype->auto_complete_stylesheet"
Returns the auto_complete stylesheet.
.ie n .IP "$prototype\->content_tag( $name, $content, \e%html_options )" 4
.el .IP "\f(CW$prototype\fR\->content_tag( \f(CW$name\fR, \f(CW$content\fR, \e%html_options )" 4
.IX Item "$prototype->content_tag( $name, $content, %html_options )"
Returns a block with opening tag, content, and ending tag. Useful for
autogenerating tags like \fB>. The first parameter is the tag name, i.e. \fB'a'\fR or
\&\fB'img'\fR.
.ie n .IP "$prototype\->text_field( $name, $method, $html_options )" 4
.el .IP "\f(CW$prototype\fR\->text_field( \f(CW$name\fR, \f(CW$method\fR, \f(CW$html_options\fR )" 4
.IX Item "$prototype->text_field( $name, $method, $html_options )"
Returns an input tag of the \*(L"text\*(R" type tailored for accessing a specified
attribute (identified by \fI\f(CI$method\fI\fR) on an object assigned to the template
(identified by \fI\f(CI$object\fI\fR). Additional options on the input tag can be passed
as a hash ref with \fI\f(CI$html_options\fI\fR.
.ie n .IP "$prototype\->define_javascript_functions" 4
.el .IP "\f(CW$prototype\fR\->define_javascript_functions" 4
.IX Item "$prototype->define_javascript_functions"
Returns the library of JavaScript functions and objects, in a script block.
.Sp
Notes for Catalyst users:
.Sp
You can use \f(CW\*(C`script/myapp_create.pl Prototype\*(C'\fR to generate a static JavaScript
file which then can be included via remote \f(CW\*(C`script\*(C'\fR tag.
.ie n .IP "$prototype\->draggable_element( $element_id, \e%options )" 4
.el .IP "\f(CW$prototype\fR\->draggable_element( \f(CW$element_id\fR, \e%options )" 4
.IX Item "$prototype->draggable_element( $element_id, %options )"
Makes the element with the \s-1DOM ID\s0 specified by \f(CW\*(C`element_id\*(C'\fR draggable.
.Sp
Example:
.Sp
.Vb 1
\& $prototype\->draggable_element( \*(Aqmy_image\*(Aq, { revert => \*(Aqtrue\*(Aq } );
.Ve
.Sp
The available options are:
.RS 4
.IP "handle" 4
.IX Item "handle"
Default: none. Sets whether the element should only be draggable by an
embedded handle. The value is a string referencing a \s-1CSS\s0 class. The
first child/grandchild/etc. element found within the element that has
this \s-1CSS\s0 class will be used as the handle.
.IP "revert" 4
.IX Item "revert"
Default: false. If set to true, the element returns to its original
position when the drags ends.
.IP "constraint" 4
.IX Item "constraint"
Default: none. If set to 'horizontal' or 'vertical' the drag will be
constrained to take place only horizontally or vertically.
.IP "change" 4
.IX Item "change"
Javascript callback function called whenever the Draggable is moved by
dragging. It should be a string whose contents is a valid JavaScript
function definition. The called function gets the Draggable instance
as its parameter. It might look something like this:
.Sp
.Vb 1
\& \*(Aqfunction (element) { // do something with dragged element }\*(Aq
.Ve
.RE
.RS 4
.Sp
See http://script.aculo.us for more documentation.
.RE
.ie n .IP "$prototype\->drop_receiving_element( $element_id, \e%options )" 4
.el .IP "\f(CW$prototype\fR\->drop_receiving_element( \f(CW$element_id\fR, \e%options )" 4
.IX Item "$prototype->drop_receiving_element( $element_id, %options )"
Makes the element with the \s-1DOM ID\s0 specified by \f(CW\*(C`element_id\*(C'\fR receive
dropped draggable elements (created by draggable_element).
.Sp
And make an \s-1AJAX\s0 call.
.Sp
By default, the action called gets the \s-1DOM ID\s0 of the element as parameter.
.Sp
Example:
\f(CW$prototype\fR\->drop_receiving_element(
'my_cart', { url => 'http://foo.bar/add' } );
.Sp
Required options are:
.RS 4
.IP "url" 4
.IX Item "url"
The \s-1URL\s0 for the \s-1AJAX\s0 call.
.RE
.RS 4
.Sp
Additional options are:
.IP "accept" 4
.IX Item "accept"
Default: none. Set accept to a string or an array of
strings describing \s-1CSS\s0 classes. The Droppable will only accept
Draggables that have one or more of these \s-1CSS\s0 classes.
.IP "containment" 4
.IX Item "containment"
Default: none. The droppable will only accept the Draggable if the
Draggable is contained in the given elements (or element ids). Can be a
single element or an array of elements. This is option is used by
Sortables to control Drag-and-Drop between Sortables.
.IP "overlap" 4
.IX Item "overlap"
Default: none. If set to 'horizontal' or 'vertical' the droppable will
only react to a Draggable if it overlaps by more than 50% in the given
direction. Used by Sortables.
.Sp
Additionally, the following JavaScript callback functions can be used
in the option parameter:
.IP "onHover" 4
.IX Item "onHover"
Javascript function called whenever a Draggable is moved over the
Droppable and the Droppable is affected (would accept it). The
callback gets three parameters: the Draggable, the Droppable element,
and the percentage of overlapping as defined by the overlap
option. Used by Sortables. The function might look something like
this:
.Sp
.Vb 1
\& \*(Aqfunction (draggable, droppable, pcnt) { // do something }\*(Aq
.Ve
.RE
.RS 4
.Sp
See http://script.aculo.us for more documentation.
.RE
.ie n .IP "$prototype\->evaluate_remote_response" 4
.el .IP "\f(CW$prototype\fR\->evaluate_remote_response" 4
.IX Item "$prototype->evaluate_remote_response"
Returns 'eval(request.responseText)' which is the Javascript function
that form_remote_tag can call in :complete to evaluate a multiple
update return document using update_element_function calls.
.ie n .IP "$prototype\->form_remote_tag(\e%options)" 4
.el .IP "\f(CW$prototype\fR\->form_remote_tag(\e%options)" 4
.IX Item "$prototype->form_remote_tag(%options)"
Returns a form tag that will submit in the background using XMLHttpRequest,
instead of the regular reloading \s-1POST\s0 arrangement.
.Sp
Even though it is using JavaScript to serialize the form elements, the
form submission will work just like a regular submission as viewed by
the receiving side.
.Sp
The options for specifying the target with \f(CW\*(C`url\*(C'\fR and defining callbacks
are the same as \f(CW\*(C`link_to_remote\*(C'\fR.
.ie n .IP "$prototype\->javascript_tag( $content, \e%html_options )" 4
.el .IP "\f(CW$prototype\fR\->javascript_tag( \f(CW$content\fR, \e%html_options )" 4
.IX Item "$prototype->javascript_tag( $content, %html_options )"
Returns a javascript block with opening tag, content and ending tag.
.ie n .IP "$prototype\->link_to_function( $name, $function, \e%html_options )" 4
.el .IP "\f(CW$prototype\fR\->link_to_function( \f(CW$name\fR, \f(CW$function\fR, \e%html_options )" 4
.IX Item "$prototype->link_to_function( $name, $function, %html_options )"
Returns a link that will trigger a JavaScript function using the onClick
handler and return false after the fact.
.Sp
Examples:
.Sp
.Vb 2
\& $prototype\->link_to_function( "Greeting", "alert(\*(AqHello world!\*(Aq) )
\& $prototype\->link_to_function( \*(Aq\*(Aq, \*(Aqdo_delete()\*(Aq, { entities => \*(Aq\*(Aq } )
.Ve
.ie n .IP "$prototype\->link_to_remote( $content, \e%options, \e%html_options )" 4
.el .IP "\f(CW$prototype\fR\->link_to_remote( \f(CW$content\fR, \e%options, \e%html_options )" 4
.IX Item "$prototype->link_to_remote( $content, %options, %html_options )"
Returns a link to a remote action defined by options \f(CW\*(C`url\*(C'\fR that's
called in the background using XMLHttpRequest.
.Sp
The result of that request can then be inserted into a \s-1DOM\s0 object whose
id can be specified with options\->{update}.
.Sp
Examples:
.Sp
.Vb 4
\& $prototype\->link_to_remote( \*(AqDelete\*(Aq, {
\& update => \*(Aqposts\*(Aq,
\& url => \*(Aqhttp://localhost/posts/\*(Aq
\& } )
\&
\& $prototype\->link_to_remote( \*(Aq\*(Aq, {
\& update => \*(Aqemails\*(Aq,
\& url => \*(Aqhttp://localhost/refresh/\*(Aq
\& } )
.Ve
.Sp
By default, these remote requests are processed asynchronously, during
which various callbacks can be triggered (e.g. for progress indicators
and the like).
.Sp
Example:
.Sp
.Vb 4
\& $prototype\->link_to_remote( \*(Aqcount\*(Aq, {
\& url => \*(Aqhttp://localhost/count/\*(Aq,
\& complete => \*(AqdoStuff(request)\*(Aq
\& } )
.Ve
.Sp
The callbacks that may be specified are:
.Sp
\&\f(CW\*(C`loading\*(C'\fR: Called when the remote document is being loaded with data
by the browser.
.Sp
\&\f(CW\*(C`loaded\*(C'\fR: Called when the browser has finished loading the remote document.
.Sp
\&\f(CW\*(C`interactive\*(C'\fR: Called when the user can interact with the remote document,
even though it has not finished loading.
.Sp
\&\f(CW\*(C`complete\*(C'\fR: Called when the XMLHttpRequest is complete.
.Sp
If you do need synchronous processing
(this will block the browser while the request is happening),
you can specify \f(CW$options\fR\->{type} = 'synchronous'.
.Sp
You can customize further browser side call logic by passing
in Javascript code snippets via some optional parameters. In
their order of use these are:
.Sp
\&\f(CW\*(C`confirm\*(C'\fR: Adds confirmation dialog.
.Sp
\&\f(CW\*(C`condition\*(C'\fR: Perform remote request conditionally by this expression.
Use this to describe browser-side conditions when request should not be
initiated.
.Sp
\&\f(CW\*(C`before\*(C'\fR: Called before request is initiated.
.Sp
\&\f(CW\*(C`after\*(C'\fR: Called immediately after request was initiated and before \f(CW\*(C`loading\*(C'\fR.
.ie n .IP "$prototype\->observe_field( $id, \e%options)" 4
.el .IP "\f(CW$prototype\fR\->observe_field( \f(CW$id\fR, \e%options)" 4
.IX Item "$prototype->observe_field( $id, %options)"
Observes the field with the \s-1DOM ID\s0 specified by \f(CW$id\fR and makes an
Ajax when its contents have changed.
.Sp
Required options are:
.Sp
\&\f(CW\*(C`frequency\*(C'\fR: The frequency (in seconds) at which changes to this field
will be detected.
.Sp
\&\f(CW\*(C`url\*(C'\fR: url to be called when field content has changed.
.Sp
Additional options are:
.Sp
\&\f(CW\*(C`update\*(C'\fR: Specifies the \s-1DOM ID\s0 of the element whose innerHTML
should be updated with the XMLHttpRequest response text.
.Sp
\&\f(CW\*(C`with\*(C'\fR: A JavaScript expression specifying the parameters for the
XMLHttpRequest.
This defaults to value, which in the evaluated context refers to the
new field value.
.Sp
Additionally, you may specify any of the options documented in
\&\f(CW\*(C`link_to_remote\*(C'\fR.
.Sp
Example \s-1TT2\s0 template in Catalyst:
.Sp
.Vb 10
\& [% c.prototype.define_javascript_functions %]
\& [% page.title %]
\&
\&
\& [% url = base _ \*(Aqedit/\*(Aq _ page.title %]
\& [% c.prototype.observe_field( \*(Aqeditor\*(Aq, {
\& url => url,
\& with => "\*(Aqbody=\*(Aq+value",
\& update => \*(Aqview\*(Aq
\& } ) %]
.Ve
.ie n .IP "$prototype\->observe_form( $id, \e%options )" 4
.el .IP "\f(CW$prototype\fR\->observe_form( \f(CW$id\fR, \e%options )" 4
.IX Item "$prototype->observe_form( $id, %options )"
Like \f(CW\*(C`observe_field\*(C'\fR, but operates on an entire form identified by
the \s-1DOM ID\s0 \f(CW$id\fR.
.Sp
Options are the same as \f(CW\*(C`observe_field\*(C'\fR, except the default value of
the \f(CW\*(C`with\*(C'\fR option evaluates to the serialized (request string) value
of the form.
.ie n .IP "$prototype\->periodically_call_remote( \e%options )" 4
.el .IP "\f(CW$prototype\fR\->periodically_call_remote( \e%options )" 4
.IX Item "$prototype->periodically_call_remote( %options )"
Periodically calls the specified url \f(CW$options\fR\->{url} every
\&\f(CW$options\fR\->{frequency} seconds (default is 10).
.Sp
Usually used to update a specified div \f(CW$options\fR\->{update} with the
results of the remote call.
.Sp
The options for specifying the target with \f(CW\*(C`url\*(C'\fR and defining
callbacks is the same as \f(CW\*(C`link_to_remote\*(C'\fR.
.ie n .IP "$prototype\->sortable_element( $element_id, \e%options )" 4
.el .IP "\f(CW$prototype\fR\->sortable_element( \f(CW$element_id\fR, \e%options )" 4
.IX Item "$prototype->sortable_element( $element_id, %options )"
Makes the element with the \s-1DOM ID\s0 specified by \f(CW$element_id\fR sortable
by drag-and-drop and make an Ajax call whenever the sort order has
changed. By default, the action called gets the serialized sortable
element as parameters.
.Sp
Example:
\f(CW$prototype\fR\->sortable_element( 'my_list', { url => 'http://foo.bar/baz' } );
.Sp
In the example, the action gets a \*(L"my_list\*(R" array parameter
containing the values of the ids of elements the sortable consists
of, in the current order.
.Sp
You can change the behaviour with various options, see
http://script.aculo.us for more documentation.
.ie n .IP "$prototype\->submit_to_remote( $name, $value, \e%options )" 4
.el .IP "\f(CW$prototype\fR\->submit_to_remote( \f(CW$name\fR, \f(CW$value\fR, \e%options )" 4
.IX Item "$prototype->submit_to_remote( $name, $value, %options )"
Returns a button input tag that will submit a form using XMLHttpRequest
in the background instead of a typical reloading via \s-1POST.\s0
.Sp
\&\f(CW\*(C`options\*(C'\fR argument is the same as in \f(CW\*(C`form_remote_tag\*(C'\fR
.ie n .IP "$prototype\->tag( $name, \e%options, $starttag );" 4
.el .IP "\f(CW$prototype\fR\->tag( \f(CW$name\fR, \e%options, \f(CW$starttag\fR );" 4
.IX Item "$prototype->tag( $name, %options, $starttag );"
Returns a opening tag.
.ie n .IP "$prototype\->update_element_function( $element_id, \e%options, \e&code )" 4
.el .IP "\f(CW$prototype\fR\->update_element_function( \f(CW$element_id\fR, \e%options, \e&code )" 4
.IX Item "$prototype->update_element_function( $element_id, %options, &code )"
Returns a Javascript function (or expression) that'll update a \s-1DOM\s0 element
according to the options passed.
.Sp
\&\f(CW\*(C`content\*(C'\fR: The content to use for updating.
Can be left out if using block, see example.
.Sp
\&\f(CW\*(C`action\*(C'\fR: Valid options are \f(CW\*(C`update\*(C'\fR (assumed by default), :empty, :remove
.Sp
\&\f(CW\*(C`position\*(C'\fR: If the :action is :update, you can optionally specify one
of the following positions: :before, :top, :bottom, :after.
.Sp
Example:
\f(CW$prototype\fR\->javascript_tag( \f(CW$prototype\fR\->update_element_function(
'products', { position => 'bottom', content => 'New product!
'
) );
.Sp
This method can also be used in combination with remote method call
where the result is evaluated afterwards to cause multiple updates
on a page.
.Sp
Example:
# View
\f(CW$prototype\fR\->form_remote_tag( {
url => { \*(L"http://foo.bar/buy\*(R" },
complete => \f(CW$prototype\fR\->evaluate_remote_response
} );
.Sp
.Vb 8
\& # Returning view
\& $prototype\->update_element_function( \*(Aqcart\*(Aq, {
\& action => \*(Aqupdate\*(Aq,
\& position => \*(Aqbottom\*(Aq,
\& content => "New Product: $product_name
"
\& } );
\& $prototype\->update_element_function( \*(Aqstatus\*(Aq,
\& { binding => "You\*(Aqve bought a new product!" } );
.Ve
.ie n .IP "$prototype\->visual_effect( $name, $element_id, \e%js_options )" 4
.el .IP "\f(CW$prototype\fR\->visual_effect( \f(CW$name\fR, \f(CW$element_id\fR, \e%js_options )" 4
.IX Item "$prototype->visual_effect( $name, $element_id, %js_options )"
Returns a JavaScript snippet to be used on the Ajax callbacks for starting
visual effects.
.Sp
.Vb 7
\& $prototype\->link_to_remote( \*(AqReload\*(Aq, {
\& update => \*(Aqposts\*(Aq,
\& url => \*(Aqhttp://foo.bar/baz\*(Aq,
\& complete => $prototype\->visual_effect( \*(Aqhighlight\*(Aq, \*(Aqposts\*(Aq, {
\& duration => \*(Aq0.5\*(Aq
\& } )
\& } );
.Ve
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Catalyst::Plugin::Prototype, Catalyst.
.SH "AUTHOR"
.IX Header "AUTHOR"
Sascha Kiefer, \f(CW\*(C`esskar@cpan.org\*(C'\fR
Sebastian Riedel, \f(CW\*(C`sri@oook.de\*(C'\fR
Marcus Ramberg, \f(CW\*(C`mramberg@cpan.org\*(C'\fR
.PP
Built around Prototype by Sam Stephenson.
Much code is ported from Ruby on Rails javascript helpers.
.SH "THANK YOU"
.IX Header "THANK YOU"
Drew Taylor, Leon Brocard, Andreas Marienborg
.SH "LICENSE"
.IX Header "LICENSE"
This library is free software. You can redistribute it and/or modify it under
the same terms as perl itself.