From 44a2f7918ef9896cd6d16bdbaea64d74e5edd3a1 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 16 Jul 2009 13:55:03 -0600 Subject: [PATCH] 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. --- framework/Core/lib/Horde.php | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) 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"; + } + } -- 2.11.0