123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
-
- function link_to_function($name, $function, $html_options = array())
- {
- $html_options = _parse_attributes($html_options);
- $html_options['href'] = isset($html_options['href']) ? $html_options['href'] : '#';
- if ( isset($html_options['confirm']) )
- {
- $confirm = escape_javascript($html_options['confirm']);
- $html_options['onclick'] = "if(confirm('$confirm')){ $function;}; return false;";
- }
- else
- {
- $html_options['onclick'] = $function.'; return false;';
- }
- return content_tag('a', $name, $html_options);
- }
-
- function button_to_function($name, $function, $html_options = array())
- {
- $html_options = _parse_attributes($html_options);
- $html_options['onclick'] = $function.'; return false;';
- $html_options['type'] = 'button';
- $html_options['value'] = $name;
- return tag('input', $html_options);
- }
-
- function javascript_tag($content = null)
- {
- if (!is_null($content))
- {
- return content_tag('script', javascript_cdata_section($content), array('type' => 'text/javascript'));
- }
- else
- {
- ob_start();
- }
- }
- function end_javascript_tag()
- {
- echo javascript_tag(ob_get_clean());
- }
- function javascript_cdata_section($content)
- {
- return "\n//".cdata_section("\n$content\n//")."\n";
- }
-
- function if_javascript()
- {
- if (!sfContext::getInstance()->getRequest()->isXmlHttpRequest())
- {
- ob_start();
- }
- }
-
- function end_if_javascript()
- {
- if (!sfContext::getInstance()->getRequest()->isXmlHttpRequest())
- {
- $content = ob_get_clean();
- echo javascript_tag("document.write('" . esc_js_no_entities($content) . "');");
- }
- }
-
- function array_or_string_for_javascript($option)
- {
- if (is_array($option))
- {
- return "['".join('\',\'', $option)."']";
- }
- else if (is_string($option) && $option[0] != "'")
- {
- return "'$option'";
- }
- return $option;
- }
-
- 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).'}';
- }
-
- function boolean_for_javascript($bool)
- {
- if (is_bool($bool))
- {
- return ($bool===true ? 'true' : 'false');
- }
- return $bool;
- }
|