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

ᴍᴀᴛ*_*ᴋᴇʀ 11 php tinymce joomla-extensions joomla2.5 joomla3.0

我正在尝试在Joomla的文章编辑器中插入一个额外的按钮.它在扩展模式下使用默认的TinyMCE插件.您已经知道编辑器下面有4个按钮(文章,图像,分页和阅读更多).我想做的是插入第5个按钮.(我确实附上了一个图像按钮,所以说我不能发帖,至少需要10个重复点.)

我曾尝试复制分页按钮插件并重命名等,然后将其重新安装为新插件,但所有这一切都会导致TinyMCE出错并且不会出现任何按钮.

问题:如何插入按钮?

ᴍᴀᴛ*_*ᴋᴇʀ 9

我继续进行广泛的搜索,并找到了为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>
Run Code Online (Sandbox Code Playgroud)

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;
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

感谢大家的帮助.如果您有任何其他更好的方法,我将非常感激.

  • 值得庆幸的是,您将代码放在此处,因为教程链接目前无法正常工作。 (3认同)