如何向工具栏添加调用 JavaScript 函数的自定义按钮?
我想向工具栏添加一个按钮来调用 JavaScript 函数,例如 Tada()
?
关于如何添加这个有什么想法吗?
I'd like to add a button to the toolbar that calls a JavaScript function like Tada()
?
Any ideas on how to add this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
还有一种很好的方法允许人们在不创建插件的情况下添加按钮。
html:
javascript:
在这里查看它是如何工作的:DEMO
Also there is a nice way allowing one to add the button without creating plugin.
html:
javascript:
Check out how it works here: DEMO
我正在为 CKEditor 开发一些自定义插件,这是我的书签生存包:
为了您的目的,我建议您查看
_source/plugins
目录中的插件之一,例如“打印”按钮。添加一个简单的 Javascript 函数非常容易实现。您应该能够复制打印插件(将目录从 _source 放入实际的插件/目录中,稍后再担心缩小问题),重命名它,重命名其中每次提到“打印”的地方,为按钮指定一个稍后使用的正确名称在您的工具栏设置中包含该按钮,并添加您的功能。I am in the process of developing a number of custom Plugins for CKEditor and here's my survival pack of bookmarks:
For your purpose, I would recommend look at one of the plugins in the
_source/plugins
directory, for example the "print" button. Adding a simple Javascript function is quite easy to achieve. You should be able to duplicate the print plugin (take the directory from _source into the actual plugins/ directory, worry about minification later), rename it, rename every mention of "print" within it, give the button a proper name you use later in your toolbar setup to include the button, and add your function.请参阅此 URL 以获取简单示例 http://ajithmanmadhan.wordpress.com/2009/12/16/customizing-ckeditor-and-adding-a-new-toolbar-button/
有几个步骤:
1)创建一个插件文件夹
2) 注册你的插件(上面的 URL 说要编辑 ckeditor.js 文件,不要这样做,因为下次发布新版本时它会中断。而是编辑 config.js 并添加一行,如下所示
3)插件文件夹中名为plugin.js 的JS 文件
这是我的代码
See this URL for a easy example http://ajithmanmadhan.wordpress.com/2009/12/16/customizing-ckeditor-and-adding-a-new-toolbar-button/
There are a couple of steps:
1) create a plugin folder
2) register your plugin (the URL above says to edit the ckeditor.js file DO NOT do this, as it will break next time a new version is relased. Instead edit the config.js and add a line like so
3) make a JS file called plugin.js inside your plugin folder
Here is my code
如果有人感兴趣,我使用 Prototype 编写了一个解决方案。为了使按钮正确显示,我必须在
CKEDITOR.replace()
方法调用中指定extraPlugins: 'ajaxsave'
。这是plugin.js:
In case anybody is interested, I wrote a solution for this using Prototype. In order to get the button to appear correctly, I had to specify
extraPlugins: 'ajaxsave'
from inside theCKEDITOR.replace()
method call.Here is the plugin.js:
CKEditor 4
官方 CKEditor 4 文档中有一些方便的教程,其中介绍了编写一个将内容插入编辑器、注册按钮并显示对话框窗口的插件:
如果您阅读了这两篇文章,请继续阅读 将插件与高级内容过滤器集成。
CKEditor 5
到目前为止,有一篇介绍文章可用:
CKEditor 5 框架:快速入门 - 创建一个简单的插件
CKEditor 4
There are handy tutorials in the official CKEditor 4 documentation, that cover writing a plugin that inserts content into the editor, registers a button and shows a dialog window:
If you read these two, move on to Integrating Plugins with Advanced Content Filter.
CKEditor 5
So far there is one introduction article available:
CKEditor 5 Framework: Quick Start - Creating a simple plugin
您需要创建一个插件。 CKEditor 的文档对此非常缺乏,特别是因为我相信自 FCKEditor 以来它已经发生了很大的变化。我建议复制现有的插件并研究它。快速谷歌搜索“CKEditor插件”还发现此博文。
You'll need to create a plug-in. The documentation for CKEditor is very poor for this, especially since I believe it has changed significantly since FCKEditor. I would suggest copying an existing plug-in and studying it. A quick google for "CKEditor plugin" also found this blog post.
您可以按如下方式添加按钮图像:
此处< /a> 是实际的插件,包含描述的所有步骤。
You can add the button image as follows:
Here is the actual plugin with all steps described.
这篇文章可能也有用 http://mito-team .com/article/2012/collapse-button-for-ckeditor-for-drupal
这里有关于使用自定义按钮构建您自己的 CKEditor 插件的代码示例和分步指南。
This article may be useful too http://mito-team.com/article/2012/collapse-button-for-ckeditor-for-drupal
There are code samples and step-by-step guide about building your own CKEditor plugin with custom button.
如果您自定义了 ckeditor 工具栏,则使用此方法:
由于 stackoverflow 的一些安全问题,jsfiddle 中的工作代码:
http://jsfiddle.net/k2vwqoyp/
If you have customized the ckeditor toolbar then use this method:
Working code in jsfiddle due to some security issue of stackoverflow:
http://jsfiddle.net/k2vwqoyp/
可能有多个插件,但其中一个可能使用 CSS 来创建按钮。首先,单击编辑器中提到的“源”按钮,然后将按钮代码粘贴到那里,因为我使用CSS创建按钮并向其添加href。
这是在其上编写的“打开应用程序”按钮。
您可以更改颜色,因为我正在使用#0080ff(浅蓝色)
There might be Several plugins but one may use CSS for creating button. First of all click on Source button mentioned in Editor then paste the button code over there, As I use CSS to create button and added href to it.
This is the Button Written Open App over It.
You May change the Color as i am using #0080ff (Light Blue)