Replace deprecated String.prototype.substr()

String.prototype.substr() is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) so we replace it with slice() which works similarily but isn't deprecated.
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
This commit is contained in:
Tobias Speicher 2022-02-17 17:06:55 +01:00
parent bb372ec424
commit 4d7b36b24d
No known key found for this signature in database
GPG Key ID: 2CF824BD810C3BDB

View File

@ -2432,8 +2432,8 @@ var datetimepickerFactory = function ($) {
val = this.value,
pos = this.selectionStart
var valueBeforeCursor = val.substr(0, pos);
var valueAfterPaste = val.substr(pos + pastedData.length);
var valueBeforeCursor = val.slice(0, pos);
var valueAfterPaste = val.slice(pos + pastedData.length);
val = valueBeforeCursor + pastedData + valueAfterPaste;
pos += pastedData.length;
@ -2478,7 +2478,7 @@ var datetimepickerFactory = function ($) {
// 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
while (true) {
var maskValueAtCurPos = options.mask.substr(pos, 1);
var maskValueAtCurPos = options.mask.slice(pos, pos+1);
var posShorterThanMaskLength = pos < options.mask.length;
var posGreaterThanZero = pos > 0;
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
var defaultBlank = options.mask.replace(/[0-9]/g, '_');
var defaultBlankSelectionReplacement = defaultBlank.substr(pos, selLength);
var selReplacementRemainder = defaultBlankSelectionReplacement.substr(1) // might be empty
var defaultBlankSelectionReplacement = defaultBlank.slice(pos, pos+selLength);
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 charsAfterSelection = val.substr(pos + selLength);
var charsAfterSelection = val.slice(pos + selLength);
val = valueBeforeSel + insertChars + charsAfterSelection
} else {
var valueBeforeCursor = val.substr(0, pos);
var valueBeforeCursor = val.slice(0, pos);
var insertChar = digit;
var valueAfterNextChar = val.substr(pos + 1);
var valueAfterNextChar = val.slice(pos + 1);
val = valueBeforeCursor + insertChar + valueAfterNextChar
}
@ -2535,7 +2535,7 @@ var datetimepickerFactory = function ($) {
// resume cursor location
pos += (key === BACKSPACE) ? 0 : 1;
// 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;
}