Exemplo n.º 1
0
 function test_link_to_function()
 {
     $foo = JsHelper::link_to_function('Greeting', "alert('Hello world!')", array('title' => 'hello'));
     $exp = '<a title="hello" href="#" onclick="alert(\'Hello world!\'); ' . 'return false;">Greeting</a>';
     $this->assertEqual($exp, $foo);
 }
Exemplo n.º 2
0
 /**
  * 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'.
  *
  * Examples:
  *  link_to_remote('Delete this post',
  *                 array('update' => 'posts', 'url' => 'destroy?id='.$id))
  *
  * 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:
  *  link_to_remote('Delete this post',
  *                 array('update' => array('success' => 'posts',
  *                                         'failure' => 'error'),
  *                       'url' => 'destroy?id='.$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.
  *
  * 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 present).
  *
  * You can further refine 'success' and 'failure' by adding additional
  * callbacks for specific status codes:
  *
  * Example:
  *   link_to_remote($word, array('url' => $rule,
  *                               '404' => "alert('Not found...?')",
  *                               'failure' => "alert('HTTPError!')"))
  *
  * 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.
  *
  * @param type <description>
  * @param type <description>
  * @param type <description>
  *
  * @return type <description>
  */
 function link_to_remote($name, $options = array(), $html_options = array())
 {
     return JsHelper::link_to_function($name, PrototypeHelper::remote_function($options), $html_options);
 }