From: Michael M Slusarz Date: Tue, 6 Oct 2009 18:53:40 +0000 (-0600) Subject: Revise Horde::addScriptFile() API X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=82ab649321b2e7d418610f4d089c8d78c4763e45;p=horde.git Revise Horde::addScriptFile() API Move addExternalScriptFile() into this function - no reason to have a separate function for this. Direct loading should be the default. Loading through javascript.php is deprecated and any remaining scripts that contain PHP code should be rewritten ASAP. Fix javascript loading for fckeditor - use addScriptFile() instead of the deprecated javascript notification handler. --- diff --git a/framework/Ajax/lib/Horde/Ajax/Imple/SpellChecker.php b/framework/Ajax/lib/Horde/Ajax/Imple/SpellChecker.php index 80c57824a..29ecfc6a4 100644 --- a/framework/Ajax/lib/Horde/Ajax/Imple/SpellChecker.php +++ b/framework/Ajax/lib/Horde/Ajax/Imple/SpellChecker.php @@ -56,10 +56,10 @@ class Horde_Ajax_Imple_SpellChecker extends Horde_Ajax_Imple_Base */ public function attach() { - Horde::addScriptFile('prototype.js', 'horde', true); - Horde::addScriptFile('effects.js', 'horde', true); - Horde::addScriptFile('KeyNavList.js', 'horde', true); - Horde::addScriptFile('SpellChecker.js', 'horde', true); + Horde::addScriptFile('prototype.js', 'horde'); + Horde::addScriptFile('effects.js', 'horde'); + Horde::addScriptFile('KeyNavList.js', 'horde'); + Horde::addScriptFile('SpellChecker.js', 'horde'); $url = $this->_getUrl('SpellChecker', 'horde', array('input' => $this->_params['targetId'])); diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index 3bd559dfc..701db50cf 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -267,20 +267,31 @@ HTML; * Adds the javascript code to the output (if output has already started) * or to the list of script files to include via includeScriptFiles(). * - * @param string $file The full javascript file name. - * @param string $app The application name. Defaults to the current - * application. - * @param boolean $direct Include the file directly without passing it - * through javascript.php - * @param boolean $full Output a full URL + * @param string $file The full javascript file name. + * @param string $app The application name. Defaults to the current + * application. + * @param array $options Additional options: + *
+     * 'direct' - (boolean) Include the file directly without passing it
+     *            through javascript.php.
+     *            DEFAULT: true
+     * 'external' - (boolean) Treat $file as an external URL.
+     *              DEFAULT: $file is located in the app's js/ directory.
+     * 'full' - (boolean) Output a full URL
+     *          DEFAULT: false
+     * 
* * @throws Horde_Exception */ - static public function addScriptFile($file, $app = null, $direct = false, - $full = false) + static public function addScriptFile($file, $app = null, + $options = array()) { $hsf = Horde_Script_Files::singleton(); - $hsf->add($file, $app, $direct, $full); + if (empty($options['external'])) { + $hsf->add($file, $app, isset($options['direct']) ? $options['direct'] : true, !empty($options['full'])); + } else { + $hsf->addExternal($file, $app); + } } /** @@ -413,18 +424,6 @@ HTML; } /** - * Inlude script files from external sources. - * - * @param string $url The url to the external script file. - * @param string $app The app scope - */ - static public function addExternalScriptFile($url, $app = null) - { - $hsf = Horde_Script_Files::singleton(); - $hsf->addExternal($url, $app); - } - - /** * Get a token for protecting a form. * * @param string $slug Slug name. @@ -2229,7 +2228,7 @@ HTML; */ static public function popupJs($url, $options = array()) { - Horde::addScriptFile('popup.js', 'horde', true); + Horde::addScriptFile('popup.js', 'horde'); $params = new stdClass; $pos = strpos($url, '?'); diff --git a/framework/Editor/lib/Horde/Editor/Fckeditor.php b/framework/Editor/lib/Horde/Editor/Fckeditor.php index d541010ea..b8238b201 100644 --- a/framework/Editor/lib/Horde/Editor/Fckeditor.php +++ b/framework/Editor/lib/Horde/Editor/Fckeditor.php @@ -28,14 +28,18 @@ class Horde_Editor_Fckeditor extends Horde_Editor public function __construct($params = array()) { $fck_path = $GLOBALS['registry']->get('webroot', 'horde') . '/services/editor/fckeditor/'; - $js = "var oFCKeditor = new FCKeditor('" . $params['id'] . "'); oFCKeditor.BasePath = '" . $fck_path . "';"; + $js = array( + 'var oFCKeditor = new FCKeditor("' . $params['id'] . '")', + 'oFCKeditor.BasePath = "' . $fck_path . '"' + ); if (!empty($params['no_notify'])) { - $this->_js = ''; + $this->_js = ''; } else { - Horde::addScriptFile('prototype.js', 'horde', true); - $GLOBALS['notification']->push('Event.observe(window, \'load\', function() {' . $js . ' oFCKeditor.ReplaceTextarea();});', 'javascript'); - $GLOBALS['notification']->push($fck_path . 'fckeditor.js', 'javascript-file'); + Horde::addScriptFile('prototype.js', 'horde'); + Horde::addScriptFile($fck_path . 'fckeditor.js', null, array('external' => true)); + $js[] = 'oFCKeditor.ReplaceTextarea()'; + Horde::addInlineScript($js, 'load'); } } diff --git a/framework/Editor/lib/Horde/Editor/Xinha.php b/framework/Editor/lib/Horde/Editor/Xinha.php index 9d08f261c..d9fc13e11 100644 --- a/framework/Editor/lib/Horde/Editor/Xinha.php +++ b/framework/Editor/lib/Horde/Editor/Xinha.php @@ -139,15 +139,16 @@ class Horde_Editor_xinha extends Horde_Editor 'Xinha.startEditors(_editors); };'; if (empty($params['no_autoload'])) { - Horde::addScriptFile('prototype.js', 'horde', true); - $js .= 'Event.observe(window, \'load\', xinha_init);'; + Horde::addScriptFile('prototype.js', 'horde'); } if (!empty($params['no_notify'])) { + $js .= 'Event.observe(window, \'load\', xinha_init);'; $this->_js = ''; } else { - $GLOBALS['notification']->push($js, 'javascript'); - $GLOBALS['notification']->push($xinha_path . 'XinhaCore.js', 'javascript-file'); + Horde::addScriptFile($xinha_path . 'XinhaCore.js', null, array('external' => true)); + Horde::addInlineScript($js); + Horde::addInlineScript('xinha_init()', 'load'); } } diff --git a/framework/Text_Filter/lib/Horde/Text/Filter/Highlightquotes.php b/framework/Text_Filter/lib/Horde/Text/Filter/Highlightquotes.php index 17705ce51..403c03f36 100644 --- a/framework/Text_Filter/lib/Horde/Text/Filter/Highlightquotes.php +++ b/framework/Text_Filter/lib/Horde/Text/Filter/Highlightquotes.php @@ -156,7 +156,7 @@ class Horde_Text_Filter_Highlightquotes extends Horde_Text_Filter if ($qcount > 8) { if ($this->_params['outputJS']) { - Horde::addScriptFile('prototype.js', 'horde', true); + Horde::addScriptFile('prototype.js', 'horde'); } $out .= (($this->_params['citeblock']) ? '
' : '') .