jenkins-bot has submitted this change and it was merged.

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, 35 insertions(+), 16 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/rangefix/rangefix.js b/lib/rangefix/rangefix.js
index c494b5f..35c2b04 100644
--- a/lib/rangefix/rangefix.js
+++ b/lib/rangefix/rangefix.js
@@ -1,31 +1,43 @@
 /*!
- * 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 = {};
 
        /**
-        * Check if the bug is present in the native function
+        * Check if bugs are present in the native functions
         *
-        * Constructs two lines of text and creates a range between them.
-        * Broken browsers will return three rectangles instead of two.
+        * For getClientRects, constructs two lines of text and
+        * creates a range between them. Broken browsers will
+        * return three rectangles instead of two.
+        *
+        * For getBoundingClientRect, create a collapsed range
+        * and check if the resulting rect has non-zero offsets.
+        *
+        * getBoundingClientRect is also considered broken if
+        * getClientRects is broken.
         *
         * @private
-        * @return {boolean} The bug is present
+        * @return {Object} Object containing boolean properties 
'getClientRects'
+        *                  and 'getBoundingClientRect' indicating bugs are 
present
+        *                  in these functions.
         */
-       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 +47,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 +69,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 +114,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: merged
Gerrit-Change-Id: I9bcc6c3922ec6ed59927c3f6beb56d183d9c6ecf
Gerrit-PatchSet: 2
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to