[HOW-TO - vB4] Create a Custom Button for CK Editor (no file edits)
This article explains how to add or remove buttons from CKEditor by using Ckeditor and vBulletin plugins. No standard file edits needed.
To add a button to CKEditor, you need to create a CKE plugin. This is an example code for such a plugin. It will add "Hello World" to the editor and spawn a JS alert. Important note: This article is on the technique of adding a button, not on how you will get your button to do whatever it is you want it to do. There are plenty sites out there that give support for CKEditor plugins. The CKE API documentation can be found here. First step: Create the CKEditor plugin The editor plugin files reside in the folder [forumroot]/clientscript/ckeplugins. Create a new folder in there. For the purpose of this article, I'll name it celButtonDemo. Inside that folder, create a file called plugin.js. So you end up with this: [forumroot]/clientscript/ckeplugins/celButtonDemo/plugin.js Important note: Please take notice that "celButtonDemo" will have to be replaced in the folder name and in the following code examples accordingly!. Inside plugin.js goes the plugin code: Code:
CKEDITOR.plugins.add( 'celButtonDemo', Second step: vB Operations - register your button, add it to the toolbar, and more In a second step we will create two vB plugins and a vB phrase. You should bundle all that together to a product, to have it all nicely together. Let's start with the phrase: Go to AdminCP, create a phrase in the CKEditor phrase group, and name it CelButtonDemo. Enter "Hello World, hello Button" - or whatever. Save. Done. Then create a new plugin at hook "editor_construct". This will add our button to the CKE configuration. PHP Code:
In this example, our button will be inserted after the Quote-Button. Your options to place the button can be found in /vb/ckeditor.php. See line 7 in the following code: PHP Code:
Result (Screencast): http://screencast-o-matic.com/watch/clnqDcazQ Removing buttons The technique used above to add the button can also be used to remove a button. Example: Removing the image button would look like that (hook "editor_toolbar_filter") PHP Code:
PHP Code:
Restricting buttons by editor-mode or usergroup You have everything available to you in the vB-universe to restrict access to your button, just extend the if-condition. You can restrict by usergroup, or you can show a button only in a certain editor The editor mode can be queried via $this->editor_type in plugins at editor_toolbar_filter: fe = full qr = quick reply qe = quick edit cms_article Example: PHP Code:
Have fun! cellarius . . |
A lot of people will find this helpful. :up:
Great article! |
Nice! Thanks for taking the time to write this all out. :)
|
Thought I'd save everyone else some time and effort. :)
|
Thanks Cellarius for the neat writeup!
|
this is real nice coding...thanks a lot :)
|
Hi all, i don't know if this is the correct place, but i want to ask here.... This hack is super, but i have only need to add the "code" (standard vbulletin bbcode) in my QR - QE.
I have addedd in my qe and qr my custom bbcode (like spoiler for example) just adding this plugin via vbulletin ACP Code:
if ($this->editor_type == 'qr' || $this->editor_type == 'qe') |
Quote:
|
Yes i did.... but please lynne, can u check my last post if mine it is a correct solution? Thanks
|
Great article, and I was able to accomplish what I wanted to accomplish for a single button. However, what if I wanted to add 3-4 buttons? Do I need to create unique JS files and plug-in's for each?
|
Yes.
|
Thanks. Got it working great.
|
Quote:
Code:
https://vborg.vbsupport.ru/showthread.php?t=282328 |
Quote:
|
Back again -- I can't get this permissions piece of the code to work:
Code:
if (is_array($row) AND is_member_of($vbulletin->userinfo['usergroupid'], 5, 6, 7) AND $this->editor_type == 'qr' ) |
thanks, this is very useful.
Is there any way to use {vb:raw vboptions.xxx} in plugin.js ? |
Lets say i already have a bbcode, for example the [ hide ] for the dbtech post thanks mod.
How would i add it in this example? |
PHP Code:
|
Unfortunately, no support here more or?????
|
I can't seem to get this to work ... did something change between 4.2 and 4.2.1?
|
Hello!
Great Plugin! I want to just attach a link to my file that opens in new window. Would someone possiblly help me with that one? Thanks a lot! |
No idea what you want to do, but this article is not about attaching anything to a file, but adding a button to the editor. Please open your own thread in the appropriate forums.
|
Quote:
I want to make the button link to a file in a new window. I have no idea about php and I am new to the vbulletin as well, thats why I am a bit disoriented, sorry about that. I think that what I want is simple, but I do not how to do it :( |
OK. As I wrote in the article, this is not normally the place to ask for things that you want the button to do - this is for the addition of the button, not more.
Anyway: This has nothing to do with PHP - all of this is Javascript. And to open a page in a new window, you would add something like Code:
window.open("http://www.your-page.com/goes/here.html"); Code:
exec: function(editor){ |
Thanks a lot!
|
How to move custom button to End Toolbar
|
By inserting it after the last button using the method described in the article.
|
vbb 4.2.3 not work. member can't click button... but admin can
|
And? The article describes how you can restrict the button per usergroup. If you don't want that, don't implement it.
|
i use code
Code:
foreach ($toolbar AS &$row) |
Quote:
|
how can I still register the bbcode.
if I investing here, I see no more toolbar PHP Code:
|
All times are GMT. The time now is 02:14 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|