I'm using ckeditor with ASP.NET and wondering how I can add a link to page feature in the link dialog box? I've seen a few tutorials that focus on php but i cannot figure out how to get it to work with asp.net.
Tue, 10/02/2012 - 23:31
#1
Re: How can I add a Link to Page feature in the link dialog
even.. i was trying hard to implement. i have created a custom dialog , wrote a method to fetch data from server but only facing problem to assign the values as select items....
ShowFolderFileList();
CKEDITOR.plugins.add('simpleLink',
{
init: function (editor) {
editor.addCommand('simpleLinkDialog', new CKEDITOR.dialogCommand('simpleLinkDialog'));
editor.ui.addButton('SimpleLink',
{
label: 'Custom Link',
command: 'simpleLinkDialog',
icon: this.path + 'images/icon.png'
});
CKEDITOR.dialog.add('simpleLinkDialog', function (editor) {
return {
title: 'Custom Link : CKFinder',
minWidth: 400,
minHeight: 200,
contents:
[
{
id: 'general',
label: 'Settings',
elements:
[
{
type: 'html',
html: 'Please add your custom text and link.'
},
{
type: 'select',
id: 'documents',
label: 'Select Document',
validate: CKEDITOR.dialog.validate.notEmpty('Please select a file.'),
items:
[
fileNames
], // expecting ARRAY....
required: true,
commit: function (data) {
data.contents = this.getValue();
}
},
{
type: 'text',
id: 'url',
label: 'URL',
validate: CKEDITOR.dialog.validate.notEmpty('The link must have a URL.'),
required: true,
commit: function (data) {
data.url = this.getValue();
}
},
{
type: 'checkbox',
id: 'newPage',
label: 'Opens in a new page',
'default': true,
commit: function (data) {
data.newPage = this.getValue();
}
}
]
}
],
onOk: function () {
var dialog = this,
data = {},
link = editor.document.createElement('a');
this.commitContent(data);
link.setAttribute('href', data.url);
if (data.newPage)
link.setAttribute('target', '_blank');
link.setHtml(data.contents);
editor.insertElement(link);
}
};
});
}
});
function ShowFolderFileList() {
var xmlHttp;
var lstArray = new Array();
//Let us create the XML http object
xmlHttp = null;
if (window.XMLHttpRequest) {
//for new browsers
xmlHttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
//for old ones
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp != null) {
//Handle the response of this async request we just made(subscribe to callback)
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
//loaded
if (xmlHttp.status == 200) {
//request was successful. so Retrieve the values in the response.
var pages = xmlHttp.responseText.split(';');
var dataCount = pages.length;
for (var i = 0; i < dataCount; ++i) {
lstArray[i] = '[' + pages[i] + ']';
}
//return loadCKEditorPlugin(lstArray);
}
}
}
//Pass the value to a web page on server as query string using XMLHttpObject.
xmlHttp.open("GET", "/ckeditor/plugins/simpleLink/pages.aspx", true);
xmlHttp.send(null);
}
}
Re: How can I add a Link to Page feature in the link dialog
Figured out a way to do it...
Check out this thread here http://cksource.com/forums/viewtopic.php?f=18&t=24282
Follow his basic instructions by coping the internalpage folder into plugins folder.
Remove the pages.php file and create your own pages.aspx page.
Response.Write to your page a string in this format (no html):
Update his plugin.js file and replace the pages.php with pages.aspx.
Open the config.js file in ckeditor add this to the CKEDITOR.editorConfig function:
config.extraPlugins = 'internpage';
For example:
CKEDITOR.editorConfig = function( config )
{
config.extraPlugins = 'internpage';
};
All done.