I am building a sipmle WYSIWYG editor for my website.
Insite the possible contents it will generate, there is a youtube video which is wrapped by a div to make it responsive.
My problem is, once I insert this sub-div inside the contentEditable div, sometimes the user will place the caret inside the child div, adding content to it, when that element that should be left untouched and further data should be added outside of it.
Is there a way to prevent the caret from going inside the child div? Or any other possible solution to this problem?
Here is the basic code:
<div class="htmlbox">
<div class="htmlboxtools">
<div class="icon-video" onclick="insertVideo(this)"></div>
</div>
<div class="htmlboxedit" contenteditable="true">
</div>
</div>
function insertVideo(element){
$(element).closest('.htmlbox').children('.htmlboxedit').focus();
embed = '<div class="video-responsive"><iframe src="http://www.youtube.com/embed/SMe-hvCwTRo" frameborder="0" allowfullscreen></iframe></div>';
pasteHtmlAtCaret(embed);
};
pasteHTMLatCaret() is found here: https://stackoverflow.com/a/6691294/2724978