简体   繁体   English

将自定义按钮添加到Joomla的文章编辑器(TinyMCE)

[英]Add Custom Button to Joomla's Article Editor (TinyMCE)

I'm trying to insert an additional button in Joomla's article editor. 我正在尝试在Joomla的文章编辑器中插入一个额外的按钮。 It's using the default TinyMCE plug in Extended mode. 它在扩展模式下使用默认的TinyMCE插件。 As you'll already know there are 4 buttons underneath the editor (Article, Image, Page Break and Read More). 您已经知道编辑器下面有4个按钮(文章,图像,分页和阅读更多)。 What I'd like to do is insert a 5th button. 我想做的是插入第5个按钮。 (I did attach a image button SO said I can't post as need a minimum of 10 rep points.) (我确实附上了一个图像按钮,所以说我不能发帖,至少需要10个重复点。)

I have tried copying the Page Break Button plugin and renaming it etc, then re-installing it as a new plugin, but all that does it cause errors with TinyMCE and no button appears. 我曾尝试复制分页按钮插件并重命名等,然后将其重新安装为新插件,但所有这一切都会导致TinyMCE出错,并且不会出现任何按钮。

Question : How do I insert the button? 问题 :如何插入按钮?

I've continued my extensive search and have found a guide on adding an additional button to the Article Editor for Joomla 1.5. 我继续进行广泛的搜索,并找到了一个关于为Joomla 1.5的文章编辑器添加额外按钮的指南。

The tutorial is available at: http://tushev.org/articles/programming/18-how-to-create-an-editor-button-editors-xtd-plugin-for-joomla . 该教程可从以下网址获得: http//tushev.org/articles/programming/18-how-to-create-an-editor-button-editors-xtd-plugin-for-joomla

Straight out of the box this won't work with Joomla 2.5 and Joomla 3.0 as the XML manifest standards have changed ever-so-slightly. 开箱即用,这对于Joomla 2.5和Joomla 3.0无效,因为XML清单标准已经发生了如此微小的变化。 Keeping in line with the tutorial use this XML manifest instead. 与教程保持一致使用此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>

The tutorial PHP is correct and is as follows: 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;
    }
}
?>

Thank you all for your help. 感谢大家的帮助。 If you have any other better methods I'd be most grateful. 如果您有任何其他更好的方法,我将非常感激。

If your plugin installed successfully,then you have to put your plugin name into the Custom plugin and Custom button in the advanced parameters setting in tinymce plugins.And make sure your installed plugins is published.See the image below for example. 如果您的插件安装成功,那么您必须将您的插件名称放入tinymce Custom plugin的高级参数设置中的Custom pluginCustom button 。并确保已发布已安装的插件。例如,请参见下图。

This is my custom plugin which is set enabled.see this image : 这是我的自定义插件已设置为启用。请看这个图片: 在此输入图像描述

And then in the tinymce plugin go to advanced parameter and see at very last end there is the custom fields option.see this image: 然后在tinymce插件中转到高级参数,最后看到有自定义字段选项。请看这个图像:

在此输入图像描述

Enter the plugins name and button name.And locate your button in the article manager editor. 输入插件名称和按钮名称。在文章管理器编辑器中找到您的按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM