Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
fix for bazillions of click handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
kalepail committed Jan 7, 2019
1 parent b688f48 commit 8b56a3a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
30 changes: 17 additions & 13 deletions dev/js/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,27 @@
});

// Once you click into a selection.. this lets you click out
this.element.on('click', function() {
document.addEventListener('click', function (event) {
var contains = $(event.target).parent().closest(self.element);
var clickHandler = function(event) {
var contains = $(event.target).parent().closest(self.element);

if (!contains.length) {
if (self.presetIsOpen)
self.presetToggle();
if (!contains.length) {
document.removeEventListener('click', clickHandler, false);

if (self.calIsOpen) {
if ($(self.selected).hasClass('dr-date-end'))
self.calendarSaveDates();
if (self.presetIsOpen)
self.presetToggle();

self.calendarSetDates();
self.calendarClose('force');
}
if (self.calIsOpen) {
if ($(self.selected).hasClass('dr-date-end'))
self.calendarSaveDates();

self.calendarSetDates();
self.calendarClose('force');
}
});
}
}

this.element.on('click', function() {
document.addEventListener('click', clickHandler, false);
});
}

Expand Down
30 changes: 17 additions & 13 deletions public/js/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,27 @@
});

// Once you click into a selection.. this lets you click out
this.element.on('click', function() {
document.addEventListener('click', function (event) {
var contains = $(event.target).parent().closest(self.element);
var clickHandler = function(event) {
var contains = $(event.target).parent().closest(self.element);

if (!contains.length) {
if (self.presetIsOpen)
self.presetToggle();
if (!contains.length) {
document.removeEventListener('click', clickHandler, false);

if (self.calIsOpen) {
if ($(self.selected).hasClass('dr-date-end'))
self.calendarSaveDates();
if (self.presetIsOpen)
self.presetToggle();

self.calendarSetDates();
self.calendarClose('force');
}
if (self.calIsOpen) {
if ($(self.selected).hasClass('dr-date-end'))
self.calendarSaveDates();

self.calendarSetDates();
self.calendarClose('force');
}
});
}
}

this.element.on('click', function() {
document.addEventListener('click', clickHandler, false);
});
}

Expand Down

0 comments on commit 8b56a3a

Please sign in to comment.