Fixed insert of text modules.
This commit is contained in:
parent
f88e05e1bb
commit
9da8aeb054
3 changed files with 43 additions and 2 deletions
|
@ -103,7 +103,7 @@ class App.Utils
|
|||
)
|
||||
|
||||
# remove tags & content
|
||||
html.find('li, ul, ol, a, b, u, i, strong, blockquote, h1, h2, h3, h4, h5, h6, br, hr, img').remove()
|
||||
html.find('li, ul, ol, a, b, u, i, strong, blockquote, h1, h2, h3, h4, h5, h6, hr, img').remove()
|
||||
|
||||
html
|
||||
|
||||
|
|
|
@ -179,7 +179,33 @@
|
|||
|
||||
// get cursor position
|
||||
var marker = '<span id="js-cursor-position"></span>'
|
||||
Medium.Injector.prototype.inject( marker )
|
||||
|
||||
// IE9 and non-IE
|
||||
sel = window.getSelection();
|
||||
if (sel.getRangeAt && sel.rangeCount) {
|
||||
range = sel.getRangeAt(0);
|
||||
range.deleteContents();
|
||||
|
||||
// Range.createContextualFragment() would be useful here but is
|
||||
// only relatively recently standardized and is not supported in
|
||||
// some browsers (IE9, for one)
|
||||
var el = document.createElement("div");
|
||||
el.innerHTML = marker;
|
||||
var frag = document.createDocumentFragment(), node, lastNode;
|
||||
while ( (node = el.firstChild) ) {
|
||||
lastNode = frag.appendChild(node);
|
||||
}
|
||||
range.insertNode(frag);
|
||||
|
||||
// Preserve the selection
|
||||
if (lastNode) {
|
||||
range = range.cloneRange();
|
||||
range.setStartAfter(lastNode);
|
||||
range.collapse(true);
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
}
|
||||
}
|
||||
position = $('#js-cursor-position').position()
|
||||
$('#js-cursor-position').remove()
|
||||
if (!position) return
|
||||
|
|
|
@ -223,6 +223,16 @@ test( "htmlRemoveRichtext", function() {
|
|||
result = App.Utils.htmlRemoveRichtext( $(source) )
|
||||
equal( result.html(), should, source )
|
||||
|
||||
source = "<div><br></div>"
|
||||
should = "<br>"
|
||||
result = App.Utils.htmlClanup( $(source) )
|
||||
equal( result.html(), should, source )
|
||||
|
||||
source = "<div><div class=\"xxx\"><br></div></div>"
|
||||
should = "<div><br></div>"
|
||||
result = App.Utils.htmlRemoveRichtext( $(source) )
|
||||
equal( result.html(), should, source )
|
||||
|
||||
});
|
||||
|
||||
// htmlClanup
|
||||
|
@ -253,6 +263,11 @@ test( "htmlClanup", function() {
|
|||
result = App.Utils.htmlClanup( $(source) )
|
||||
equal( result.html(), should, source )
|
||||
|
||||
source = "<div><div class=\"xxx\"><br></div></div>"
|
||||
should = "<div><br></div>"
|
||||
result = App.Utils.htmlRemoveRichtext( $(source) )
|
||||
equal( result.html(), should, source )
|
||||
|
||||
});
|
||||
|
||||
// wrap
|
||||
|
|
Loading…
Reference in a new issue