<?php
function javascript_escape($raw) {
return str_replace("'","\'",str_replace("\\","\\\\",$raw));
}
$old_internet_explorer = preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"]);
$internet_explorer_buggy = $old_internet_explorer
&& preg_match("/MSIE 5.0/", $_SERVER["HTTP_USER_AGENT"]);
function set_attribute($object,
$attribute,
$value,
$indentation) { /* set a javascript
attribute portably */
global $internet_explorer_buggy;
return $indentation . (!$internet_explorer_buggy ?
( 'var attribute = document.createAttribute("'
. $attribute . '");' . $indentation
. 'attribute.nodeValue = ' . $value . ';' . $indentation
. $object . '.setAttributeNode(attribute);') :
($object . '.' . $attribute . ' = ' . $value . ';'));
}
function js_array_push($array,$value) { /* push to javascript array portably*/
global $internet_explorer_buggy;
return $internet_explorer_buggy
? ($array . "[" . $array . ".length] = $value;")
: ($array . ".push($value);");
}
function js_event_listener($element, $event, $action, $indentation) {
/* portably add an event listener $action for the event
$event on the element $element */
return $indentation
. "if (window.addEventListener) {" . $indentation
. " $element.addEventListener('$event', $action, false);"
. $indentation
. "} else {" . $indentation
. " $element.attachEvent('on$event', $action);" . $indentation
. "}";
}
?>