function replace_in_text_node(text_node, offset, old_word, new_word) { var isIE = !!document.documentMode, range, text_value, s; range = document.createRange(); range.setStart(text_node, offset); range.setEnd(text_node, offset + old_word.length); s = window.getSelection(); if(s.rangeCount > 0) { s.removeAllRanges(); } s.addRange(range); if (isIE) { text_value = text_node.nodeValue; text_value = text_value.slice(0, offset) + new_word + text_value.slice(offset + old_word.length); text_node.nodeValue = text_value; } else { // For none IE, simulate more closely so that it could trigger // element node change. document.execCommand('delete'); document.execCommand('insertText', false, new_word); } } function replace_word_internal(root_node, old_word, new_word) { var i, value, offset, result; if (root_node.nodeType === 1 /* ELEMENT */) { for (i = 0; i < root_node.childNodes.length; i += 1) { cur_child = root_node.childNodes[i]; result = replace_word_internal(cur_child, old_word, new_word); if (result) { return true; } } } else if (root_node.nodeType === 3 /* TEXT_NODE */) { offset = root_node.nodeValue.indexOf(old_word); if (offset == -1) { return false; } replace_in_text_node(root_node, offset, old_word, new_word); } return false; } function replace_word(old_word, new_word) { var edit_div = document.getElementById('edit_div'); replace_word_internal(edit_div, old_word, new_word); } function replace_tag_internal(root_node, contained_text) { var i, cur_child, new_child; for (i = 0; i < root_node.childNodes.length; i += 1) { cur_child = root_node.childNodes[i]; if (cur_child.nodeType === 1 && (cur_child.nodeName === 'I' || cur_child.nodeName === 'B') && cur_child.textContent.indexOf(contained_text) !== -1) { new_child = document.createElement('I'); new_child.textContent = '[' + cur_child.textContent + ']'; cur_child.parentNode.replaceChild(new_child, cur_child); } else if (cur_child.nodeType === 1) { replace_tag_internal(cur_child, contained_text); } } } function replace_tag_that_has(contained_text) { var edit_div = document.getElementById('edit_div'); replace_tag_internal(edit_div, contained_text); } function word_is_around_selection(word) { var selection = window.getSelection(), range, text_content; if (!selection.rangeCount) { return false; } range = selection.getRangeAt(0); if (range.startContainer.nodeType === 1) { text_content = range.startContainer.textContent; } else if (range.startContainer.nodeType === 3) { text_content = range.startContainer.nodeValue; } else { return false; } return text_content.indexOf(word) !== -1; }
Below is the content editable:
The following is quotte from the company website: weee founded Menlo Secuirty to eliminae the threatt of malware from the web and emale
We believe that everyon should be able to enjoy the benefits of the Internet