Monday, April 11, 2016

Is there a way to add button to link plugin of CKEditor on the run?

Leave a Comment

There are ways to add function to the toolbar for CKEditor on the run. For example,

http://stackoverflow.com/a/25443349/1273587

How to add a custom button to the toolbar that calls a JavaScript function?

And there are ways to add new choice to existing link plugin of CKEditor

https://ssdtutorials.com/courses/ckeditor-internal-page-link

http://blog.xoundboy.com/?p=393

Is there a way to add button to existing link plugin on the run? I have a button to add to the link plugin that depends on user data and therefore the button must be added on the run.

1 Answers

Answers 1

I have used the internpage plugin and changed the source to support dynamically changing the list of links that appears. In the code at the link above you see they define a setup function, which is called every time the dialog is opened and the select shown:

setup : function (f) {     this.allowOnChange = false;     this.setValue(f.url ? f.url.url : '');     this.allowOnChange = true; } 

All you need to do is change or refresh the list of items in the select using the available methods:

  • this.clear() - removes all items in the select
  • this.remove(index) - removes an item in the select
  • this.add(text,url) - adds an item in the select
  • this.getElement() - gets the actual select element

Note that this.items remains unchanged when using these methods so you can use that property to automatically refresh the select.

Here is a working demo: https://jsfiddle.net/ud4csxyc/

Press the red button a few times and you will see the list of items is changed.

I hope it's what you wanted.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment