fix: remove memory leak in click-outside

This commit is contained in:
Baptiste Grob
2020-06-29 18:19:28 +02:00
parent 7d313d2104
commit fc0a7d4c66

View File

@@ -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);
didApplyClickOutside = true;
}
};
// $scope.onDocumentClick = (event) => { $scope.$on('$destroy', () => {
// /* Ignore click if on SKAlert */ attrs.clickOutside = undefined;
// if (event.target.closest('.sk-modal')) { $element.unbind('click', onElementClick);
// return; $document.unbind('click', onDocumentClick);
// } });
// if (!didApplyClickOutside) {
// $scope.$apply(attrs.clickOutside);
// didApplyClickOutside = true;
// }
// };
// $element.bind('click', $scope.onElementClick); $element.bind('click', onElementClick);
// $document.bind('click', $scope.onDocumentClick); $document.bind('click', onDocumentClick);
} }
}; };
} }