Workaround for browser bugs in Range.prototype.getClientRects and Range.prototype.getBoundingClientRect.
Workaround for browser bugs in Range.prototype.getClientRects and Range.prototype.getBoundingClientRect.
In particular:
There are no known issues in Edge and IE >= 11. In these browsers the library will fall through to native behaviour.
$ npm install rangefix
CommonJS
var RangeFix = require( 'rangefix' );
AMD
define( [ 'rangefix' ], function ( Rangefix ) {
// ...
} );
Browser global
<script src="path/to/rangefix.js"></script>
API
Replace instances of Range.prototype.getClientRects
/getBoundingClientRect
with RangeFix.getClientRects
/getBoundingClientRect
:
var range = document.getSelection().getRangeAt( 0 );
// Before
var rects = range.getClientRects();
var boundingRect = range.getBoundingClientRect();
// After
var rects = RangeFix.getClientRects( range );
var boundingRect = RangeFix.getBoundingClientRect( range );