Skip to content

Commit a5ae3b0

Browse files
committed
Fixed tabIndex conflict; Fixed register of multiple listeneres for window events
1 parent e8fa81e commit a5ae3b0

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

Diff for: dist/js/DatePickerX.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
titleFormatMonth : 'MM yyyy',
3131
titleFormatYear : 'yyyy'
3232
},
33-
openedDPX = null;
33+
openedDPX = null,
34+
globalEventsInitiated = false;
3435

3536
/**
3637
* Creates and returns new DOM element
@@ -235,7 +236,7 @@
235236
document.querySelectorAll('[href], input, select, textarea, button, iframe, object, embed, [tabindex], [contenteditable]')
236237
).filter(function(item)
237238
{
238-
return focusableElements.indexOf(item) < 0;
239+
return focusableElements.indexOf(item) < 0 && item.tabIndex >= 0;
239240
}).forEach(function(item)
240241
{
241242
item.dataset.datepickerxDisabledTabIndex = item.tabIndex;
@@ -267,6 +268,8 @@
267268
{
268269
item.tabIndex = -1;
269270
});
271+
272+
openedDPX = null;
270273
}
271274
}
272275

@@ -285,7 +288,7 @@
285288
};
286289

287290
input.addEventListener('click', openDatePicker);
288-
window.addEventListener('keydown', function(event)
291+
!globalEventsInitiated && window.addEventListener('keydown', function(event)
289292
{
290293
if (event.keyCode === 13) {
291294
if (document.activeElement === input) {
@@ -306,7 +309,7 @@
306309
}
307310
}
308311
});
309-
window.addEventListener('click', closeDatePicker);
312+
!globalEventsInitiated && window.addEventListener('click', closeDatePicker);
310313
elements.container.addEventListener('click', function(e)
311314
{
312315
e.stopPropagation();
@@ -351,6 +354,8 @@
351354
{
352355
dpx.setValue(null) && closeDatePicker();
353356
});
357+
358+
globalEventsInitiated = true;
354359
}
355360

356361
/**

0 commit comments

Comments
 (0)