From: Michael M Slusarz Date: Tue, 27 Jul 2010 21:28:31 +0000 (-0600) Subject: No PHP code in open_html_helper.js script X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=04cf8e0124b317ce4ffc361ee50a8ad17a06f9e6;p=horde.git No PHP code in open_html_helper.js script --- diff --git a/framework/Core/lib/Horde/Core/Text/Filter/Emoticons.php b/framework/Core/lib/Horde/Core/Text/Filter/Emoticons.php index 1f03e5a73..c3694c98c 100644 --- a/framework/Core/lib/Horde/Core/Text/Filter/Emoticons.php +++ b/framework/Core/lib/Horde/Core/Text/Filter/Emoticons.php @@ -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)); } diff --git a/framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php b/framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php index 4552635a0..0ef8c30ec 100644 --- a/framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php +++ b/framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php @@ -293,10 +293,26 @@ class Horde_Core_Ui_VarRenderer_Html extends Horde_Core_Ui_VarRenderer if ($var->type->hasHelper() && $browser->hasFeature('javascript')) { $html .= '
'; - 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 . '"') . ''; + $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 . '"') . ''; } $html .= '
_genID('htmlhelper_' . $var->getVarName()) . ' class="control">
' . "\n"; } diff --git a/framework/Model/lib/Horde/Form/VarRenderer/Xhtml.php b/framework/Model/lib/Horde/Form/VarRenderer/Xhtml.php index c97a9a62c..9db8f9252 100644 --- a/framework/Model/lib/Horde/Form/VarRenderer/Xhtml.php +++ b/framework/Model/lib/Horde/Form/VarRenderer/Xhtml.php @@ -161,10 +161,24 @@ class Horde_Form_VarRenderer_Xhtml extends Horde_Form_VarRenderer if ($var->type->hasHelper() && $browser->hasFeature('javascript')) { $html .= '
'; - 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"') . ''."\n"; } diff --git a/framework/Text_Filter/lib/Horde/Text/Filter/Emoticons.php b/framework/Text_Filter/lib/Horde/Text/Filter/Emoticons.php index ccda7a6bf..f77e75818 100644 --- a/framework/Text_Filter/lib/Horde/Text/Filter/Emoticons.php +++ b/framework/Text_Filter/lib/Horde/Text/Filter/Emoticons.php @@ -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 index 000000000..c4835811f --- /dev/null +++ b/horde/js/open_html_helper.js @@ -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 + * @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 index eb3d5d185..000000000 --- a/horde/templates/javascript/open_html_helper.js +++ /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 - * @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'); - 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 + '' + ' '; - return false; - } - cell.appendChild(link); - img = document.createElement('IMG') - img.src = ''; - img.align = 'middle'; - img.border = 0; - link.appendChild(img); - - row.appendChild(cell); - tbody.appendChild(row); - table.appendChild(tbody); - } - - lay.appendChild(table); - lay.style.display = 'block'; -}