NAME HTML::Prototype - Generate HTML and Javascript for the Prototype library SYNOPSIS 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->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 $ptototype->update_element_function(...); print $prototype->visual_effect(...); DESCRIPTION The module contains some code generators for Prototype, the famous JavaScript OO library and the script.aculous extensions. The Prototype library (http://prototype.conio.net/) is designed to make AJAX easy. Catalyst::Plugin::Prototype makes it easy to connect to the Prototype library. This is mostly a port of the Ruby on Rails helper tags for JavaScript for use in Catalyst. METHODS $prototype->auto_complete_field( $field_id, \%options ) Adds Ajax autocomplete functionality to the text input field with the DOM ID specified by "field_id". This function expects that the called action returns a HTML
', 'do_delete()' )
$prototype->link_to_remote( $content, \%options, \%html_options )
Returns a link to a remote action defined by options "url" that's
called in the background using XMLHttpRequest.
The result of that request can then be inserted into a DOM object
whose id can be specified with options->{update}.
Examples:
$prototype->link_to_remote( 'Delete', {
update => 'posts',
url => 'http://localhost/posts/'
} )
$prototype->link_to_remote( '
', {
update => 'emails',
url => 'http://localhost/refresh/'
} )
By default, these remote requests are processed asynchronously,
during which various callbacks can be triggered (e.g. for progress
indicators and the like).
Example:
$prototype->link_to_remote( 'count', {
url => 'http://localhost/count/',
complete => 'doStuff(request)'
} )
The callbacks that may be specified are:
"loading": Called when the remote document is being loaded with data
by the browser.
"loaded": Called when the browser has finished loading the remote
document.
"interactive": Called when the user can interact with the remote
document, even though it has not finished loading.
"complete": Called when the XMLHttpRequest is complete.
If you do need synchronous processing (this will block the browser
while the request is happening), you can specify $options->{type} =
'synchronous'.
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:
"confirm": Adds confirmation dialog.
"condition": Perform remote request conditionally by this
expression. Use this to describe browser-side conditions when
request should not be initiated.
"before": Called before request is initiated.
"after": Called immediately after request was initiated and before
"loading".
$prototype->observe_field( $id, \%options)
Observes the field with the DOM ID specified by $id and makes an
Ajax when its contents have changed.
Required options are:
"frequency": The frequency (in seconds) at which changes to this
field will be detected.
"url": url to be called when field content has changed.
Additional options are:
"update": Specifies the DOM ID of the element whose innerHTML should
be updated with the XMLHttpRequest response text.
"with": A JavaScript expression specifying the parameters for the
XMLHttpRequest. This defaults to value, which in the evaluated
context refers to the new field value.
Additionally, you may specify any of the options documented in
"link_to_remote".
Example TT2 template in Catalyst:
[% c.prototype.define_javascript_functions %]
New product!
' ) ); 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. Example: # View $prototype->form_remote_tag( { url => { "http://foo.bar/buy" }, complete => $prototype->evaluate_remote_response } ); # Returning view $prototype->update_element_function( 'cart', { action => 'update', position => 'bottom', content => "New Product: $product_name
" } ); $prototype->update_element_function( 'status', { binding => "You've bought a new product!" } ); $prototype->visual_effect( $name, $element_id, \%js_options ) Returns a JavaScript snippet to be used on the Ajax callbacks for starting visual effects. $prototype->link_to_remote( 'Reload', { update => 'posts', url => 'http://foo.bar/baz', complete => $prototype->visual_effect( 'highlight', 'posts', { duration => '0.5' } ) } ); SEE ALSO Catalyst::Plugin::Prototype, Catalyst.