javascript - How to order an array of ranges by position -
i range this, in div contenteditable
mode :
var sel = document.getselection(); var range = sel.getrangeat(0).clonerange(); //... comments.push(range);
the text in div has html tags <br>
, <mark>
(highlighted comments). range.startoffset , range.endoffset concern container (and not div contenteditable mode), don't know how order ranges according position in text (from top bottom).
help me, please.
if want sort ranges starting positions, can use
comments.sort(r1, r2) { var comp = r1.startcontainer.comparedocumentposition(r2.startcontainer); if(comp & node.document_position_following) return -1; if(comp & node.document_position_preceding) return +1; return r1.startoffset - r2.startoffset; }
Comments
Post a Comment