From: Bartosz DziewoƄski Date: Mon, 19 Feb 2018 19:53:11 +0000 (+0100) Subject: mw.Title: Use $.trimByteLength from jquery.byteLimit module X-Git-Tag: 1.31.0-rc.0~557^2 X-Git-Url: http://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=0406ae156a7441c345a6239fdef936c1945251c3 mw.Title: Use $.trimByteLength from jquery.byteLimit module Change-Id: I39ebd559a72ce72743cbe3bb86abe679d108d94a --- diff --git a/resources/Resources.php b/resources/Resources.php index e139c3af81..4d89f87199 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1202,6 +1202,7 @@ return [ ], 'dependencies' => [ 'jquery.byteLength', + 'jquery.byteLimit', 'mediawiki.util', ], 'targets' => [ 'desktop', 'mobile' ], diff --git a/resources/src/mediawiki/mediawiki.Title.js b/resources/src/mediawiki/mediawiki.Title.js index 851f06c2d1..6a4ebb1f14 100644 --- a/resources/src/mediawiki/mediawiki.Title.js +++ b/resources/src/mediawiki/mediawiki.Title.js @@ -407,21 +407,7 @@ * @return {string} */ trimToByteLength = function ( s, length ) { - var byteLength, chopOffChars, chopOffBytes; - - // bytelength is always greater or equal to the length in characters - s = s.substr( 0, length ); - while ( ( byteLength = $.byteLength( s ) ) > length ) { - // Calculate how many characters can be safely removed - // First, we need to know how many bytes the string exceeds the threshold - chopOffBytes = byteLength - length; - // A character in UTF-8 is at most 4 bytes - // One character must be removed in any case because the - // string is too long - chopOffChars = Math.max( 1, Math.floor( chopOffBytes / 4 ) ); - s = s.substr( 0, s.length - chopOffChars ); - } - return s; + return $.trimByteLength( '', s, length ).newVal; }, /**