fix: remove memory leak in click-outside
This commit is contained in:
@@ -3,38 +3,35 @@ export function clickOutside($document: ng.IDocumentService) {
|
|||||||
return {
|
return {
|
||||||
restrict: 'A',
|
restrict: 'A',
|
||||||
replace: false,
|
replace: false,
|
||||||
link: function ($scope: ng.IScope, $element: JQLite, attrs: any) {
|
link($scope: ng.IScope, $element: JQLite, attrs: any) {
|
||||||
// Causes memory leak as-is:
|
let didApplyClickOutside = false;
|
||||||
// let didApplyClickOutside = false;
|
|
||||||
|
|
||||||
// $scope.$on('$destroy', () => {
|
function onElementClick(event: JQueryEventObject) {
|
||||||
// attrs.clickOutside = null;
|
didApplyClickOutside = false;
|
||||||
// $element.unbind('click', $scope.onElementClick);
|
if (attrs.isOpen) {
|
||||||
// $document.unbind('click', $scope.onDocumentClick);
|
event.stopPropagation();
|
||||||
// $scope.onElementClick = null;
|
}
|
||||||
// $scope.onDocumentClick = null;
|
}
|
||||||
// });
|
|
||||||
|
|
||||||
// $scope.onElementClick = (event) => {
|
function onDocumentClick(event: JQueryEventObject) {
|
||||||
// didApplyClickOutside = false;
|
/** Ignore click if on SKAlert */
|
||||||
// if (attrs.isOpen) {
|
if (event.target.closest('.sk-modal')) {
|
||||||
// event.stopPropagation();
|
return;
|
||||||
// }
|
}
|
||||||
// };
|
if (!didApplyClickOutside) {
|
||||||
|
$scope.$apply(attrs.clickOutside);
|
||||||
// $scope.onDocumentClick = (event) => {
|
didApplyClickOutside = true;
|
||||||
// /* Ignore click if on SKAlert */
|
}
|
||||||
// if (event.target.closest('.sk-modal')) {
|
};
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if (!didApplyClickOutside) {
|
|
||||||
// $scope.$apply(attrs.clickOutside);
|
|
||||||
// didApplyClickOutside = true;
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// $element.bind('click', $scope.onElementClick);
|
$scope.$on('$destroy', () => {
|
||||||
// $document.bind('click', $scope.onDocumentClick);
|
attrs.clickOutside = undefined;
|
||||||
|
$element.unbind('click', onElementClick);
|
||||||
|
$document.unbind('click', onDocumentClick);
|
||||||
|
});
|
||||||
|
|
||||||
|
$element.bind('click', onElementClick);
|
||||||
|
$document.bind('click', onDocumentClick);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user