'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2015, 2017 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['../../../../lib/@waca/core-client/js/core-client/ui/core/Class', './NormalizedPosition'], function (Class, NormalizedPosition) { /* * Represents a range from the document model, but with normalized positions */ var NormalizedRange = Class.extend({ /* * @param {range} a Range object from the browser */ init: function init(range) { this.original = range; this.start = new NormalizedPosition(range.startContainer, range.startOffset); this.end = new NormalizedPosition(range.endContainer, range.endOffset); }, /** * @return true iff this range isn't a selection, but rather a cursor location */ isCursor: function isCursor() { return this.start.equals(this.end); }, /** * @param {string} [selector] a selector to specify whether to restrict which DOM elements the new selection should be defined in terms of * @return a Range object for use in selection, tweaked for best accuracy in a browser */ toDocumentRange: function toDocumentRange(selector) { var range = document.createRange(); var start = this.start.chooseDocumentPosition(false, selector); if (!start) { return null; } range.setStart(start.container, start.offset); var end = null; if (this.isCursor()) { end = start; //use identical parameters to start } else { //set favourEarlier to true to collapse the selection to only the nodes with actual content end = this.end.chooseDocumentPosition(true, selector); } range.setEnd(end.container, end.offset); return range; } }); return NormalizedRange; }); //# sourceMappingURL=NormalizedRange.js.map