【问题标题】:Add Custom Button to Joomla's Article Editor (TinyMCE)将自定义按钮添加到 Joomla 的文章编辑器 (TinyMCE)
【发布时间】:2012-11-24 11:29:29
【问题描述】:

我正在尝试在 Joomla 的文章编辑器中插入一个额外的按钮。它在扩展模式下使用默认的 TinyMCE 插件。如您所知,编辑器下方有 4 个按钮(文章、图像、分页符和阅读更多)。我想做的是插入第 5 个按钮。 (我确实附上了一个图片按钮,所以说我不能发布,因为需要至少 10 个代表点。)

我尝试复制分页按钮插件并将其重命名等,然后将其重新安装为新插件,但所有这些都会导致 TinyMCE 出现错误并且没有按钮出现。

问题:如何插入按钮?

【问题讨论】:

  • 你能发布你的代码吗?我认为插件已安装并位于正确的位置并已启用。
  • 嗨,Elin,我考虑过发布代码,但这无济于事,因为它是默认 Joomla 安装附带的“分页符”按钮可用的代码。该插件已启用,并且与其他 editor-xtd 插件位于同一位置。
  • 如果它只是一个完整的副本,您很可能无法更改名称必须与 xml 中的某些内容匹配的地方之一。

标签: php tinymce joomla2.5 joomla3.0 joomla-extensions


【解决方案1】:

我继续进行了广泛的搜索,并找到了有关在 Joomla 1.5 的文章编辑器中添加附加按钮的指南。

教程位于:http://tushev.org/articles/programming/18-how-to-create-an-editor-button-editors-xtd-plugin-for-joomla

开箱即用,这不适用于 Joomla 2.5 和 Joomla 3.0,因为 XML 清单标准发生了非常微小的变化。为了与教程保持一致,请改用此 XML 清单。

<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="plugin" method="upgrade" group="editors-xtd">
        <name>test</name>
        <author>Name</author>
        <creationDate>Month 2013</creationDate>
        <copyright>Month Name. All rights reserved.</copyright>
        <license>GPL</license>
        <authorEmail>Email</authorEmail>
        <authorUrl>Your URL</authorUrl>
        <version>1.0.0</version>
        <description>
            "adds the button 'test' to the editor"
        </description>
        <files>
            <filename plugin="test">test.php</filename>
        </files>
</extension>

教程PHP正确,如下:

<?php

 // no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin' );

class plgButtonTest extends JPlugin {

    function plgButtonTest(& $subject, $config)
    {
        parent::__construct($subject, $config);
    }
    function onDisplay($name)
    {
        $js =  "                      
         function buttonTestClick(editor) {
                             txt = prompt('Please enter something','123');
                             if(!txt) return;
                               jInsertEditorText('{test '+txt+'}', editor);
        }";
        $css = ".button2-left .testButton {
                    background: transparent url(/plugins/editors-xtd/test.png) no-repeat 100% 0px;
                }";
        $doc = & JFactory::getDocument();
        $doc->addScriptDeclaration($js);
        $doc->addStyleDeclaration($css);
        $button = new JObject();
        $button->set('modal', false);
        $button->set('onclick', 'buttonTestClick(\''.$name.'\');return false;');
        $button->set('text', JText::_('Test'));
        $button->set('name', 'testButton');
        $button->set('link', '#');
        return $button;
    }
}
?>

感谢大家的帮助。如果您有其他更好的方法,我将不胜感激。

【讨论】:

  • 感谢您将代码放在这里,因为教程链接现在不起作用。
【解决方案2】:

如果您的插件安装成功,那么您必须在tinymce插件的高级参数设置中将您的插件名称放入 Custom pluginCustom button。并确保您安装的插件已发布。见下图例如。

这是我设置为启用的自定义插件。请参阅此图像:

然后在tinymce 插件中转到高级参数并在最后看到自定义字段选项。请参阅此图片:

输入插件名称和按钮名称。然后在文章管理器编辑器中找到您的按钮。

【讨论】:

  • 只有当你想添加一个 tinymce 按钮而不是如果你想在下面添加一个按钮,它将是一个 editor-xtd 插件。
  • 谢谢龙卷风。这是向工具栏添加自定义图标按钮的理想选择,但我希望有一个更大的按钮,例如“阅读更多”按钮。感谢您使用图形,它有很大帮助! +1 使用图片。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-29
  • 2012-02-08
  • 2012-10-20
相关资源
最近更新 更多