Revise Horde::addScriptFile() API
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 6 Oct 2009 18:53:40 +0000 (12:53 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 6 Oct 2009 18:53:40 +0000 (12:53 -0600)
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.

framework/Ajax/lib/Horde/Ajax/Imple/SpellChecker.php
framework/Core/lib/Horde.php
framework/Editor/lib/Horde/Editor/Fckeditor.php
framework/Editor/lib/Horde/Editor/Xinha.php
framework/Text_Filter/lib/Horde/Text/Filter/Highlightquotes.php

index 80c5782..29ecfc6 100644 (file)
@@ -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']));
 
index 3bd559d..701db50 100644 (file)
@@ -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:
+     * <pre>
+     * '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
+     * </pre>
      *
      * @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, '?');
index d541010..b8238b2 100644 (file)
@@ -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 = '<script type="text/javascript" src="' . $fck_path . 'fckeditor.js"></script><script type="text/javascript">' . $js . '</script>';
+            $this->_js = '<script type="text/javascript" src="' . $fck_path . 'fckeditor.js"></script><script type="text/javascript">' . implode(';', $js) . '</script>';
         } 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');
         }
     }
 
index 9d08f26..d9fc13e 100644 (file)
@@ -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 = '<script type="text/javascript">' . $js . '</script><script type="text/javascript" src="' . $xinha_path . 'XinhaCore.js"></script>';
         } 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');
         }
     }
 
index 17705ce..403c03f 100644 (file)
@@ -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']) ? '<br />' : '') .