mirror of
https://github.com/xdan/datetimepicker.git
synced 2024-11-18 06:24:22 +00:00
fix removing symbols with cmd or selecting
(cherry picked from commit cf89d330df
)
This commit is contained in:
parent
1621ce716c
commit
9ab5953f50
@ -589,7 +589,7 @@ var datetimepickerFactory = function ($) {
|
||||
inverseButton: false,
|
||||
hours12: false,
|
||||
next: 'xdsoft_next',
|
||||
prev: 'xdsoft_prev',
|
||||
prev : 'xdsoft_prev',
|
||||
dayOfWeekStart: 0,
|
||||
parentID: 'body',
|
||||
timeHeightInTimePicker: 25,
|
||||
@ -619,9 +619,9 @@ var datetimepickerFactory = function ($) {
|
||||
weekends: [],
|
||||
highlightedDates: [],
|
||||
highlightedPeriods: [],
|
||||
allowDates: [],
|
||||
allowDateRe: null,
|
||||
disabledDates: [],
|
||||
allowDates : [],
|
||||
allowDateRe : null,
|
||||
disabledDates : [],
|
||||
disabledWeekDays: [],
|
||||
yearOffset: 0,
|
||||
beforeShowDay: null,
|
||||
@ -664,7 +664,7 @@ var datetimepickerFactory = function ($) {
|
||||
},
|
||||
formatter: {
|
||||
parseDate: function (date, format) {
|
||||
if(isFormatStandard(format)) {
|
||||
if(isFormatStandard(format)){
|
||||
return defaultDateHelper.parseDate(date, format);
|
||||
}
|
||||
var d = moment(date, format);
|
||||
@ -672,13 +672,13 @@ var datetimepickerFactory = function ($) {
|
||||
},
|
||||
|
||||
formatDate: function (date, format) {
|
||||
if(isFormatStandard(format)) {
|
||||
if(isFormatStandard(format)){
|
||||
return defaultDateHelper.formatDate(date, format);
|
||||
}
|
||||
return moment(date).format(format);
|
||||
},
|
||||
|
||||
formatMask: function(format) {
|
||||
formatMask: function(format){
|
||||
return format
|
||||
.replace(/Y{4}/g, '9999')
|
||||
.replace(/Y{2}/g, '99')
|
||||
@ -690,11 +690,11 @@ var datetimepickerFactory = function ($) {
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// for locale settings
|
||||
$.datetimepicker = {
|
||||
setLocale: function(locale) {
|
||||
setLocale: function(locale){
|
||||
var newLocale = default_options.i18n[locale] ? locale : globalLocaleDefault;
|
||||
if (globalLocale !== newLocale) {
|
||||
globalLocale = newLocale;
|
||||
@ -725,12 +725,11 @@ var datetimepickerFactory = function ($) {
|
||||
RFC_1123: 'D, d M Y H:i:s O',
|
||||
RSS: 'D, d M Y H:i:s O',
|
||||
W3C: 'Y-m-d\TH:i:sP'
|
||||
};
|
||||
}
|
||||
|
||||
var isFormatStandard = function(format) {
|
||||
return $.map(standardFormats, function (val) { return val })
|
||||
.indexOf(format) === -1 ? false : true;
|
||||
};
|
||||
var isFormatStandard = function(format){
|
||||
return Object.values(standardFormats).indexOf(format) === -1 ? false : true;
|
||||
}
|
||||
|
||||
$.extend($.datetimepicker, standardFormats);
|
||||
|
||||
@ -896,7 +895,7 @@ var datetimepickerFactory = function ($) {
|
||||
timeboxparent.on('mousewheel', function (event) {
|
||||
var top = Math.abs(parseInt(timebox.css('marginTop'), 10));
|
||||
|
||||
top = top + (event.originalEvent.deltaY * 20);
|
||||
top = top - (event.deltaY * 20);
|
||||
if (top < 0) {
|
||||
top = 0;
|
||||
}
|
||||
@ -935,6 +934,7 @@ var datetimepickerFactory = function ($) {
|
||||
_KEY0 = 96,
|
||||
_KEY9 = 105,
|
||||
CTRLKEY = 17,
|
||||
CMDKEY = 91,
|
||||
DEL = 46,
|
||||
ENTER = 13,
|
||||
ESC = 27,
|
||||
@ -951,7 +951,7 @@ var datetimepickerFactory = function ($) {
|
||||
ZKEY = 90,
|
||||
YKEY = 89,
|
||||
ctrlDown = false,
|
||||
isClosed = false,
|
||||
cmdDown = false,
|
||||
options = ($.isPlainObject(opt) || !opt) ? $.extend(true, {}, default_options, opt) : $.extend(true, {}, default_options),
|
||||
|
||||
lazyInitTimer = 0,
|
||||
@ -1068,7 +1068,7 @@ var datetimepickerFactory = function ($) {
|
||||
if(distance > options.touchMovedThreshold) {
|
||||
this.touchMoved = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
month_picker
|
||||
.find('.xdsoft_select')
|
||||
@ -2226,7 +2226,6 @@ var datetimepickerFactory = function ($) {
|
||||
datetimepicker
|
||||
.on('open.xdsoft', function (event) {
|
||||
var onShow = true;
|
||||
isClosed = false;
|
||||
if (options.onShow && $.isFunction(options.onShow)) {
|
||||
onShow = options.onShow.call(datetimepicker, _xdsoft_datetime.currentTime, datetimepicker.data('input'), event);
|
||||
}
|
||||
@ -2247,12 +2246,6 @@ var datetimepickerFactory = function ($) {
|
||||
})
|
||||
.on('close.xdsoft', function (event) {
|
||||
var onClose = true;
|
||||
event.stopPropagation();
|
||||
|
||||
if (isClosed) {
|
||||
return;
|
||||
}
|
||||
|
||||
month_picker
|
||||
.find('.xdsoft_month,.xdsoft_year')
|
||||
.find('.xdsoft_select')
|
||||
@ -2263,7 +2256,7 @@ var datetimepickerFactory = function ($) {
|
||||
if (onClose !== false && !options.opened && !options.inline) {
|
||||
datetimepicker.hide();
|
||||
}
|
||||
isClosed = true;
|
||||
event.stopPropagation();
|
||||
})
|
||||
.on('toggle.xdsoft', function () {
|
||||
if (datetimepicker.is(':visible')) {
|
||||
@ -2354,7 +2347,7 @@ var datetimepickerFactory = function ($) {
|
||||
return false;
|
||||
};
|
||||
|
||||
if (options.mask) {
|
||||
if(options.mask) {
|
||||
input.off('keydown.xdsoft');
|
||||
}
|
||||
|
||||
@ -2379,7 +2372,7 @@ var datetimepickerFactory = function ($) {
|
||||
setCaretPos(input[0], 0);
|
||||
}
|
||||
|
||||
input.off('paste.xdsoft').on('paste.xdsoft', function (event) {
|
||||
input.on('paste.xdsoft', function (event) {
|
||||
// couple options here
|
||||
// 1. return false - tell them they can't paste
|
||||
// 2. insert over current characters - minimal validation
|
||||
@ -2392,13 +2385,12 @@ var datetimepickerFactory = function ($) {
|
||||
var clipboardData = event.clipboardData || event.originalEvent.clipboardData || window.clipboardData,
|
||||
pastedData = clipboardData.getData('text'),
|
||||
val = this.value,
|
||||
pos = this.selectionStart;
|
||||
pos = this.selectionStart
|
||||
|
||||
var valueBeforeCursor = val.substr(0, pos);
|
||||
var valueAfterPaste = val.substr(pos + pastedData.length);
|
||||
|
||||
val = valueBeforeCursor + pastedData + valueAfterPaste;
|
||||
val = val.substring(0, options.mask.length);
|
||||
pos += pastedData.length;
|
||||
|
||||
if (isValidValue(options.mask, val)) {
|
||||
@ -2456,6 +2448,10 @@ var datetimepickerFactory = function ($) {
|
||||
|
||||
}
|
||||
|
||||
if (event.metaKey) { // cmd has been pressed
|
||||
pos = 0;
|
||||
hasSel = true;
|
||||
}
|
||||
|
||||
if (hasSel) {
|
||||
// pos might have moved so re-calc length
|
||||
@ -2578,6 +2574,7 @@ var datetimepickerFactory = function ($) {
|
||||
};
|
||||
$(options.ownerDocument)
|
||||
.off('keydown.xdsoftctrl keyup.xdsoftctrl')
|
||||
.off('keydown.xdsoftcmd keyup.xdsoftcmd')
|
||||
.on('keydown.xdsoftctrl', function (e) {
|
||||
if (e.keyCode === CTRLKEY) {
|
||||
ctrlDown = true;
|
||||
@ -2586,6 +2583,16 @@ var datetimepickerFactory = function ($) {
|
||||
.on('keyup.xdsoftctrl', function (e) {
|
||||
if (e.keyCode === CTRLKEY) {
|
||||
ctrlDown = false;
|
||||
}
|
||||
})
|
||||
.on('keydown.xdsoftcmd', function (e) {
|
||||
if (e.keyCode === CMDKEY) {
|
||||
cmdDown = true;
|
||||
}
|
||||
})
|
||||
.on('keyup.xdsoftcmd', function (e) {
|
||||
if (e.keyCode === CMDKEY) {
|
||||
cmdDown = false;
|
||||
}
|
||||
});
|
||||
|
||||
@ -2651,12 +2658,12 @@ var datetimepickerFactory = function ($) {
|
||||
}
|
||||
};
|
||||
;(function (factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
if ( typeof define === 'function' && define.amd ) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['jquery', 'jquery-mousewheel'], factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
// Node/CommonJS style for Browserify
|
||||
module.exports = factory(require('jquery'));
|
||||
module.exports = factory(require('jquery'));;
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(jQuery);
|
||||
|
Loading…
Reference in New Issue
Block a user