All Projects → edg2s → rangefix

edg2s / rangefix

Licence: other
Workaround for browser bugs in Range.prototype.getClientRects and Range.prototype.getBoundingClientRect.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to rangefix

webpack2-polyfill-plugin
Insert polyfills (such as Promise) for Webpack 2
Stars: ✭ 18 (-48.57%)
Mutual labels:  polyfill
async generator
Making it easy to write async iterators in Python 3.5
Stars: ✭ 87 (+148.57%)
Mutual labels:  polyfill
core-web
like core-js but for Web APIs (based on polyfill.io)
Stars: ✭ 34 (-2.86%)
Mutual labels:  polyfill
object-keys
Object.keys shim
Stars: ✭ 41 (+17.14%)
Mutual labels:  polyfill
visual-studio-fonts
Workaround for missing Line Spacing feature in Visual Studio.
Stars: ✭ 18 (-48.57%)
Mutual labels:  workaround
audioworklet-polyfill
strictly unofficial polyfill for Web Audio API AudioWorklet
Stars: ✭ 49 (+40%)
Mutual labels:  polyfill
Javascript-Interview-Preparation
A curated collection of javascript interview questions & solutions.
Stars: ✭ 163 (+365.71%)
Mutual labels:  polyfill
web-streams-polyfill
Web Streams, based on the WHATWG spec reference implementation
Stars: ✭ 198 (+465.71%)
Mutual labels:  polyfill
o9n
🖥 A screen.orientation ponyfill
Stars: ✭ 55 (+57.14%)
Mutual labels:  polyfill
String.prototype.matchAll
Spec-compliant polyfill for String.prototype.matchAll, in ES2020
Stars: ✭ 14 (-60%)
Mutual labels:  polyfill
github-wc-polyfill
Ensure that all GitHub and GitLab scripts required for UXP and SeaMonkey are loaded correctly
Stars: ✭ 87 (+148.57%)
Mutual labels:  polyfill
appHistory
A polyfill for the AppHistory proposal
Stars: ✭ 21 (-40%)
Mutual labels:  polyfill
mini-create-react-context
(A smaller) polyfill for the react context API
Stars: ✭ 34 (-2.86%)
Mutual labels:  polyfill
react-native-wasm
A polyfill to use WebAssembly in React Native.
Stars: ✭ 39 (+11.43%)
Mutual labels:  polyfill
webvr-polyfill-dpdb
An up-to-date Device Parameter Database for the WebVR Polyfill
Stars: ✭ 29 (-17.14%)
Mutual labels:  polyfill
require-polyfill
Make `require` work in browsers, at runtime. No code bundling needed!
Stars: ✭ 37 (+5.71%)
Mutual labels:  polyfill
Array.prototype.at
An ES-spec-compliant (proposed) `Array.prototype.at`shim/polyfill/replacement that works as far down as ES3.
Stars: ✭ 20 (-42.86%)
Mutual labels:  polyfill
Gapotchenko.FX
.NET polyfill to the future. A versatile RAD framework for .NET platform.
Stars: ✭ 23 (-34.29%)
Mutual labels:  polyfill
fromentries
Object.fromEntries() ponyfill (in 6 lines)
Stars: ✭ 62 (+77.14%)
Mutual labels:  polyfill
scoped
Scoped CSS polyfill
Stars: ✭ 67 (+91.43%)
Mutual labels:  polyfill

Workaround for browser bugs in Range.prototype.getClientRects and Range.prototype.getBoundingClientRect.

In particular:

  • Chrome <= 54: Selections spanning multiple nodes return rectangles for all the parents of the endContainer. See https://code.google.com/p/chromium/issues/detail?id=324437.
  • Chrome 55: Images get no rectangle when they are wrapped in a node and you select across them.
  • Safari: Similar to the Chrome <= 54 bug, but only triggered near the edge of a block node, or programmatically near an inline node.
  • Firefox: Similar to the Chrome <= 54 bug, but only triggered near the edge of a inline node
  • IE <= 10: Rectangles are incorrectly scaled when using the browser's zoom feature.
  • Chrome: Selection across a space which spans two lines results in a bounding rectangle which doesn't cover all the individual rectangles.
  • Firefox: Selections across a space which spans two lines, and text on the next line results in a bounding rectangle which doesn't cover all the individual rectangles.

There are no known issues in Chrome >= 56, Edge and IE >= 11. In these browsers the library will fall through to native behaviour.

Install

$ npm install rangefix

Usage

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 );

Demo

http://edg2s.github.io/rangefix/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].