/**
* converts the the PHP options array into a javscript array
 *
 * @param array
 * @return string javascript arry equivalent
*/
function options_for_javascript($options)
{
    $opts = array();
    foreach ($options as $key => $value) {
        if (is_array($value)) {
            $value = options_for_javascript($value);
        }
        $opts[] = $key . ":" . boolean_for_javascript($value);
    }
    sort($opts);
    return '{' . join(', ', $opts) . '}';
}
/**
 * Internal function don't use.
 */
function toJsArgument($value, $isFunction = false)
{
    $pattern = '%s';
    if ($isFunction) {
        $pattern = sprintf($pattern, $value);
    } else {
        if (!is_null($value)) {
            if (is_array($value)) {
                $pattern = sprintf($pattern, json_encode($value));
            }
            if (is_numeric($value)) {
                $pattern = sprintf($pattern, $value);
            }
            if (is_string($value)) {
                $pattern = "'%s'";
                $pattern = sprintf($pattern, $value);
            }
            if (is_bool($value)) {
                $pattern = sprintf($pattern, boolean_for_javascript($value));
            }
        }
    }
    return $pattern;
}
Exemplo n.º 3
0
 * This file is part of the symfony package.
 * (c) 2004-2006 Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../bootstrap/unit.php';
require_once __DIR__ . '/../../../lib/helper/TagHelper.php';
require_once __DIR__ . '/../../../lib/helper/JavascriptBaseHelper.php';
$t = new lime_test(9, new lime_output_color());
// boolean_for_javascript()
$t->diag('boolean_for_javascript()');
$t->is(boolean_for_javascript(true), 'true', 'boolean_for_javascript() makes a javascript representation of the boolean if the param is boolean');
$t->is(boolean_for_javascript(false), 'false', 'boolean_for_javascript() makes a javascript representation of the boolean if the param is boolean');
$t->is(boolean_for_javascript(1 == 0), 'false', 'boolean_for_javascript() makes a javascript representation of the boolean if the param is boolean');
$t->is(boolean_for_javascript('dummy'), 'dummy', 'boolean_for_javascript() makes a javascript representation of the boolean if the param is boolean');
//options_for_javascript()
$t->diag('options_for_javascript()');
$t->is(options_for_javascript(array("'a'" => "'b'", "'c'" => false)), "{'a':'b', 'c':false}", 'options_for_javascript() makes a javascript representation of the passed array');
$t->is(options_for_javascript(array("'a'" => array("'b'" => "'c'"))), "{'a':{'b':'c'}}", 'options_for_javascript() works with nested arrays');
//javascript_tag()
$t->diag('javascript_tag()');
$expect = <<<EOT
<script type="text/javascript">
//<![CDATA[
alert("foo");
//]]>
</script>
EOT;
$t->is(javascript_tag('alert("foo");'), $expect, 'javascript_tag() takes the content as string parameter');
//link_to_function()
Exemplo n.º 4
0
/**
 * Set up an automatic rotation through tabs of a tab pane.
 * 
 * @param string $selector jQuery Selector
 * @param string $ms Is an amount of time in milliseconds until the next tab in
 *                   the cycle gets activated. Set value 0 to stop the rotation.
 * @param string $continuing Control whether or not to continue the rotation
 * after a tab has been selected by a user. Default: false
 * @return string
 */
function ui_tabs_rotate($selector, $ms = 0, $continuing = false)
{
    $continuingVal = false;
    if (is_bool($continuing) && $continuing == true) {
        $continuingVal = true;
    }
    $params = sprintf("%s,%s", $ms * 1000, boolean_for_javascript($continuingVal));
    return add_method_support('tabs', $selector, 'rotate', $params);
}