From a99e1d25f58ce2cacad532b14b37af2d6424ca34 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sun, 18 Jan 2009 10:41:45 -0500 Subject: [PATCH] Even better, add an 'onload' parameter to Kronolith::addInlineScript() like we do in IMP. --- kronolith/lib/Imple/ContactAutoCompleter.php | 2 +- kronolith/lib/Kronolith.php | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/kronolith/lib/Imple/ContactAutoCompleter.php b/kronolith/lib/Imple/ContactAutoCompleter.php index 2405b4e33..a69cd9180 100644 --- a/kronolith/lib/Imple/ContactAutoCompleter.php +++ b/kronolith/lib/Imple/ContactAutoCompleter.php @@ -53,7 +53,7 @@ class Imple_ContactAutoCompleter extends Imple $params[] = '{' . implode(',', $js_params) . '}'; - Kronolith::addInlineScript('document.observe(\'dom:loaded\', function () {new Ajax.Autocompleter(' . implode(',', $params) . ')})'); + Kronolith::addInlineScript('new Ajax.Autocompleter(' . implode(',', $params) . ')', 'dom'); } /** diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 27917fdac..96064ed78 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -162,13 +162,15 @@ class Kronolith { * * @since Kronolith 2.2 * - * @param mixed $script The script text to add (can be stored in an - * array also). + * @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'. * * @return string The javascript text to output, or empty if the page * headers have not yet been sent. */ - function addInlineScript($script) + function addInlineScript($script, $onload = false) { if (is_array($script)) { $script = implode(';', $script); @@ -178,6 +180,15 @@ class Kronolith { 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; + } if (!isset($GLOBALS['__kronolith_inline_script'])) { $GLOBALS['__kronolith_inline_script'] = array(); -- 2.11.0