Merge pull request #694 from brcportal2/master

fix removing symbols with cmd or selecting
This commit is contained in:
Valeriy Chupurnov 2019-02-23 13:26:47 +03:00 committed by GitHub
commit 3e051a26a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 101 additions and 33 deletions

20
.gitignore vendored Normal file
View File

@ -0,0 +1,20 @@
lib
node_modules
*.log
.idea
.vscode/
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
package-lock.json
/.nyc_output/
coverage/
/coverage/

View File

@ -636,7 +636,8 @@ var datetimepickerFactory = function ($) {
beforeShowDay: null, beforeShowDay: null,
enterLikeTab: true, enterLikeTab: true,
showApplyButton: false showApplyButton: false,
insideParent: false,
}; };
var dateHelper = null, var dateHelper = null,
@ -942,7 +943,8 @@ var datetimepickerFactory = function ($) {
KEY9 = 57, KEY9 = 57,
_KEY0 = 96, _KEY0 = 96,
_KEY9 = 105, _KEY9 = 105,
CTRLKEY = 17, CTRLKEY = 17,
CMDKEY = 91,
DEL = 46, DEL = 46,
ENTER = 13, ENTER = 13,
ESC = 27, ESC = 27,
@ -958,7 +960,8 @@ var datetimepickerFactory = function ($) {
VKEY = 86, VKEY = 86,
ZKEY = 90, ZKEY = 90,
YKEY = 89, YKEY = 89,
ctrlDown = false, ctrlDown = false,
cmdDown = false,
options = ($.isPlainObject(opt) || !opt) ? $.extend(true, {}, default_options, opt) : $.extend(true, {}, default_options), options = ($.isPlainObject(opt) || !opt) ? $.extend(true, {}, default_options, opt) : $.extend(true, {}, default_options),
lazyInitTimer = 0, lazyInitTimer = 0,
@ -1353,8 +1356,11 @@ var datetimepickerFactory = function ($) {
.append(calendar) .append(calendar)
.append(applyButton); .append(applyButton);
$(options.parentID) if (options.insideParent) {
.append(datetimepicker); $(input).parent().append(datetimepicker);
} else {
$(options.parentID).append(datetimepicker);
}
XDSoft_datetime = function () { XDSoft_datetime = function () {
var _this = this; var _this = this;
@ -2180,7 +2186,7 @@ var datetimepickerFactory = function ($) {
} }
}); });
if (dateInputHasFixedAncestor) { if (dateInputHasFixedAncestor && !options.insideParent) {
position = 'fixed'; position = 'fixed';
//If the picker won't fit entirely within the viewport then display it above the date input. //If the picker won't fit entirely within the viewport then display it above the date input.
@ -2220,12 +2226,16 @@ var datetimepickerFactory = function ($) {
datetimepickerCss = { datetimepickerCss = {
position: position, position: position,
left: left, left: options.insideParent ? dateInputElem.offsetLeft : left,
top: '', //Initialize to prevent previous values interfering with new ones. top: '', //Initialize to prevent previous values interfering with new ones.
bottom: '' //Initialize to prevent previous values interfering with new ones. bottom: '' //Initialize to prevent previous values interfering with new ones.
}; };
datetimepickerCss[verticalAnchorEdge] = verticalPosition; if (options.insideParent) {
datetimepickerCss[verticalAnchorEdge] = dateInputElem.offsetTop + dateInputElem.offsetHeight;
} else {
datetimepickerCss[verticalAnchorEdge] = verticalPosition;
}
datetimepicker.css(datetimepickerCss); datetimepicker.css(datetimepickerCss);
}; };
@ -2453,8 +2463,12 @@ var datetimepickerFactory = function ($) {
// hitting backspace in a selection, you can possibly go back any further - go forward // hitting backspace in a selection, you can possibly go back any further - go forward
pos += (key === BACKSPACE && !hasSel) ? -1 : 1; pos += (key === BACKSPACE && !hasSel) ? -1 : 1;
} }
if (event.metaKey) { // cmd has been pressed
pos = 0;
hasSel = true;
}
if (hasSel) { if (hasSel) {
// pos might have moved so re-calc length // pos might have moved so re-calc length
@ -2576,16 +2590,27 @@ var datetimepickerFactory = function ($) {
} }
}; };
$(options.ownerDocument) $(options.ownerDocument)
.off('keydown.xdsoftctrl keyup.xdsoftctrl') .off('keydown.xdsoftctrl keyup.xdsoftctrl')
.off('keydown.xdsoftcmd keyup.xdsoftcmd')
.on('keydown.xdsoftctrl', function (e) { .on('keydown.xdsoftctrl', function (e) {
if (e.keyCode === CTRLKEY) { if (e.keyCode === CTRLKEY) {
ctrlDown = true; ctrlDown = true;
} }
}) })
.on('keyup.xdsoftctrl', function (e) { .on('keyup.xdsoftctrl', function (e) {
if (e.keyCode === CTRLKEY) { if (e.keyCode === CTRLKEY) {
ctrlDown = false; ctrlDown = false;
} }
})
.on('keydown.xdsoftcmd', function (e) {
if (e.keyCode === CMDKEY) {
cmdDown = true;
}
})
.on('keyup.xdsoftcmd', function (e) {
if (e.keyCode === CMDKEY) {
cmdDown = false;
}
}); });
this.each(function () { this.each(function () {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -627,7 +627,8 @@ var datetimepickerFactory = function ($) {
beforeShowDay: null, beforeShowDay: null,
enterLikeTab: true, enterLikeTab: true,
showApplyButton: false showApplyButton: false,
insideParent: false,
}; };
var dateHelper = null, var dateHelper = null,
@ -728,8 +729,7 @@ var datetimepickerFactory = function ($) {
} }
var isFormatStandard = function(format){ var isFormatStandard = function(format){
return $.map(standardFormats, function (val) { return val }) return Object.values(standardFormats).indexOf(format) === -1 ? false : true;
.indexOf(format) === -1 ? false : true;
} }
$.extend($.datetimepicker, standardFormats); $.extend($.datetimepicker, standardFormats);
@ -934,7 +934,8 @@ var datetimepickerFactory = function ($) {
KEY9 = 57, KEY9 = 57,
_KEY0 = 96, _KEY0 = 96,
_KEY9 = 105, _KEY9 = 105,
CTRLKEY = 17, CTRLKEY = 17,
CMDKEY = 91,
DEL = 46, DEL = 46,
ENTER = 13, ENTER = 13,
ESC = 27, ESC = 27,
@ -950,7 +951,8 @@ var datetimepickerFactory = function ($) {
VKEY = 86, VKEY = 86,
ZKEY = 90, ZKEY = 90,
YKEY = 89, YKEY = 89,
ctrlDown = false, ctrlDown = false,
cmdDown = false,
options = ($.isPlainObject(opt) || !opt) ? $.extend(true, {}, default_options, opt) : $.extend(true, {}, default_options), options = ($.isPlainObject(opt) || !opt) ? $.extend(true, {}, default_options, opt) : $.extend(true, {}, default_options),
lazyInitTimer = 0, lazyInitTimer = 0,
@ -1345,8 +1347,11 @@ var datetimepickerFactory = function ($) {
.append(calendar) .append(calendar)
.append(applyButton); .append(applyButton);
$(options.parentID) if (options.insideParent) {
.append(datetimepicker); $(input).parent().append(datetimepicker);
} else {
$(options.parentID).append(datetimepicker);
}
XDSoft_datetime = function () { XDSoft_datetime = function () {
var _this = this; var _this = this;
@ -2172,7 +2177,7 @@ var datetimepickerFactory = function ($) {
} }
}); });
if (dateInputHasFixedAncestor) { if (dateInputHasFixedAncestor && !options.insideParent) {
position = 'fixed'; position = 'fixed';
//If the picker won't fit entirely within the viewport then display it above the date input. //If the picker won't fit entirely within the viewport then display it above the date input.
@ -2212,12 +2217,16 @@ var datetimepickerFactory = function ($) {
datetimepickerCss = { datetimepickerCss = {
position: position, position: position,
left: left, left: options.insideParent ? dateInputElem.offsetLeft : left,
top: '', //Initialize to prevent previous values interfering with new ones. top: '', //Initialize to prevent previous values interfering with new ones.
bottom: '' //Initialize to prevent previous values interfering with new ones. bottom: '' //Initialize to prevent previous values interfering with new ones.
}; };
datetimepickerCss[verticalAnchorEdge] = verticalPosition; if (options.insideParent) {
datetimepickerCss[verticalAnchorEdge] = dateInputElem.offsetTop + dateInputElem.offsetHeight;
} else {
datetimepickerCss[verticalAnchorEdge] = verticalPosition;
}
datetimepicker.css(datetimepickerCss); datetimepicker.css(datetimepickerCss);
}; };
@ -2371,7 +2380,7 @@ var datetimepickerFactory = function ($) {
setCaretPos(input[0], 0); setCaretPos(input[0], 0);
} }
input.off('paste.xdsoft').on('paste.xdsoft', function (event) { input.on('paste.xdsoft', function (event) {
// couple options here // couple options here
// 1. return false - tell them they can't paste // 1. return false - tell them they can't paste
// 2. insert over current characters - minimal validation // 2. insert over current characters - minimal validation
@ -2389,8 +2398,7 @@ var datetimepickerFactory = function ($) {
var valueBeforeCursor = val.substr(0, pos); var valueBeforeCursor = val.substr(0, pos);
var valueAfterPaste = val.substr(pos + pastedData.length); var valueAfterPaste = val.substr(pos + pastedData.length);
val = valueBeforeCursor + pastedData + valueAfterPaste; val = valueBeforeCursor + pastedData + valueAfterPaste;
val = val.substring(0, options.mask.length)
pos += pastedData.length; pos += pastedData.length;
if (isValidValue(options.mask, val)) { if (isValidValue(options.mask, val)) {
@ -2446,8 +2454,12 @@ var datetimepickerFactory = function ($) {
// hitting backspace in a selection, you can possibly go back any further - go forward // hitting backspace in a selection, you can possibly go back any further - go forward
pos += (key === BACKSPACE && !hasSel) ? -1 : 1; pos += (key === BACKSPACE && !hasSel) ? -1 : 1;
} }
if (event.metaKey) { // cmd has been pressed
pos = 0;
hasSel = true;
}
if (hasSel) { if (hasSel) {
// pos might have moved so re-calc length // pos might have moved so re-calc length
@ -2569,16 +2581,27 @@ var datetimepickerFactory = function ($) {
} }
}; };
$(options.ownerDocument) $(options.ownerDocument)
.off('keydown.xdsoftctrl keyup.xdsoftctrl') .off('keydown.xdsoftctrl keyup.xdsoftctrl')
.off('keydown.xdsoftcmd keyup.xdsoftcmd')
.on('keydown.xdsoftctrl', function (e) { .on('keydown.xdsoftctrl', function (e) {
if (e.keyCode === CTRLKEY) { if (e.keyCode === CTRLKEY) {
ctrlDown = true; ctrlDown = true;
} }
}) })
.on('keyup.xdsoftctrl', function (e) { .on('keyup.xdsoftctrl', function (e) {
if (e.keyCode === CTRLKEY) { if (e.keyCode === CTRLKEY) {
ctrlDown = false; ctrlDown = false;
} }
})
.on('keydown.xdsoftcmd', function (e) {
if (e.keyCode === CMDKEY) {
cmdDown = true;
}
})
.on('keyup.xdsoftcmd', function (e) {
if (e.keyCode === CMDKEY) {
cmdDown = false;
}
}); });
this.each(function () { this.each(function () {