I met some trouble with javascript and ckeditor.
I've done a function that will replace in a textarea all abreviations by their expression, for example tel -> telephone, etc....
The trouble is with ckeditor. on a normal textarea this function works fine, like that:
var abbreviations = {
<?php $rqt="SELECT * FROM `glossaire` WHERE `id_company` ='".$societe['id']."'";
$result=mysql_query($rqt);
while($data=mysql_fetch_assoc($result))
{?>
"<?php echo ($data['libelle']) ; ?>": "<?php echo ($data['texte']) ; ?>",
<?php } ?>
};
function abbrReplace(el, abbrs) {
if (!el || !abbrs) {
return false;
}
else {
var val = el.value,
words = val.split(/\s/);
for (var i = 0, len = words.length; i<len; i++) {
if (abbrs[words[i]]) {
words[i] = abbrs[words[i]];
}
}
return words.join(' ');
}
}
document.getElementById("suivi").onkeyup = function(){
this.value = abbrReplace(this, abbreviations);
};
So on ckeditor, I've tried this : CKEDITOR.instances.commentaire.insertText('abbreviations');
Like that:
var abbreviations = {
<?php $rqt="SELECT * FROM `glossaire` WHERE `id_company` ='".$societe['id']."'";
$result=mysql_query($rqt);
while($data=mysql_fetch_assoc($result))
{?>
"<?php echo ($data['libelle']) ; ?>": "<?php echo ($data['texte']) ; ?>",
<?php } ?>
};
function abbrReplace(el, abbrs) {
if (!el || !abbrs) {
return false;
}
else {
var val = el.value,
words = val.split(/\s/);
for (var i = 0, len = words.length; i<len; i++) {
if (abbrs[words[i]]) {
words[i] = abbrs[words[i]];
}
}
return words.join(' ');
}
}
document.getElementById("suivi").onkeyup = function(){
this.value = CKEDITOR.instances.commentaire.insertText('abbreviations');
};
I'm really lost, on ckeditor it does not work,
I think I do something wrong, butg I do not know how to correct it.
Anykind of help will be much appreciated.
Kind Regards.
SP.