Skip to content
This repository has been archived by the owner on Feb 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #424 from ETroll/master
Browse files Browse the repository at this point in the history
Fixed memory leak where a mousedown event retained detached dom forever
  • Loading branch information
AuspeXeu committed Sep 17, 2015
2 parents 4b437a4 + 70f1222 commit df4d49c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions js/bootstrap-datetimepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@

this._attachEvents();

this.clickedOutside = function (e) {
// Clicked outside the datetimepicker, hide it
if ($(e.target).closest('.datetimepicker').length === 0) {
that.hide();
}
}

this.formatViewType = 'datetime';
if ('formatViewType' in options) {
this.formatViewType = options.formatViewType;
Expand Down Expand Up @@ -211,12 +218,8 @@
var selector = this.bootcssVer === 3 ? '.prev span, .next span' : '.prev i, .next i';
this.picker.find(selector).toggleClass(this.icons.leftArrow + ' ' + this.icons.rightArrow);
}
$(document).on('mousedown', function (e) {
// Clicked outside the datetimepicker, hide it
if ($(e.target).closest('.datetimepicker').length === 0) {
that.hide();
}
});

$(document).on('mousedown', this.clickedOutside);

this.autoclose = false;
if ('autoclose' in options) {
Expand Down Expand Up @@ -362,6 +365,7 @@

remove: function () {
this._detachEvents();
$(document).off('mousedown', this.clickedOutside);
this.picker.remove();
delete this.picker;
delete this.element.data().datetimepicker;
Expand Down

0 comments on commit df4d49c

Please sign in to comment.