I've got a dropdown list of various text and values on the same screen at the editor and I'd like to be able to click an option and have it place the value in the editor where the cursor is at that time. Is this possible and if so how?
Thank in advance.
http://www.h2odevelopments.co.uk
Mon, 07/03/2006 - 05:34
#1
RE: Inserting a value from outside
1)FCKEditor can be extended by writing plugins.
2)The FCKEditor API has a function "insertHTML". You can use it in a plugin to insert a text choosen from your list.
3)You could code down something like :
oFCKEditor.insertHTML(document.getElementById('myListId').value)
Hope this helps.
Y.Chaouche
RE: Inserting a value from outside
I can get it to insert text no problem, what I cannot get to work is inserting the text where the cursor is in the editor.
RE: Inserting a value from outside
Sorry, i cannot help you on this. I never had to do something similar... Maybe somebody else has the answer !
Y.Chaouche
RE: Inserting a value from outside
I've managed to get it to work now so if anyone is interested let me know and I'll post it here or should something like this go elsewhere
RE: Inserting a value from outside
Hi !
.
I'm, and surely others are too, interrested
Y.Chaouche
RE: Inserting a value from outside
1 - In the page where your editor is you'll need some javascript can be included in your page or an external file:
function selectObject(myValue,myField) {
var oEditor = FCKeditorAPI.GetInstance(myField) ;
var myObj=oEditor.EditorDocument;
var myText="###FAILED###";
if (myObj.selection) {
myObj.focus();
sel = myObj.selection.createRange();
sel.text = myValue;
} else if (myObj.selectionStart || myObj.selectionStart == '0') {
var startPos = myObj.selectionStart;
var endPos = myObj.selectionEnd;
myText = myText.substring(0, startPos) + myValue+ myText.substring(endPos, myText.length);
} else {
myText += myValue;
}
}
2 - Create your dropdown and populate with whatever your wish, even from a database like this information is, but for now I've just hardcoded it here for speed (ID can be anything).
<select id="objects" size="10" onclick="selectObject(this.value,'INSTANCE NAME OF YOUR FCKEDITOR');">
<option value="###CASE_STUDY_LIST###">###CASE_STUDY_LIST###</option>
<option value="###CASE_STUDY_ID(*)###">###CASE_STUDY_ID(?)###</option>
<option value="###NEWS_LIST###">###NEWS_LIST###</option>
<option value="###NEWS_ID(?)###">###NEWS_ID(?)###</option>
</select>
Please feel free to modify as you wish I've just done this to get it working for me. Any problems and I'll do my best to help.
RE: Inserting a value from outside
If i have it right, it seems that the EditorDocument object has a special attribute selection, which can give informations about the selected text.
There's just one question i have about this piece of code :
<code>
if (myObj.selectionStart || myObj.selectionStart == '0')
</code>
if myObj.selectionStart != Null, then the || MyObj.selectionStart == '0' is never executed since the or is lazy.
else : MyObj.selectionStart == Null, then MyObj.selectionStart == '0' will probably raise an error ?!
So i think that the first/or the second test is not necessary.
Y.Chaouche
RE: Inserting a value from outside
RE: Inserting a value from outside
RE: Inserting a value from outside
RE: Inserting a value from outside
so in my page i put your javascript function inside <head> and </head>
and there my form
<form action="index.php?page=menu" method="post">
<select id="objects" onclick="selectObject(this.value,'FCKeditor1');">
<option value="###CASE_STUDY_LIST###">###CASE_STUDY_LIST###</option>
<option value="###CASE_STUDY_ID(*)###">###CASE_STUDY_ID(?)###</option>
<option value="###NEWS_LIST###">###NEWS_LIST###</option>
<option value="###NEWS_ID(?)###">###NEWS_ID(?)###</option>
</select>
<br>
<input type="submit" value="Submit">
</form>
when i choose an element in the list,nothing happens.
Thanks a lot for your help
RE: Inserting a value from outside
Also could you just make sure the function is begin called
at the top of javascript function just enter alert(myValue);
then try again
RE: Inserting a value from outside
the default data is added automatically each time I click on the list.
But if i add :
//oEditor.InsertHtml('test');
test goes to the textarea with firefox and ie, so if i put //oEditor.InsertHtml(myText);
it works but i have the same problems with the default line in the list box
RE: Inserting a value from outside
i solved it by changing

<select id="objects" onclick="selectObject(this.value,'FCKeditor1');">
by
<select id="objects" onChange="selectObject(this.value,'FCKeditor1');">
but it's not working on firefox
RE: Inserting a value from outside
Thanks for your help
Yohan
RE: Inserting a value from outside
RE: Inserting a value from outside
<script type="text/javascript">
function selectObject(myValue,myField) {
//alert (myValue)
var oEditor = FCKeditorAPI.GetInstance(myField) ;
var myObj=oEditor.EditorDocument;
var myText="";
if (myObj.selection) {
myObj.focus();
sel = myObj.selection.createRange();
sel.text = myValue;
} else if (myObj.selectionStart || myObj.selectionStart == '0') {
var startPos = myObj.selectionStart;
var endPos = myObj.selectionEnd;
myText = myText.substring(0, startPos) + myValue+ myText.substring(endPos, myText.length);
oEditor.InsertHtml(myText);
} else {
myText += myValue;
oEditor.InsertHtml(myText);
}
}
</script>
I will try now to insert this in the fck_link file...
RE: Inserting a value from outside
RE: Inserting a value from outside
i didn't modify much...