* "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 trimValueForByteLength( safeVal, newVal, byteLimit, fn ) {
+ $.trimByteLength = function ( safeVal, newVal, byteLimit, fn ) {
var startMatches, endMatches, matchesLen, inpParts,
oldVal = safeVal;
newVal: newVal,
trimmed: true
};
- }
+ };
var eventKeys = [
'keyup.byteLimit',
// 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 = trimValueForByteLength(
+ var res = $.trimByteLength(
prevSafeVal,
this.value,
elLimit,
this.value = res.newVal;
}
// Always adjust prevSafeVal to reflect the input value. Not doing this could cause
- // trimValueForByteLength 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;
} );
} );
};
- $.fn.byteLimit.trimValueForByteLength = trimValueForByteLength;
-
/**
* @class jQuery
* @mixins jQuery.plugin.byteLimit
mw.widgets.TitleInputWidget.prototype.cleanUpValue = function ( value ) {
var widget = this;
value = mw.widgets.TitleInputWidget.parent.prototype.cleanUpValue.call( this, value );
- return $.fn.byteLimit.trimValueForByteLength( this.value, value, this.maxLength, function ( value ) {
+ return $.trimByteLength( this.value, value, this.maxLength, function ( value ) {
var title = widget.getTitle( value );
return title ? title.getMain() : value;
} ).newVal;