@wordpress/dom
Version:
DOM utilities module for WordPress.
43 lines (40 loc) • 1.63 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = hiddenCaretRangeFromPoint;
var _caretRangeFromPoint = _interopRequireDefault(require("./caret-range-from-point"));
var _getComputedStyle = _interopRequireDefault(require("./get-computed-style"));
/**
* Internal dependencies
*/
/**
* Get a collapsed range for a given point.
* Gives the container a temporary high z-index (above any UI).
* This is preferred over getting the UI nodes and set styles there.
*
* @param {Document} doc The document of the range.
* @param {number} x Horizontal position within the current viewport.
* @param {number} y Vertical position within the current viewport.
* @param {HTMLElement} container Container in which the range is expected to be found.
*
* @return {?Range} The best range for the given point.
*/
function hiddenCaretRangeFromPoint(doc, x, y, container) {
const originalZIndex = container.style.zIndex;
const originalPosition = container.style.position;
const {
position = 'static'
} = (0, _getComputedStyle.default)(container);
// A z-index only works if the element position is not static.
if (position === 'static') {
container.style.position = 'relative';
}
container.style.zIndex = '10000';
const range = (0, _caretRangeFromPoint.default)(doc, x, y);
container.style.zIndex = originalZIndex;
container.style.position = originalPosition;
return range;
}
//# sourceMappingURL=hidden-caret-range-from-point.js.map
;