From: James D. Forrester Date: Wed, 25 Oct 2017 19:34:32 +0000 (-0700) Subject: resources: Remove deprecated 'jquery.autoEllipsis' module X-Git-Tag: 1.31.0-rc.0~1635^2~1 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=e5a906ae07d447f3e80fbfdf344eac27cd64e890 resources: Remove deprecated 'jquery.autoEllipsis' module Change-Id: Ib181b814953bac0153dead95a25040ed2d4ca7ca --- diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31 index add2ee97e1..17dba874d2 100644 --- a/RELEASE-NOTES-1.31 +++ b/RELEASE-NOTES-1.31 @@ -31,6 +31,8 @@ production. ==== Removed and replaced external libraries ==== * (T17845) The deprecated 'jquery.badge' module was removed. +* The deprecated 'jquery.autoEllipsis' module was removed. Use the CSS + text-overflow property instead. * … === Bug fixes in 1.31 === diff --git a/jsduck.json b/jsduck.json index 0f8daf8bd2..0021f37676 100644 --- a/jsduck.json +++ b/jsduck.json @@ -21,7 +21,6 @@ "resources/src/mediawiki.toolbar", "resources/src/mediawiki.widgets", "resources/src/jquery/jquery.accessKeyLabel.js", - "resources/src/jquery/jquery.autoEllipsis.js", "resources/src/jquery/jquery.byteLength.js", "resources/src/jquery/jquery.byteLimit.js", "resources/src/jquery/jquery.checkboxShiftClick.js", diff --git a/resources/Resources.php b/resources/Resources.php index ec995bc9b3..545a84c058 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -158,12 +158,6 @@ return [ 'jquery.async' => [ 'scripts' => 'resources/lib/jquery/jquery.async.js', ], - 'jquery.autoEllipsis' => [ - 'deprecated' => 'Use CSS text-overflow instead.', - 'scripts' => 'resources/src/jquery/jquery.autoEllipsis.js', - 'dependencies' => 'jquery.highlightText', - 'targets' => [ 'desktop', 'mobile' ], - ], 'jquery.byteLength' => [ 'scripts' => 'resources/src/jquery/jquery.byteLength.js', 'targets' => [ 'desktop', 'mobile' ], diff --git a/resources/src/jquery/jquery.autoEllipsis.js b/resources/src/jquery/jquery.autoEllipsis.js deleted file mode 100644 index 8716b69405..0000000000 --- a/resources/src/jquery/jquery.autoEllipsis.js +++ /dev/null @@ -1,171 +0,0 @@ -/** - * @class jQuery.plugin.autoEllipsis - */ -( function ( $ ) { - - var - // Cache ellipsed substrings for every string-width-position combination - cache = {}, - - // Use a separate cache when match highlighting is enabled - matchTextCache = {}; - - // Due to - // jscs:disable jsDoc - /** - * Automatically truncate the plain text contents of an element and add an ellipsis - * - * @param {Object} options - * @param {'left'|'center'|'right'} [options.position='center'] Where to remove text. - * @param {boolean} [options.tooltip=false] Whether to show a tooltip with the remainder - * of the text. - * @param {boolean} [options.restoreText=false] Whether to save the text for restoring - * later. - * @param {boolean} [options.hasSpan=false] Whether the element is already a container, - * or if the library should create a new container for it. - * @param {string|null} [options.matchText=null] Text to highlight, e.g. search terms. - * @return {jQuery} - * @chainable - */ - $.fn.autoEllipsis = function ( options ) { - options = $.extend( { - position: 'center', - tooltip: false, - restoreText: false, - hasSpan: false, - matchText: null - }, options ); - - return this.each( function () { - var $trimmableText, - text, trimmableText, w, pw, - l, r, i, side, m, - // container element - used for measuring against - $container = $( this ); - - if ( options.restoreText ) { - if ( !$container.data( 'autoEllipsis.originalText' ) ) { - $container.data( 'autoEllipsis.originalText', $container.text() ); - } else { - $container.text( $container.data( 'autoEllipsis.originalText' ) ); - } - } - - // trimmable text element - only the text within this element will be trimmed - if ( options.hasSpan ) { - $trimmableText = $container.children( options.selector ); - } else { - $trimmableText = $( '' ) - .css( 'whiteSpace', 'nowrap' ) - .text( $container.text() ); - $container - .empty() - .append( $trimmableText ); - } - - text = $container.text(); - trimmableText = $trimmableText.text(); - w = $container.width(); - pw = 0; - - // Try cache - if ( options.matchText ) { - if ( !( text in matchTextCache ) ) { - matchTextCache[ text ] = {}; - } - if ( !( options.matchText in matchTextCache[ text ] ) ) { - matchTextCache[ text ][ options.matchText ] = {}; - } - if ( !( w in matchTextCache[ text ][ options.matchText ] ) ) { - matchTextCache[ text ][ options.matchText ][ w ] = {}; - } - if ( options.position in matchTextCache[ text ][ options.matchText ][ w ] ) { - $container.html( matchTextCache[ text ][ options.matchText ][ w ][ options.position ] ); - if ( options.tooltip ) { - $container.attr( 'title', text ); - } - return; - } - } else { - if ( !( text in cache ) ) { - cache[ text ] = {}; - } - if ( !( w in cache[ text ] ) ) { - cache[ text ][ w ] = {}; - } - if ( options.position in cache[ text ][ w ] ) { - $container.html( cache[ text ][ w ][ options.position ] ); - if ( options.tooltip ) { - $container.attr( 'title', text ); - } - return; - } - } - - if ( $trimmableText.width() + pw > w ) { - switch ( options.position ) { - case 'right': - // Use binary search-like technique for efficiency - l = 0; - r = trimmableText.length; - do { - m = Math.ceil( ( l + r ) / 2 ); - $trimmableText.text( trimmableText.slice( 0, m ) + '...' ); - if ( $trimmableText.width() + pw > w ) { - // Text is too long - r = m - 1; - } else { - l = m; - } - } while ( l < r ); - $trimmableText.text( trimmableText.slice( 0, l ) + '...' ); - break; - case 'center': - // TODO: Use binary search like for 'right' - i = [ Math.round( trimmableText.length / 2 ), Math.round( trimmableText.length / 2 ) ]; - // Begin with making the end shorter - side = 1; - while ( $trimmableText.outerWidth() + pw > w && i[ 0 ] > 0 ) { - $trimmableText.text( trimmableText.slice( 0, i[ 0 ] ) + '...' + trimmableText.slice( i[ 1 ] ) ); - // Alternate between trimming the end and begining - if ( side === 0 ) { - // Make the begining shorter - i[ 0 ]--; - side = 1; - } else { - // Make the end shorter - i[ 1 ]++; - side = 0; - } - } - break; - case 'left': - // TODO: Use binary search like for 'right' - r = 0; - while ( $trimmableText.outerWidth() + pw > w && r < trimmableText.length ) { - $trimmableText.text( '...' + trimmableText.slice( r ) ); - r++; - } - break; - } - } - if ( options.tooltip ) { - $container.attr( 'title', text ); - } - if ( options.matchText ) { - $container.highlightText( options.matchText ); - matchTextCache[ text ][ options.matchText ][ w ][ options.position ] = $container.html(); - } else { - cache[ text ][ w ][ options.position ] = $container.html(); - } - - } ); - }; - // jscs:enable jsDoc - - /** - * @class jQuery - * @mixins jQuery.plugin.autoEllipsis - */ - -}( jQuery ) ); diff --git a/tests/qunit/QUnitTestResources.php b/tests/qunit/QUnitTestResources.php index cd0ac15cef..1f2dba4325 100644 --- a/tests/qunit/QUnitTestResources.php +++ b/tests/qunit/QUnitTestResources.php @@ -46,7 +46,6 @@ return [ 'scripts' => [ 'tests/qunit/suites/resources/startup.test.js', 'tests/qunit/suites/resources/jquery/jquery.accessKeyLabel.test.js', - 'tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js', 'tests/qunit/suites/resources/jquery/jquery.byteLength.test.js', 'tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js', 'tests/qunit/suites/resources/jquery/jquery.color.test.js', @@ -103,7 +102,6 @@ return [ ], 'dependencies' => [ 'jquery.accessKeyLabel', - 'jquery.autoEllipsis', 'jquery.byteLength', 'jquery.byteLimit', 'jquery.color', diff --git a/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js b/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js deleted file mode 100644 index c3521ba878..0000000000 --- a/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js +++ /dev/null @@ -1,53 +0,0 @@ -( function ( $ ) { - - QUnit.module( 'jquery.autoEllipsis', QUnit.newMwEnvironment() ); - - function createWrappedDiv( text, width ) { - var $wrapper = $( '
' ).css( 'width', width ), - $div = $( '
' ).text( text ); - $wrapper.append( $div ); - return $wrapper; - } - - function findDivergenceIndex( a, b ) { - var i = 0; - while ( i < a.length && i < b.length && a[ i ] === b[ i ] ) { - i++; - } - return i; - } - - QUnit.test( 'Position right', function ( assert ) { - // We need this thing to be visible, so append it to the DOM - var $span, spanText, d, spanTextNew, - origText = 'This is a really long random string and there is no way it fits in 100 pixels.', - $wrapper = createWrappedDiv( origText, '100px' ); - - $( '#qunit-fixture' ).append( $wrapper ); - $wrapper.autoEllipsis( { position: 'right' } ); - - // Verify that, and only one, span element was created - $span = $wrapper.find( '> span' ); - assert.strictEqual( $span.length, 1, 'autoEllipsis wrapped the contents in a span element' ); - - // Check that the text fits by turning on word wrapping - $span.css( 'whiteSpace', 'nowrap' ); - assert.ltOrEq( - $span.width(), - $span.parent().width(), - 'Text fits (making the span "white-space: nowrap" does not make it wider than its parent)' - ); - - // Add two characters using scary black magic - spanText = $span.text(); - d = findDivergenceIndex( origText, spanText ); - spanTextNew = spanText.slice( 0, d ) + origText[ d ] + origText[ d ] + '...'; - - assert.gt( spanTextNew.length, spanText.length, 'Verify that the new span-length is indeed greater' ); - - // Put this text in the span and verify it doesn't fit - $span.text( spanTextNew ); - assert.gt( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more)' ); - } ); - -}( jQuery ) );