2012-12-06 217 views
9

我想在Joomla的文章编辑器中插入一个额外的按钮。它使用扩展模式下的默认TinyMCE插头。正如你已经知道编辑器下有4个按钮(文章,图像,分页符和阅读更多)。我想要做的是插入第五个按钮。 (我确实附加了一个图像按钮,所以我不能发布至少需要10个重复点)。将自定义按钮添加到Joomla的文章编辑器(TinyMCE)

我试着复制了分页按钮插件并重命名等,然后重新安装它作为一个新的插件,但所有这些都会导致TinyMCE出错,并且不会出现任何按钮。

问题:如何插入按钮?

+0

你能发布你的代码吗?我把它插入安装,并在正确的地方,并启​​用。 – Elin

+0

嗨艾琳,我认为发布的代码,但它不会帮助,因为它是默认的Joomla安装附带的'分页符'按钮已经可用的代码。该插件已启用,并处于与其他editor-xtd插件相同的位置。 –

+0

如果它完全是一个副本,那么很可能无法更改某个名称必须与xml中的某个内容匹配的地方。 – Elin

回答

7

我继续我的广泛搜索,并找到了向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; 
    } 
} 
?> 

感谢大家的帮助。如果你有其他更好的方法,我会非常感激。

+1

幸好你把代码放在这里,因为教程链接现在不工作。 –

4

如果成功安装插件,那么你必须把你的插件名称进入高级参数设置的 Custom pluginCustom buttontinymce plugins.And确保您已安装的插件是published.See低于例如图像。

这是设置enabled.see这个图片我的自定义插件: enter image description here

然后在tinymce插件去先进的参数,并在最后看看到底有自定义字段option.see这一形象:

enter image description here

输入插件名称和按钮name.And在文章管理器编辑器找到您的按钮。

+1

只有当你想添加一个tinymce按钮时,如果你想添加一个按钮,下面是一个编辑器 - xtd插件。 – Elin

+0

感谢龙卷风。这是添加一个自定义图标按钮到工具栏的理想选择,但我希望有一个更大的“阅读更多”按钮。感谢您使用图形,它非常有帮助! +1使用图像。 –

相关问题