1: <?php
2: /**
3: * Copyright 2007 Maintainable Software, LLC
4: * Copyright 2006-2012 Horde LLC (http://www.horde.org/)
5: *
6: * @author Mike Naberezny <mike@maintainable.com>
7: * @author Derek DeVries <derek@maintainable.com>
8: * @author Chuck Hagenbuch <chuck@horde.org>
9: * @license http://www.horde.org/licenses/bsd
10: * @category Horde
11: * @package View
12: * @subpackage Helper
13: */
14:
15: /**
16: * @author Mike Naberezny <mike@maintainable.com>
17: * @author Derek DeVries <derek@maintainable.com>
18: * @author Chuck Hagenbuch <chuck@horde.org>
19: * @license http://www.horde.org/licenses/bsd
20: * @category Horde
21: * @package View
22: * @subpackage Helper
23: */
24: class Horde_View_Helper_Javascript extends Horde_View_Helper_Base
25: {
26: public function escapeJavascript($javascript)
27: {
28: return str_replace(array('\\', "\r\n", "\r", "\n", '"', "'"),
29: array('\0\0', "\\n", "\\n", "\\n", '\"', "\'"),
30: $javascript);
31: }
32:
33: public function javascriptTag($content, $htmlOptions = array())
34: {
35: return $this->contentTag('script',
36: $this->javascriptCdataSection($content),
37: array_merge($htmlOptions, array('type' => 'text/javascript')));
38: }
39:
40: public function javascriptCdataSection($content)
41: {
42: return "\n//" . $this->cdataSection("\n$content\n//") . "\n";
43: }
44: }
45: