X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=resources%2Fsrc%2Fjquery%2Fjquery.byteLimit.js;h=620323906697a873f9fef52dd684903825999fb9;hp=5551232a557521692d183c7cf9494da79aacfd19;hb=f8659ae6ea90d7bc8ce28bfc1caa56153878836f;hpb=e1c9a04624d941ca39de282e5a7c5fa35de2fe09 diff --git a/resources/src/jquery/jquery.byteLimit.js b/resources/src/jquery/jquery.byteLimit.js index 5551232a55..6203239066 100644 --- a/resources/src/jquery/jquery.byteLimit.js +++ b/resources/src/jquery/jquery.byteLimit.js @@ -10,17 +10,17 @@ * "fobo", not "foba". Basically emulating the native maxlength by * reconstructing where the insertion occurred. * - * @private + * @static * @param {string} safeVal Known value that was previously returned by this * function, if none, pass empty string. * @param {string} newVal New value that may have to be trimmed down. * @param {number} byteLimit Number of bytes the value may be in size. - * @param {Function} [fn] See jQuery.byteLimit. + * @param {Function} [fn] See jQuery#byteLimit. * @return {Object} * @return {string} return.newVal * @return {boolean} return.trimmed */ - function trimValForByteLength( safeVal, newVal, byteLimit, fn ) { + $.trimByteLength = function ( safeVal, newVal, byteLimit, fn ) { var startMatches, endMatches, matchesLen, inpParts, oldVal = safeVal; @@ -77,12 +77,12 @@ // until the limit is statisfied. if ( fn ) { // stop, when there is nothing to slice - bug 41450 - while ( $.byteLength( fn( inpParts.join( '' ) ) ) > byteLimit && inpParts[1].length > 0 ) { - inpParts[1] = inpParts[1].slice( 0, -1 ); + while ( $.byteLength( fn( inpParts.join( '' ) ) ) > byteLimit && inpParts[ 1 ].length > 0 ) { + inpParts[ 1 ] = inpParts[ 1 ].slice( 0, -1 ); } } else { while ( $.byteLength( inpParts.join( '' ) ) > byteLimit ) { - inpParts[1] = inpParts[1].slice( 0, -1 ); + inpParts[ 1 ] = inpParts[ 1 ].slice( 0, -1 ); } } @@ -92,7 +92,7 @@ newVal: newVal, trimmed: true }; - } + }; var eventKeys = [ 'keyup.byteLimit', @@ -206,7 +206,7 @@ // See http://www.w3.org/TR/DOM-Level-3-Events/#events-keyboard-event-order for // the order and characteristics of the key events. $el.on( eventKeys, function () { - var res = trimValForByteLength( + var res = $.trimByteLength( prevSafeVal, this.value, elLimit, @@ -221,7 +221,7 @@ this.value = res.newVal; } // Always adjust prevSafeVal to reflect the input value. Not doing this could cause - // trimValForByteLength to compare the new value to an empty string instead of the + // trimByteLength to compare the new value to an empty string instead of the // old value, resulting in trimming always from the end (bug 40850). prevSafeVal = res.newVal; } );