Hello,
I have a plugin which links to internal pages.
dialogplugin.js
CKEDITOR.dialog.add('newplugin', function(editor) { CKEDITOR.skins.load(editor, 'newplugin'); var selectedItem = ""; var selectedType = "link"; var selectedText = ""; var target = "_self"; var firstTime = true; var url = window.location.toString(); var urlparts = url.split('/'); var host = urlparts[2]; var baseUrl = "http://" + host + "/"; var items = new Array(); $.getJSON('/page/jsonpages', function(data) { $.each(data.pages, function(key, val) { items.push(val.name); getAllChilds(val); }); }); function getAllChilds(elem){ var chlds = elem.childs; for(var i =0; i < chlds.length; i++){ items.push("---" + chlds[i].name); if(chlds[i].childs.length > 0) getAllChilds(chlds[i]); } } function getSelectedText() { var selected_text = ''; if (CKEDITOR.env.ie) { editor.getSelection().unlock(true); //selected_text = editor.getSelection().getNative().createRange().text; //GIVES WEIRD ERROR WHEN SOME SELECTED TEXT IS INCOMPLETE selected_text = editor.getSelection().getSelectedText(); //GIVES WEIRD ERROR WHEN SOME SELECTED TEXT IS INCOMPLETE } else { selected_text = editor.getSelection().getNative(); } if(selected_text == ""){ alert('Het is beter dat u eerst text selecteerd voordat u deze functie aanroept.'); } else { //alert(selected_text); } return selected_text; } var newAnchor = ""; return { title: 'Link naar eigen pagina', minWidth: CKEDITOR.env.ie ? 450 : 420, minHeight: 100, onOk: function(){ newAnchor = ""; //EMPTY NEW LINK (ANCHOR) var newUrl = baseUrl; /*if(selectedType == "link") { newUrl += "/"; }*/ newUrl += selectedItem.replace("---",""); newAnchor = "<a href='" + newUrl + "' target='" + target + "'>" + selectedText + "</a>"; document.body.focus(); editor.insertHtml(newAnchor); }, contents: [ { id: 'dialog_plugin', label: '', title: '', expand: true, padding: 0, elements: [ { type: 'hbox', widths: ['400px', '200px'], children: [ { type: 'vbox', children: [ { type: 'select', id: 'selector1', onAvailable:function(){ if(firstTime){ for(var i = 0; i<items.length; i++) { this.add(items[i], items[i].replace(" ","-")); } firstTime = false; } }, onShow: function(){ selectedText = getSelectedText(); if (firstTime) { for(var i = 0; i<items.length; i++) { this.add(items[i], items[i].replace(" ","-")); } firstTime = false; } }, label: 'Kies een pagina', items:[ ['<none>', ''] ], onChange: function(api){ selectedItem = this.getValue().toString(); selectedType = "link"; } }, { type: 'html', html: 'Doel: ' } ] } ] } ] }] }; });
plugin.js
(function() { CKEDITOR.plugins.add('newplugin', { init: function(editor) { editor.addCommand('newplugin', new CKEDITOR.dialogCommand('newplugin')); editor.ui.addButton('newplugin', { label: 'Link naar interne pagina', icon: this.path + 'newplugin.png', command: 'newplugin' }); CKEDITOR.dialog.add('newplugin', this.path + 'dialogs/dialogplugin.js'); } }); })();
We have multi editable Div (which converts to an Iframe) on the page.
Sometimes we select text but it returns an incorrect text
Example company is selected in text company, this is, but ompany, t is returned.
Also the link is inserted at the beginning of the text, where as FireFox / Chrome inserts it on the correct place.
Editor is version 3.6.6 (version:'3.6.6',revision:'7689')