Hi All,
I am currently working on a little solution for being able to limit text in the CK Editor, now limiting the text isn't the difficult part. What i am actually trying to do is limit the text until Ck Editor Scroll bar shows, then remove the text up until the scroll bar doesn't show.
I'm nearly there i just cant figure out how to refresh the instance, each time it goes through the loop trying to remove the last line of text it does not change the offset variable height 'o' and we end up in an infantile loop
if anyone has any ideas, please feel free to post.
Thanks in advance for any help
Joe.
I am currently working on a little solution for being able to limit text in the CK Editor, now limiting the text isn't the difficult part. What i am actually trying to do is limit the text until Ck Editor Scroll bar shows, then remove the text up until the scroll bar doesn't show.
I'm nearly there i just cant figure out how to refresh the instance, each time it goes through the loop trying to remove the last line of text it does not change the offset variable height 'o' and we end up in an infantile loop
if anyone has any ideas, please feel free to post.
CKEDITOR.replace('content', { }); // get editor var editor = CKEDITOR.instances.content; // on focus remove default text editor.on('focus', function(event) { var content = editor.getData(); if (content == 'Type your text here, press return to start text lower down page') { content = '<span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 9pt"> </span></span>'; editor.setData(content); editor.focus(); } else { checkScroll(); } } , null, 'Example'); // if on blur text = '' add default text editor.on('blur', function(event) { var content = editor.getData(); if (content == '<span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 9pt"> </span></span>' || content == '<span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: 9pt;"> </span></span>') { editor.setData('Type your text here, press return to start text lower down page'); } else { checkScroll(); } } // on keyup check scroll height editor.on('key', function(event) { var $body = editor.document.$.body; var contents = CKEDITOR.document.getById('cke_contents_' + editor.name); var d = document.getElementById('cke_contents_' + editor.name); var h = d.clientHeight - 15; var o = $body.offsetHeight; if (o > h) { do { var content = editor.getData(); content = content.substring(0, content.lastIndexOf("<br />")); editor.setData(content); //checkScroll(); $body = editor.document.$.body; d = document.getElementById('cke_contents_' + editor.name); h = d.clientHeight - 15; o = $body.offsetHeight; editor.updateElement(); alert('You have entered too much text'); } while (o > h); } } , null, 'Example'); function checkScroll() { var $body = editor.document.$.body; var contents = CKEDITOR.document.getById('cke_contents_' + editor.name); var d = document.getElementById('cke_contents_' + editor.name); var h = d.clientHeight - 15; var o = $body.offsetHeight; if (o > h) { do { var content = editor.getData(); content = content.substring(0, content.lastIndexOf("<br />")); editor.setData(content); //checkScroll(); $body = editor.document.$.body; d = document.getElementById('cke_contents_' + editor.name); h = d.clientHeight - 15; o = $body.offsetHeight; editor.updateElement(); alert('You have entered too much text'); } while (o > h); } }
Thanks in advance for any help
Joe.