[ Index ] |
|
Code source de Symfony 1.0.0 |
[Code source] [Imprimer] [Statistiques]
JavascriptHelper.
Author: | Fabien Potencier <fabien.potencier@symfony-project.com> |
Author: | John Christopher <john.christopher@symfony-project.com> |
Author: | David Heinemeier Hansson |
Version: | SVN: $Id: JavascriptHelper.php 3500 2007-02-18 10:25:13Z fabien $ |
Poids: | 1027 lignes (37 kb) |
Inclus ou requis: | 0 fois |
Référencé: | 0 fois |
Nécessite: | 0 fichiers |
get_callbacks() X-Ref |
Pas de description |
get_ajax_options() X-Ref |
Pas de description |
link_to_function($name, $function, $html_options = array() X-Ref |
Returns a link that'll trigger a javascript function using the onclick handler and return false after the fact. Examples: <?php echo link_to_function('Greeting', "alert('Hello world!')") ?> <?php echo link_to_function(image_tag('delete'), "if confirm('Really?'){ do_delete(); }") ?> |
button_to_function($name, $function, $html_options = array() X-Ref |
Returns a button that'll trigger a javascript function using the onclick handler and return false after the fact. Examples: <?php echo button_to_function('Greeting', "alert('Hello world!')") ?> |
button_to_remote($name, $options = array() X-Ref |
Returns an html button to a remote action defined by 'url' (using the 'url_for()' format) that's called in the background using XMLHttpRequest. See link_to_remote() for details. |
link_to_remote($name, $options = array() X-Ref |
Returns a link to a remote action defined by 'url' (using the 'url_for()' format) 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 'update'. Usually, the result would be a partial prepared by the controller with either 'render_partial()'. Examples: <?php echo link_to_remote('Delete this post'), array( 'update' => 'posts', 'url' => 'destroy?id='.$post.id, )) ?> <?php echo link_to_remote(image_tag('refresh'), array( 'update' => 'emails', 'url' => '@list_emails', )) ?> You can also specify a hash for 'update' to allow for easy redirection of output to an other DOM element if a server-side error occurs: Example: <?php echo link_to_remote('Delete this post', array( 'update' => array('success' => 'posts', 'failure' => 'error'), 'url' => 'destroy?id='.$post.id, )) ?> Optionally, you can use the 'position' parameter to influence how the target DOM element is updated. It must be one of 'before', 'top', 'bottom', or 'after'. By default, these remote requests are processed asynchronous during which various JavaScript callbacks can be triggered (for progress indicators and the likes). All callbacks get access to the 'request' object, which holds the underlying XMLHttpRequest. To access the server response, use 'request.responseText', to find out the HTTP status, use 'request.status'. Example: <?php echo link_to_remote($word, array( 'url' => '@undo?n='.$word_counter, 'complete' => 'undoRequestCompleted(request)' )) ?> The callbacks that may be specified are (in order): '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. 'success' Called when the XMLHttpRequest is completed, and the HTTP status code is in the 2XX range. 'failure' Called when the XMLHttpRequest is completed, and the HTTP status code is not in the 2XX range. 'complete' Called when the XMLHttpRequest is complete (fires after success/failure if they are present)., You can further refine 'success' and 'failure' by adding additional callbacks for specific status codes: Example: <?php echo link_to_remote($word, array( 'url' => '@rule', '404' => "alert('Not found...? Wrong URL...?')", 'failure' => "alert('HTTP Error ' + request.status + '!')", )) ?> A status code callback overrides the success/failure handlers if present. If you for some reason or another need synchronous processing (that'll block the browser while the request is happening), you can specify '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'. 'submit' Specifies the DOM element ID that's used as the parent of the form elements. By default this is the current form, but it could just as well be the ID of a table row or any other DOM element. |
periodically_call_remote($options = array() X-Ref |
Periodically calls the specified url ('url') every 'frequency' seconds (default is 10). Usually used to update a specified div ('update') with the results of the remote call. The options for specifying the target with 'url' and defining callbacks is the same as 'link_to_remote()'. |
form_remote_tag($options = array() X-Ref |
Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement. Even though it's using JavaScript to serialize the form elements, the form submission will work just like a regular submission as viewed by the receiving side (all elements available in 'params'). The options for specifying the target with 'url' and defining callbacks are the same as 'link_to_remote()'. A "fall-through" target for browsers that don't do JavaScript can be specified with the 'action'/'method' options on '$options_html' Example: <?php echo form_remote_tag(array( 'url' => '@tag_add', 'update' => 'question_tags', 'loading' => "Element.show('indicator'); \$('tag').value = ''", 'complete' => "Element.hide('indicator');".visual_effect('highlight', 'question_tags'), )) ?> The hash passed as a second argument is equivalent to the options (2nd) argument in the form_tag() helper. By default the fall-through action is the same as the one specified in the 'url' (and the default method is 'post'). |
submit_to_remote($name, $value, $options = array() X-Ref |
Returns a button input tag that will submit form using XMLHttpRequest in the background instead of regular reloading POST arrangement. The '$options' argument is the same as in 'form_remote_tag()'. |
update_element_function($element_id, $options = array() X-Ref |
Returns a Javascript function (or expression) that will update a DOM element '$element_id' according to the '$options' passed. Possible '$options' are: 'content' The content to use for updating. Can be left out if using block, see example. 'action' Valid options are 'update' (assumed by default), 'empty', 'remove' 'position' If the 'action' is 'update', you can optionally specify one of the following positions: 'before', 'top', 'bottom', 'after'. Example: <?php echo javascript_tag( update_element_function('products', array( 'position' => 'bottom', 'content' => "<p>New product!</p>", )) ) ?> 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: # Calling view <?php echo form_remote_tag(array( 'url' => '@buy', 'complete' => evaluate_remote_response() )) ?> all the inputs here... # Target action public function executeBuy() { $this->product = ProductPeer::retrieveByPk(1); } # Returning view <php echo update_element_function('cart', array( 'action' => 'update', 'position' => 'bottom', 'content' => '<p>New Product: '.$product->getName().'</p>', )) ?> |
evaluate_remote_response() X-Ref |
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. |
remote_function($options) X-Ref |
Returns the javascript needed for a remote function. Takes the same arguments as 'link_to_remote()'. Example: <select id="options" onchange="<?php echo remote_function(array('update' => 'options', 'url' => '@update_options')) ?>"> <option value="0">Hello</option> <option value="1">World</option> </select> |
observe_field($field_id, $options = array() X-Ref |
Observes the field with the DOM ID specified by '$field_id' and makes an AJAX call when its contents have changed. Required '$options' are: 'url' 'url_for()'-style options for the action to call when the field has changed. Additional options are: 'frequency' The frequency (in seconds) at which changes to this field will be detected. Not setting this option at all or to a value equal to or less than zero will use event based observation instead of time based observation. '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(). |
observe_form($form_id, $options = array() X-Ref |
Like 'observe_field()', but operates on an entire form identified by the DOM ID '$form_id'. '$options' are the same as 'observe_field()', except the default value of the 'with' option evaluates to the serialized (request string) value of the form. |
visual_effect($name, $element_id = false, $js_options = array() X-Ref |
Returns a JavaScript snippet to be used on the AJAX callbacks for starting visual effects. Example: <?php echo link_to_remote('Reload', array( 'update' => 'posts', 'url' => '@reload', 'complete => visual_effect('highlight', 'posts', array('duration' => 0.5 )), )) ?> If no '$element_id' is given, it assumes "element" which should be a local variable in the generated JavaScript execution context. This can be used for example with drop_receiving_element(): <?php echo drop_receving_element( ..., array( ... 'loading' => visual_effect('fade'), )) ?> This would fade the element that was dropped on the drop receiving element. You can change the behaviour with various options, see http://script.aculo.us for more documentation. |
sortable_element($element_id, $options = array() X-Ref |
Makes the elements with the DOM ID specified by '$element_id' 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. Example: <php echo sortable_element($my_list, array( 'url' => '@order', )) ?> In the example, the action gets a '$my_list' array parameter containing the values of the ids of elements the sortable consists of, in the current order. You can change the behaviour with various options, see http://script.aculo.us for more documentation. |
draggable_element($element_id, $options = array() X-Ref |
Makes the element with the DOM ID specified by '$element_id' draggable. Example: <?php echo draggable_element('my_image', array( 'revert' => true, )) ?> You can change the behaviour with various options, see http://script.aculo.us for more documentation. |
drop_receiving_element($element_id, $options = array() X-Ref |
Makes the element with the DOM ID specified by '$element_id' receive dropped draggable elements (created by 'draggable_element()') and make an AJAX call. By default, the action called gets the DOM ID of the element as parameter. Example: <?php drop_receiving_element('my_cart', array( 'url' => 'cart/add', )) ?> You can change the behaviour with various options, see http://script.aculo.us for more documentation. |
javascript_tag($content) X-Ref |
Returns a JavaScript tag with the '$content' inside. Example: <?php echo javascript_tag("alert('All is good')") ?> => <script type="text/javascript">alert('All is good')</script> |
javascript_cdata_section($content) X-Ref |
Pas de description |
input_auto_complete_tag($name, $value, $url, $tag_options = array() X-Ref |
wrapper for script.aculo.us/prototype Ajax.Autocompleter. param: string name value of input field param: string default value for input field param: array input tag options. (size, autocomplete, etc...) param: array completion options. (use_style, etc...) return: string input field tag, div for completion results, and |
input_in_place_editor_tag($name, $url, $editor_options = array() X-Ref |
wrapper for script.aculo.us/prototype Ajax.InPlaceEditor. param: string name id of field that can be edited param: string url of module/action to be called when ok is clicked param: array editor tag options. (rows, cols, highlightcolor, highlightendcolor, etc...) return: string javascript to manipulate the id field to allow click and edit functionality |
if_javascript() X-Ref |
Mark the start of a block that should only be shown in the browser if JavaScript is switched on. |
end_if_javascript() X-Ref |
Mark the end of a block that should only be shown in the browser if JavaScript is switched on. |
_in_place_editor($field_id, $url, $options = array() X-Ref |
Pas de description |
_auto_complete_field($field_id, $url, $options = array() X-Ref |
wrapper for script.aculo.us/prototype Ajax.Autocompleter. param: string id value of input field param: string url of module/action to execute for autocompletion param: array completion options return: string javascript tag for Ajax.Autocompleter |
_options_for_javascript($options) X-Ref |
Pas de description |
_array_or_string_for_javascript($option) X-Ref |
Pas de description |
_options_for_ajax($options) X-Ref |
Pas de description |
_method_option_to_s($method) X-Ref |
Pas de description |
_build_observer($klass, $name, $options = array() X-Ref |
Pas de description |
_build_callbacks($options) X-Ref |
Pas de description |
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |