After ploughing through this forum for days on end, I have finally come up with this simple yet effective method on how to link to internal cms pages using the Links Dialogue.
This method adds a button in the Links dialogue which when clicked, will open a window listing all your available cms pages as links. When a cms page link is clicked, the URL field of the Links dialogue is populated with its URL. It will also change the link protocol to Other.
First we bring a clean plugin file to work with.
copy this File:
ckeditor\_source\plugins\link\dialogs\link.js
into this Folder:
ckeditor\plugins\link\dialogs
overwriting the existing File.
Now we need to add a button to the Links dialogue.
From the ckeditor\plugins\link\dialogs\link.js file, locate this block of code (it should be around about line 510):
and replace it with this:
Note 1: I hard coded the label on the existing browse button as I thought it makes more sense. You can keep the old name if you like.
Note 2: This is the label for the button that opens the CMS Links popup.
Note 3: This is the URL to your Internal Links file relative to the ckeditor\ckeditor.js file.
Internal Links File Setup
This is a very simplified version of how my intLinks.asp page is parsed into html.
It should be pretty easy to follow.
Of course, you can use any language you want for the internal links page as long as the javascript follows what's going on in mine.
I hope someone finds this tutorial useful.
-Nico
This method adds a button in the Links dialogue which when clicked, will open a window listing all your available cms pages as links. When a cms page link is clicked, the URL field of the Links dialogue is populated with its URL. It will also change the link protocol to Other.
First we bring a clean plugin file to work with.
copy this File:
ckeditor\_source\plugins\link\dialogs\link.js
into this Folder:
ckeditor\plugins\link\dialogs
overwriting the existing File.
Now we need to add a button to the Links dialogue.
From the ckeditor\plugins\link\dialogs\link.js file, locate this block of code (it should be around about line 510):
{ type : 'button', id : 'browse', hidden : 'true', filebrowser : 'info:url', label : editor.lang.common.browseServer }
and replace it with this:
{ type : 'hbox', widths : [ '50%', '50%' ], children : [ { type : 'button', id : 'browse', hidden : 'true', filebrowser : 'info:url', label : 'Link to File on Server' // See Note 1 }, { type : 'button', id : 'browseInternal', label : 'Link to WmsCms Page', // See Note 2 filebrowser : { action : 'Browse', url : '../cmsAdmin/intLinks.asp' // See Note 3 } } ] }
Note 1: I hard coded the label on the existing browse button as I thought it makes more sense. You can keep the old name if you like.
Note 2: This is the label for the button that opens the CMS Links popup.
Note 3: This is the URL to your Internal Links file relative to the ckeditor\ckeditor.js file.
Internal Links File Setup
This is a very simplified version of how my intLinks.asp page is parsed into html.
It should be pretty easy to follow.
<html>
<head>
<title>Link to CMS Page</title>
<script language="JavaScript">
<!--
function AddLink(txtLink)
{
var dialog = window.opener.CKEDITOR.dialog.getCurrent();
dialog.setValueOf('info','url',txtLink); // Populates the URL field in the Links dialogue.
dialog.setValueOf('info','protocol',''); // This sets the Link's Protocol to Other which loads the file from the same folder the link is on
window.close(); // closes the popup window
}
-->
</script>
</head>
<body>
<h3>Internal Links</h3>
<p>
<a href="JavaScript:AddLink('default.asp?pid=1')">HOME</a><br>
<a href="JavaScript:AddLink('default.asp?pid=2')">ABOUT US</a><br>
<a href="JavaScript:AddLink('default.asp?pid=3')">PRODUCTS</a><br>
<a href="JavaScript:AddLink('default.asp?pid=4')">SERVICES</a>
</p>
</body>
</html>
Of course, you can use any language you want for the internal links page as long as the javascript follows what's going on in mine.
I hope someone finds this tutorial useful.
-Nico
Re: Tutorial on how to modify Links Plugin to link to cms pa
my solution JS on popup page - using jQuery on UL LI A tree...
thx nico/wmbiz
Works great in IE but not in Chrome
Thanks
John
Re: Tutorial on how to modify Links Plugin to link to cms pa
now i'm guessing how to add on dialog link menú one combobox filled by serverside script via ajax.
Something like this in line 400, where it's possible to add a combobox:
{
type: 'select',
id: 'internalOptions',
label: 'Internal links',
items:
[
/** here i don't know how to load the links options via AJAX
],
setup : function( data )
{
/** i supose that here i could load the serverside script, but i don't
know how to add to options select tag.
},
Re: Tutorial on how to modify Links Plugin to link to cms pa
I've added a combobox in the dialog window and attach a onload event that adds the options tags to the combobox.
Something like this in line 400
{
type: 'select',
id: 'internalOptions',
label: 'Internal options',
onLoad: function ( data )
{
e = this.getInputElement().$;
$(e).load(editor.config.internal_links_url);
//where editor.config.internal_links_url is a serverside script that returns a collection of <option>tag.
},
commit : function( data )
{
if ( !data.url )
data.url = {};
data.url.protocol = this.getValue();
}
}
Re: Tutorial on how to modify Links Plugin to link to cms pa
Nice tutorial!
One question: How do I configure the width and height of the popup window?
Re: Tutorial on how to modify Links Plugin to link to cms pa
Thanks in advance!
Re: Tutorial on how to modify Links Plugin to link to cms pa
nice work 2 questions :
- how can I change popup size ?
- I would like to automatically close the URL dialog window after clicking on a CMS url
thanks
Re: Tutorial on how to modify Links Plugin to link to cms pa
Thanks in advace
Re: Tutorial on how to modify Links Plugin to link to cms pa
This was a nice article and so helpful
I just want to warn those who are using old versions (prior to 3.6), that this might not work well
I spend almost 4-5 hours and ended up installing the newer version and it worked in a swift
Thanks again
Regards
Rajesh
Re: Tutorial on how to modify Links Plugin to link to cms pa
Thank you very much for the great post. I just registered here, just to thank you!!
btw: To insert notes url just extend in link.js following part:
Re: Tutorial on how to modify Links Plugin to link to cms pa
Thank you - You have made my day
I have been searching for this for months and months.
Any chance I could define a different location of the link.js file?
In ASP eg.:
oEditor.instanceConfig("link-dialog-definition") = "/somefolder/link.js"
... or some similar solution?
When upgrading ckeditor this would be nice!
customizing url
how can i customize [internal_link%20id=237] to slug of the page
Problems with Inline links
I've got the above to work with no problems [thanks wmbiz] in the standard editor. However since replacing the plugins\link\dialogs\link.js file and making the changes. I'm having issues with creating links using the inline editing. It appears as if the highlighted text becomes unselected. Has anyone else experienced a similar issue or know how I can resolve this rather frustrating problem. Many, many thanks.
Dynamic solution
This works great when I modify links.js, any ideas on how to get it working dynamically ?
I am using on dialogDefinition to add a page filebrowser button just as in first post, but no events are binded to the button.
Anyone know how to initialize this dynamically, without having to modifying the link source ? Perhaps the buttons events are only hooked up when the dialog in initialized, is there a way to modify the dialog and re-init it or setup ?
Dynamic solution bugged
Before anyone wastes their time trying that like I did.
see this ancient bug that was never fixed http://dev.ckeditor.com/ticket/8466
Doesn't work in the newest
Doesn't work in the newest Version 4.4.4.
Is there a solution for this version?
Here's what I did to
Here's what I did to implement this sort of feature recently (version 4.4.2, because that’s the one used in the ckeditor gem):
https://github.com/die-antwort/ckeditor/commit/92c81c7eb1ce65584e8bf9c3b8571358d26d17fe
It's of course tailored for our specific needs, but it should be quite easy to adapt.