Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After some research I've made solution based on following materials: <a href="https://developer.mozilla.org/en/DOM/range" rel="nofollow">https://developer.mozilla.org/en/DOM/range</a></p> <p><a href="http://msdn.microsoft.com/en-us/library/ms535872(v=vs.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms535872(v=vs.85).aspx</a></p> <p><a href="http://www.quirksmode.org/dom/range_intro.html" rel="nofollow">http://www.quirksmode.org/dom/range_intro.html</a></p> <p>In case of IE8 entire node must be selected but this is acceptable for me.</p> <p>Here is is some playground on jsfiddle: <a href="http://jsfiddle.net/58Uvd/" rel="nofollow">http://jsfiddle.net/58Uvd/</a> And here is code: </p> <pre class="lang-js prettyprint-override"><code>(function () { function UserRange (win) { this.win = win || window; this.doc = this.win.document; this.userRange = this.createUserRange(); } var NonIEPrototype = { constructor: UserRange, createUserRange: function () { var selection = this.win.getSelection(); return selection.rangeCount ? selection.getRangeAt(0) : this.doc.createRange(); }, overlapsNode: function (node) { return this.intersectsNode(node); }, intersectsNode: function (node) { // this method is implemented in Firefox with Gecko before 1.9 // and other non-IE browsers if (this.userRange.intersectsNode) { return this.userRange.intersectsNode(node); } return this.intersectsRange(this.createRangeWithNode(node)); }, createRangeWithNode: function (node) { var rangeWithNode = node.ownerDocument.createRange(); try { rangeWithNode.selectNode(node); } catch (ex) { rangeWithNode.selectNodeContents(node); } return rangeWithNode; }, intersectsRange: function (range) { return this.userRange.compareBoundaryPoints(Range.END_TO_START, range) === -1 &amp;&amp; this.userRange.compareBoundaryPoints(Range.START_TO_END, range) === 1; } }; var IEPrototype = { constructor: UserRange, createUserRange: function () { return this.doc.selection.createRange(); }, overlapsNode: function (node) { var rangeWithNode = this.createRangeWithNode(node); return this.containsRange(rangeWithNode); }, createRangeWithNode: function (node) { var range = node.ownerDocument.selection.createRange(); range.moveToElementText(node); return range; }, containsRange: function (range) { return this.userRange.inRange(range); } }; UserRange.prototype = window.getSelection ? NonIEPrototype : IEPrototype; window.UserRange = UserRange; }()); </code></pre> <p>And usage:</p> <pre class="lang-js prettyprint-override"><code>var userRange = new UserRange(); userRange.overlapsNode(document.getElementById('node-to-check')); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload