I've got the following code:
<div contenteditable="true" id="editor">
<p>This is example text with <span class="spoiler">spoiler<strong>s</strong></span></p>
<p>The <span class="spoiler">spoiler</span> exists in multiple paragraphs</p>
</div>
<button onclick="removeSpoiler();">remove spoiler</button>
The user can select text and after that click on the button to remove the <span class="spoiler">
formatting. After clicking the button, the text must be still selected.
For example: The user selects "with spoilers. The sp". He clicks on 'remove spoiler'. The desired output is:
<div contenteditable="true" id="editor">
<p>This is example text with spoiler<strong>s</strong></p>
<p>The sp<span class="spoiler">oiler</span> exists in multiple paragraphs</p>
</div>
<button onclick="removeSpoiler();">remove spoiler</button>
A jsFiddle of my attempt (I really don't know where to go from there): http://jsfiddle.net/632cr/
From the pop-up menu that displays after you click the tag, select Clear tag. Alternatively, you can find the data in the My Data Items column, rest the mouse pointer on the data, and click the X that appears.
Deleting a tag permanently removes it from Libby. Deleted tags can't be recovered. Go to . Tap tags at the top of the screen. Tap the tag you'd like to delete. Tap Actions. Tap Delete Tag, then Yes, Delete Tag.
From the pop-up menu that displays after you click the tag, select Clear tag. Alternatively, you can find the data in the My Data Items column, rest the mouse pointer on the data, and click the X that appears. You can clear all of the tags Structured Data Markup Helper has created, but be careful: you cannot undo a clear all tags request.
The fastest and easiest way to do this is to use rangy framework and its CSSClassApplier module.
It's easy and your code could look like this:
rangy.init();
var cssClassApplierModule = rangy.modules.CssClassApplier;
var classApplier = rangy.createCssClassApplier('spoiler');
function removeSpoiler(){
classApplier.undoToSelection(editor);
// it's some preview div
$('#preview').text( $(editor).html() );
}
See the result demo here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With