No PHP code in open_html_helper.js script
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 27 Jul 2010 21:28:31 +0000 (15:28 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 27 Jul 2010 21:45:46 +0000 (15:45 -0600)
framework/Core/lib/Horde/Core/Text/Filter/Emoticons.php
framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php
framework/Model/lib/Horde/Form/VarRenderer/Xhtml.php
framework/Text_Filter/lib/Horde/Text/Filter/Emoticons.php
horde/js/open_html_helper.js [new file with mode: 0644]
horde/templates/javascript/open_html_helper.js [deleted file]

index 1f03e5a..c3694c9 100644 (file)
@@ -22,7 +22,7 @@ class Horde_Core_Text_Filter_Emoticons extends Horde_Text_Filter_Emoticons
      *
      * @return string  The HTML image code.
      */
-    protected function _emoticonReplace($icon)
+    public function getIcon($icon)
     {
         return Horde::img(Horde_Themes::img('emoticons/' . $this->getIcons($icon) . '.png'), $icon, array('align' => 'middle', 'title' => $icon));
     }
index 4552635..0ef8c30 100644 (file)
@@ -293,10 +293,26 @@ class Horde_Core_Ui_VarRenderer_Html extends Horde_Core_Ui_VarRenderer
 
         if ($var->type->hasHelper() && $browser->hasFeature('javascript')) {
             $html .= '<br /><table cellspacing="0"><tr><td>';
-            Horde::addScriptFile('open_html_helper.js', 'horde', array('direct' => false));
             $imgId = $this->_genID($var->getVarName(), false) . 'ehelper';
+
+            Horde::addScriptFile('open_html_helper.js', 'horde');
+
             if ($var->type->hasHelper('emoticons')) {
-                $html .= Horde::link('#', _("Emoticons"), '', '', 'openHtmlHelper(\'emoticons\', \'' . $var->getVarName() . '\'); return false;') . Horde::img('emoticons/smile.png', _("Emoticons"), 'id="' . $imgId . '"') . '</a>';
+                $filter = $GLOBALS['injector']->getInstance('Horde_Text_Filter')->getFilter('emoticons');
+                $icon_list = array();
+
+                foreach (array_flip($filter->getIcons()) as $icon => $string) {
+                    $icon_list[] = array(
+                        $filter->getIcon($icon),
+                        $string
+                    );
+                }
+
+                Horde::addInlineScript(array(
+                    'Horde_Html_Helper.iconlist = ' . Horde_Serialize::serialize($icon_list, Horde_Serialize::JSON, $GLOBALS['registry']->getCharset())
+                ));
+
+                $html .= Horde::link('#', _("Emoticons"), '', '', 'Horde_Html_Helper.open(\'emoticons\', \'' . $var->getVarName() . '\'); return false;') . Horde::img('emoticons/smile.png', _("Emoticons"), 'id="' . $imgId . '"') . '</a>';
             }
             $html .= '</td></tr><tr><td><div ' . $this->_genID('htmlhelper_' . $var->getVarName()) . ' class="control"></div></td></tr></table>' . "\n";
         }
index c97a9a6..9db8f92 100644 (file)
@@ -161,10 +161,24 @@ class Horde_Form_VarRenderer_Xhtml extends Horde_Form_VarRenderer
 
         if ($var->type->hasHelper() && $browser->hasFeature('javascript')) {
             $html .= '<div class="form-html-helper">';
-            Horde::addScriptFile('open_html_helper.js', 'horde', array('direct' => false));
+            Horde::addScriptFile('open_html_helper.js', 'horde');
             $imgId = $var->getVarName() . 'ehelper';
             if ($var->type->hasHelper('emoticons')) {
-                $html .= Horde::link('#', _("Emoticons"), '', '', 'openHtmlHelper(\'emoticons\', \'' . $var->getVarName() . '\'); return false;')
+                $filter = $GLOBALS['injector']->getInstance('Horde_Text_Filter')->getFilter('emoticons');
+                $icon_list = array();
+
+                foreach (array_flip($filter->getIcons()) as $icon => $string) {
+                    $icon_list[] = array(
+                        $filter->getIcon($icon),
+                        $string
+                    );
+                }
+
+                Horde::addInlineScript(array(
+                    'Horde_Html_Helper.iconlist = ' . Horde_Serialize::serialize($icon_list, Horde_Serialize::JSON, $GLOBALS['registry']->getCharset())
+                ));
+
+                $html .= Horde::link('#', _("Emoticons"), '', '', 'Horde_Html_Helper.open(\'emoticons\', \'' . $var->getVarName() . '\'); return false;')
                     . Horde::img('emoticons/smile.png', _("Emoticons"), 'id="' . $imgId . '" align="middle"')
                     . '</a>'."\n";
             }
index ccda7a6..f77e758 100644 (file)
@@ -120,7 +120,7 @@ class Horde_Text_Filter_Emoticons extends Horde_Text_Filter_Base
      */
     public function emoticonReplace($matches)
     {
-        return $matches[1] . $this->_emoticonReplace($matches[2]) . (empty($matches[3]) ? '' : $matches[3]);
+        return $matches[1] . $this->getIcon($matches[2]) . (empty($matches[3]) ? '' : $matches[3]);
     }
 
     /**
@@ -130,7 +130,7 @@ class Horde_Text_Filter_Emoticons extends Horde_Text_Filter_Base
      *
      * @return string  The replacement text.
      */
-    protected function _emoticonReplace($icon)
+    public function getIcon($icon)
     {
         return $icon;
     }
diff --git a/horde/js/open_html_helper.js b/horde/js/open_html_helper.js
new file mode 100644 (file)
index 0000000..c483581
--- /dev/null
@@ -0,0 +1,66 @@
+/**
+ * Horde Html Helper Javascript Class
+ *
+ * Provides the javascript class insert html tags by clicking on icons.
+ *
+ * The helpers available:
+ *      emoticons - for inserting emoticons strings
+ *
+ * Copyright 2003-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author Marko Djukic <marko@oblo.com>
+ * @package Horde
+ * @todo Add handling for font tags, tables, etc.
+ */
+
+var Horde_Html_Helper = {
+
+    iconlist: [],
+    targetElement: null,
+
+    open: function(type, target)
+    {
+        var cell, row, table, tbody,
+            lay = $('htmlhelper_' + target);
+        this.targetElement = $(target);
+
+        if (lay.getStyle('display') == 'block') {
+            lay.hide();
+            return false;
+        }
+
+        if (lay.firstChild) {
+            lay.removeChild(lay.firstChild);
+        }
+
+        tbody = new Element('TBODY');
+        table = new Element('TABLE', { border: 0, cellSpacing: 0 }).insert(tbody);
+
+        if (type == 'emoticons') {
+            row = new Element('TR');
+            cell = new Element('TD');
+
+            iconlist.each(function(i) {
+                var link =
+                    new Element('A', { href: '#' }).insert(
+                        new Element('IMG', { align: 'middle', border: 0, src: i[0] })
+                    );
+                cell.appendChild(link);
+
+                link.observe('click', function(e) {
+                    this.targetElement.setValue($F(this.targetElement) + i[1] + ' ');
+                    e.stop();
+                }.bindAsEventListener(this));
+            });
+
+            row.insert(cell);
+            tbody.insert(row);
+            table.insert(tbody);
+        }
+
+        lay.insert(table).setStyle({ display: 'block' });
+    }
+};
diff --git a/horde/templates/javascript/open_html_helper.js b/horde/templates/javascript/open_html_helper.js
deleted file mode 100644 (file)
index eb3d5d1..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Horde Html Helper Javascript Class
- *
- * Provides the javascript class insert html tags by clicking on icons.
- *
- * The helpers available:
- *      emoticons - for inserting emoticons strings
- *
- * Copyright 2003-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Marko Djukic <marko@oblo.com>
- * @package Horde
- * @todo Add handling for font tags, tables, etc.
- */
-
-var targetElement;
-
-function openHtmlHelper(type, target)
-{
-    var lay = document.getElementById('htmlhelper_' + target);
-    targetElement = document.getElementById(target);
-
-    if (lay.style.display == 'block') {
-        lay.style.display = 'none';
-        return false;
-    }
-
-    if (lay.firstChild) {
-        lay.removeChild(lay.firstChild);
-    }
-
-    var table = document.createElement('TABLE');
-    var tbody = document.createElement('TBODY');
-    table.appendChild(tbody);
-    table.cellSpacing = 0;
-    table.border = 0;
-
-    if (type == 'emoticons') {
-        row = document.createElement('TR');
-        cell = document.createElement('TD');
-        <?php $filter = $GLOBALS['injector']->getInstance('Horde_Text_Filter')->getFilter('emoticons'); $icons = array_flip($filter->getIcons()); foreach ($icons as $icon => $string): ?>
-        link = document.createElement('A');
-        link.href = '#';
-        link.onclick = function() {
-            targetElement.value = targetElement.value + '<?php echo $string ?>' + ' ';
-            return false;
-        }
-        cell.appendChild(link);
-        img = document.createElement('IMG')
-        img.src = '<?php echo Horde_Themes::img('emoticons/' . $icon . '.png') ?>';
-        img.align = 'middle';
-        img.border = 0;
-        link.appendChild(img);
-        <?php endforeach; ?>
-        row.appendChild(cell);
-        tbody.appendChild(row);
-        table.appendChild(tbody);
-    }
-
-    lay.appendChild(table);
-    lay.style.display = 'block';
-}