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

Change subject: Factored getscrollbarwidth utility function out of suggester 
widget
......................................................................


Factored getscrollbarwidth utility function out of suggester widget

Change-Id: Ia30b621e3e9d88b5399d57d40a8b67a8e6a82f6e
---
M ValueView/ValueView.resources.mw.php
M ValueView/ValueView.tests.qunit.php
M ValueView/resources/jquery.ui/jquery.ui.suggester.js
A ValueView/resources/jquery.util/jquery.util.getscrollbarwidth.js
M ValueView/tests/qunit/jquery.ui/jquery.ui.suggester.tests.js
A ValueView/tests/qunit/jquery.util/jquery.util.getscrollbarwidth.tests.js
6 files changed, 78 insertions(+), 25 deletions(-)

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



diff --git a/ValueView/ValueView.resources.mw.php 
b/ValueView/ValueView.resources.mw.php
index 9ebf54c..0f95d3c 100644
--- a/ValueView/ValueView.resources.mw.php
+++ b/ValueView/ValueView.resources.mw.php
@@ -101,6 +101,7 @@
                                'jquery.ui.autocomplete',
                                'jquery.ui.widget',
                                'jquery.util.adaptlettercase',
+                               'jquery.util.getscrollbarwidth',
                        )
                ),
 
@@ -175,6 +176,12 @@
                        ),
                ),
 
+               'jquery.util.getscrollbarwidth' => $moduleTemplate + array(
+                       'scripts' => array(
+                               'jquery.util/jquery.util.getscrollbarwidth.js',
+                       ),
+               ),
+
        );
 
        // return jQuery.valueview's native resources plus those required by 
the MW extension:
diff --git a/ValueView/ValueView.tests.qunit.php 
b/ValueView/ValueView.tests.qunit.php
index e0ccf3c..2f3abbf 100644
--- a/ValueView/ValueView.tests.qunit.php
+++ b/ValueView/ValueView.tests.qunit.php
@@ -219,6 +219,15 @@
                        ),
                ),
 
+               'jquery.util.getscrollbarwidth.tests' => array(
+                       'scripts' => array(
+                               
"$bp/jquery.util/jquery.util.getscrollbarwidth.tests.js",
+                       ),
+                       'dependencies' => array(
+                               'jquery.util.getscrollbarwidth',
+                       ),
+               ),
+
        );
 
 } );
diff --git a/ValueView/resources/jquery.ui/jquery.ui.suggester.js 
b/ValueView/resources/jquery.ui/jquery.ui.suggester.js
index 3d6d43e..928770a 100644
--- a/ValueView/resources/jquery.ui/jquery.ui.suggester.js
+++ b/ValueView/resources/jquery.ui/jquery.ui.suggester.js
@@ -82,6 +82,7 @@
  * @dependency jquery.eachchange
  * @dependency jquery.ui.autocomplete
  * @dependency jquery.util.adaptlettercase
+ * @dependency jquery.util.getscrollbarwidth
  */
 ( function( $ ) {
        'use strict';
@@ -338,7 +339,7 @@
                                        for ( var i = 0; i < 
this.options.maxItems; i++ ) {
                                                fixedHeight += $( 
$menu.children()[i] ).height();
                                        }
-                                       $menu.width( $menu.width() + 
this._getScrollbarWidth() );
+                                       $menu.width( $menu.width() + 
$.util.getscrollbarwidth() );
                                        $menu.height( fixedHeight );
                                        $menu.css( 'overflowY', 'scroll' );
                                }
@@ -453,25 +454,6 @@
                                height += $( this ).height();
                        } );
                        return height;
-               },
-
-               /**
-                * Calculates the width of the browser's scrollbar.
-                *
-                * @returns {Number} scrollbar width
-                */
-               _getScrollbarWidth: function() {
-                       var $inner = $( '<p/>', { style: 
'width:100px;height:100px' } ),
-                               $outer = $( '<div/>', {
-                                       style: 
'position:absolute;top:-1000px;left:-1000px;visibility:hidden;'
-                                               + 
'width:50px;height:50px;overflow:hidden;'
-                               } ).append( $inner ).appendTo( $( 'body' ) ),
-                               majorWidth = $outer[0].clientWidth;
-
-                       $outer.css( 'overflow', 'scroll' );
-                       var minorWidth = $outer[0].clientWidth;
-                       $outer.remove();
-                       return ( majorWidth - minorWidth );
                },
 
                /**
diff --git a/ValueView/resources/jquery.util/jquery.util.getscrollbarwidth.js 
b/ValueView/resources/jquery.util/jquery.util.getscrollbarwidth.js
new file mode 100644
index 0000000..7035b39
--- /dev/null
+++ b/ValueView/resources/jquery.util/jquery.util.getscrollbarwidth.js
@@ -0,0 +1,40 @@
+/**
+ * Utility function retrieving the width of the browser's scrollbar.
+ *
+ * @licence GNU GPL v2+
+ * @author H. Snater < [email protected] >
+ *
+ * @dependency jQuery
+ */
+jQuery.util = jQuery.util || {};
+
+jQuery.util.getscrollbarwidth = ( function( $ ) {
+       'use strict';
+
+       var scrollbarWidth;
+
+       return function() {
+               if( scrollbarWidth ) {
+                       return scrollbarWidth;
+               }
+
+               var $inner = $( '<p/>', { style: 'width:100px;height:100px' } ),
+                       $outer = $( '<div/>', {
+                               style: 
'position:absolute;top:-1000px;left:-1000px;visibility:hidden;'
+                                       + 
'width:50px;height:50px;overflow:hidden;'
+                       } ).append( $inner ).appendTo( $( 'body' ) ),
+                       widthWithoutScrollbar = $outer.get( 0 ).clientWidth,
+                       widthWithScrollbar;
+
+               $outer.css( 'overflow', 'scroll' );
+
+               widthWithScrollbar = $outer.get( 0 ).clientWidth;
+
+               $outer.remove();
+
+               scrollbarWidth = widthWithoutScrollbar - widthWithScrollbar;
+
+               return scrollbarWidth;
+       };
+
+} )( jQuery );
diff --git a/ValueView/tests/qunit/jquery.ui/jquery.ui.suggester.tests.js 
b/ValueView/tests/qunit/jquery.ui/jquery.ui.suggester.tests.js
index b5e88a8..cfe6b82 100644
--- a/ValueView/tests/qunit/jquery.ui/jquery.ui.suggester.tests.js
+++ b/ValueView/tests/qunit/jquery.ui/jquery.ui.suggester.tests.js
@@ -98,11 +98,6 @@
                        'Suggestion menu gets resized.'
                );
 
-               assert.ok(
-                       suggester._getScrollbarWidth() > 0,
-                       'Detected scrollbar width.'
-               );
-
                suggester.destroy();
                $input.remove();
 
diff --git 
a/ValueView/tests/qunit/jquery.util/jquery.util.getscrollbarwidth.tests.js 
b/ValueView/tests/qunit/jquery.util/jquery.util.getscrollbarwidth.tests.js
new file mode 100644
index 0000000..8208480
--- /dev/null
+++ b/ValueView/tests/qunit/jquery.util/jquery.util.getscrollbarwidth.tests.js
@@ -0,0 +1,20 @@
+/**
+ * @licence GNU GPL v2+
+ * @author H. Snater < [email protected] >
+ */
+
+( function( $, QUnit ) {
+       'use strict';
+
+       QUnit.module( 'jquery.util.getscrollbarwidth' );
+
+       QUnit.test( 'Get scrollbar width', function( assert ) {
+
+               assert.ok(
+                       $.util.getscrollbarwidth() > 0,
+                       'Retrieved scrollbar width.'
+               );
+
+       } );
+
+}( jQuery, QUnit ) );
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia30b621e3e9d88b5399d57d40a8b67a8e6a82f6e
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to