Merge pull request #786 from CommanderRoot/rm-deprecated-substr

Replace deprecated String.prototype.substr()
This commit is contained in:
Valeriy 2022-04-06 14:49:35 +03:00 committed by GitHub
commit 14403461f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2432,8 +2432,8 @@ var datetimepickerFactory = function ($) {
val = this.value, val = this.value,
pos = this.selectionStart pos = this.selectionStart
var valueBeforeCursor = val.substr(0, pos); var valueBeforeCursor = val.slice(0, pos);
var valueAfterPaste = val.substr(pos + pastedData.length); var valueAfterPaste = val.slice(pos + pastedData.length);
val = valueBeforeCursor + pastedData + valueAfterPaste; val = valueBeforeCursor + pastedData + valueAfterPaste;
pos += pastedData.length; pos += pastedData.length;
@ -2478,7 +2478,7 @@ var datetimepickerFactory = function ($) {
// value char - keep incrementing position while on separator char and we still have room // value char - keep incrementing position while on separator char and we still have room
// del char - keep decrementing position while on separator char and we still have room // del char - keep decrementing position while on separator char and we still have room
while (true) { while (true) {
var maskValueAtCurPos = options.mask.substr(pos, 1); var maskValueAtCurPos = options.mask.slice(pos, pos+1);
var posShorterThanMaskLength = pos < options.mask.length; var posShorterThanMaskLength = pos < options.mask.length;
var posGreaterThanZero = pos > 0; var posGreaterThanZero = pos > 0;
var notNumberOrPlaceholder = /[^0-9_]/; var notNumberOrPlaceholder = /[^0-9_]/;
@ -2504,19 +2504,19 @@ var datetimepickerFactory = function ($) {
// if we have a selection length we will wipe out entire selection and replace with default template for that range // if we have a selection length we will wipe out entire selection and replace with default template for that range
var defaultBlank = options.mask.replace(/[0-9]/g, '_'); var defaultBlank = options.mask.replace(/[0-9]/g, '_');
var defaultBlankSelectionReplacement = defaultBlank.substr(pos, selLength); var defaultBlankSelectionReplacement = defaultBlank.slice(pos, pos+selLength);
var selReplacementRemainder = defaultBlankSelectionReplacement.substr(1) // might be empty var selReplacementRemainder = defaultBlankSelectionReplacement.slice(1) // might be empty
var valueBeforeSel = val.substr(0, pos); var valueBeforeSel = val.slice(0, pos);
var insertChars = digit + selReplacementRemainder; var insertChars = digit + selReplacementRemainder;
var charsAfterSelection = val.substr(pos + selLength); var charsAfterSelection = val.slice(pos + selLength);
val = valueBeforeSel + insertChars + charsAfterSelection val = valueBeforeSel + insertChars + charsAfterSelection
} else { } else {
var valueBeforeCursor = val.substr(0, pos); var valueBeforeCursor = val.slice(0, pos);
var insertChar = digit; var insertChar = digit;
var valueAfterNextChar = val.substr(pos + 1); var valueAfterNextChar = val.slice(pos + 1);
val = valueBeforeCursor + insertChar + valueAfterNextChar val = valueBeforeCursor + insertChar + valueAfterNextChar
} }
@ -2535,7 +2535,7 @@ var datetimepickerFactory = function ($) {
// resume cursor location // resume cursor location
pos += (key === BACKSPACE) ? 0 : 1; pos += (key === BACKSPACE) ? 0 : 1;
// don't stop on a separator, continue whatever direction you were going // don't stop on a separator, continue whatever direction you were going
while (/[^0-9_]/.test(options.mask.substr(pos, 1)) && pos < options.mask.length && pos > 0) { while (/[^0-9_]/.test(options.mask.slice(pos, pos+1)) && pos < options.mask.length && pos > 0) {
pos += (key === BACKSPACE) ? 0 : 1; pos += (key === BACKSPACE) ? 0 : 1;
} }