Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/173007

Change subject: Update RangeFix library 0.1.0 -> 0.1.1
......................................................................

Update RangeFix library 0.1.0 -> 0.1.1

* https://github.com/edg2s/rangefix/commit/66a529d0
  Fix for broken range.getBoundingClientRect behaviour in Safari

Bug: 73336
Change-Id: I9bcc6c3922ec6ed59927c3f6beb56d183d9c6ecf
---
M lib/rangefix/rangefix.js
1 file changed, 22 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/07/173007/1

diff --git a/lib/rangefix/rangefix.js b/lib/rangefix/rangefix.js
index c494b5f..5d19bc3 100644
--- a/lib/rangefix/rangefix.js
+++ b/lib/rangefix/rangefix.js
@@ -1,13 +1,13 @@
 /*!
- * RangeFix v0.1.0
- * https://github.com/edg2s/range-get-client-rects
+ * RangeFix v0.1.1
+ * https://github.com/edg2s/rangefix
  *
  * Copyright 2014 Ed Sanders.
  * Released under the MIT license
  */
 ( function () {
 
-       var isBroken,
+       var broken,
                rangeFix = {};
 
        /**
@@ -19,13 +19,16 @@
         * @private
         * @return {boolean} The bug is present
         */
-       function isGetClientRectsBroken() {
-               if ( isBroken === undefined ) {
-                       var p1 = document.createElement( 'p' ),
+       function isBroken() {
+               if ( broken === undefined ) {
+                       var boundingRect,
+                               p1 = document.createElement( 'p' ),
                                p2 = document.createElement( 'p' ),
                                t1 = document.createTextNode( 'aa' ),
                                t2 = document.createTextNode( 'aa' ),
                                range = document.createRange();
+
+                       broken = {};
 
                        p1.appendChild( t1 );
                        p2.appendChild( t2 );
@@ -35,12 +38,19 @@
 
                        range.setStart( t1, 1 );
                        range.setEnd( t2, 1 );
-                       isBroken = range.getClientRects().length > 2;
+                       broken.getClientRects = broken.getBoundingClientRect = 
range.getClientRects().length > 2;
+
+                       if ( !broken.getBoundingClientRect ) {
+                               // Safari doesn't return a valid bounding rect 
for collapsed ranges
+                               range.setEnd( t1, 1 );
+                               boundingRect = range.getBoundingClientRect();
+                               broken.getBoundingClientRect = boundingRect.top 
=== 0 && boundingRect.left === 0;
+                       }
 
                        document.body.removeChild( p1 );
                        document.body.removeChild( p2 );
                }
-               return isBroken;
+               return broken;
        }
 
        /**
@@ -50,7 +60,7 @@
         * @return {ClientRectList|ClientRect[]} ClientRectList or list of 
ClientRect objects describing range
         */
        rangeFix.getClientRects = function ( range ) {
-               if ( !isGetClientRectsBroken() ) {
+               if ( !isBroken().getClientRects ) {
                        return range.getClientRects();
                }
 
@@ -95,13 +105,13 @@
                        nativeBoundingRect = range.getBoundingClientRect();
 
                // If there are no rects return null, otherwise we'll fall 
through to
-               // getBoundingClientRect, which in Chrome becomes [0,0,0,0].
+               // getBoundingClientRect, which in Chrome and Firefox becomes 
[0,0,0,0].
                if ( rects.length === 0 ) {
                        return null;
                }
 
-               if ( !isGetClientRectsBroken() ) {
-                       return range.getBoundingClientRect();
+               if ( !isBroken().getBoundingClientRect ) {
+                       return nativeBoundingRect;
                }
 
                // When nativeRange is a collapsed cursor at the end of a line 
or

-- 
To view, visit https://gerrit.wikimedia.org/r/173007
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9bcc6c3922ec6ed59927c3f6beb56d183d9c6ecf
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to