Exemplo n.º 1
0
    function test_javascript_tag()
    {
        $foo = JsHelper::javascript_tag("alert('All is good')");
        $exp = <<<EXPECTED
<script type="text/javascript">
//<![CDATA[
alert('All is good')
//]]>
</script>
EXPECTED;
        $this->assertEqual($exp, $foo);
    }
Exemplo n.º 2
0
 /**
  * @ignore
  */
 function build_observer($klass, $name, $options = array())
 {
     if (!isset($options['with']) && $options['update']) {
         $options['with'] = 'value';
     }
     $callback = PrototypeHelper::remote_function($options);
     $javascript = 'new ' . $klass . '("' . $name . '", ';
     if (isset($options['frequency'])) {
         $javascript .= $options['frequency'] . ", ";
     }
     $javascript .= 'function(element, value) {';
     $javascript .= $callback . '});';
     return JsHelper::javascript_tag($javascript);
 }
Exemplo n.º 3
0
 /**
  * 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.
  */
 function sortable_element($element_id, $options = array())
 {
     if (!isset($options['with'])) {
         $options['with'] = "Sortable.serialize('{$element_id}')";
     }
     if (!isset($options['onUpdate'])) {
         $options['onUpdate'] = sprintf('function(){%s}', PrototypeHelper::remote_function($options));
     }
     foreach (PrototypeHelper::get_ajax_options() as $key) {
         unset($options[$key]);
     }
     foreach (array('tag', 'overlap', 'constraint', 'handle') as $option) {
         if (isset($options[$option])) {
             $options[$option] = "'{$options[$option]}'";
         }
     }
     if (isset($options['containment'])) {
         $options['containment'] = self::array_or_string_for_javascript($options['containment']);
     }
     if (isset($options['hoverclass'])) {
         $options['hoverclass'] = "'{$options['hoverclass']}'";
     }
     if (isset($options['only'])) {
         $options['only'] = self::array_or_string_for_javascript($options['only']);
     }
     return JsHelper::javascript_tag(sprintf("Sortable.create('%s', %s)", $element_id, JsHelper::options_for_javascript($options)));
 }