From: Michael M Slusarz Date: Thu, 16 Jul 2009 19:55:03 +0000 (-0600) Subject: Add IMP inline script handling functions. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=44a2f7918ef9896cd6d16bdbaea64d74e5edd3a1;p=horde.git Add IMP inline script handling functions. Again, this will probably eventually need to be moved elsewhere, but it needs to be moved out of IMP immediately since several things moving to framework rely on this code. --- diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index 2caa80334..e6a329fd0 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -57,6 +57,13 @@ class Horde static protected $_hooksLoaded = array(); /** + * Inline script cache. + * + * @var array + */ + static protected $_inlineScript = array(); + + /** * Logs a message to the global Horde log backend. * * @param mixed $message Either a string or an object with a @@ -1866,4 +1873,68 @@ HTML; exit; } + /** + * Add inline javascript to the output buffer. + * + * @param mixed $script The script text to add (can be stored in an + * array also). + * @param string $onload Load the script after the page has loaded? + * Either 'dom' (on dom:loaded), 'load'. + */ + static public function addInlineScript($script, $onload = false) + { + if (is_array($script)) { + $script = implode(';', $script); + } + + $script = trim($script); + if (empty($script)) { + return; + } + + switch ($onload) { + case 'dom': + $script = 'document.observe("dom:loaded", function() {' . $script . '});'; + break; + + case 'load': + $script = 'Event.observe(window, "load", function() {' . $script . '});'; + break; + } + + self::$_inlineScript[] = $script; + + // If headers have already been sent, we need to output a + // \n"; + } + }