Functional directives TS

This commit is contained in:
Mo Bitar
2020-04-13 08:27:10 -05:00
parent 38873afa43
commit aed8d4a3da
15 changed files with 138 additions and 120 deletions

View File

@@ -0,0 +1,40 @@
/* @ngInject */
export function clickOutside($document: ng.IDocumentService) {
return {
restrict: 'A',
replace: false,
link: function ($scope: ng.IScope, $element: JQLite, attrs: any) {
// Causes memory leak as-is:
// let didApplyClickOutside = false;
// $scope.$on('$destroy', () => {
// attrs.clickOutside = null;
// $element.unbind('click', $scope.onElementClick);
// $document.unbind('click', $scope.onDocumentClick);
// $scope.onElementClick = null;
// $scope.onDocumentClick = null;
// });
// $scope.onElementClick = (event) => {
// didApplyClickOutside = false;
// if (attrs.isOpen) {
// event.stopPropagation();
// }
// };
// $scope.onDocumentClick = (event) => {
// /* 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);
// $document.bind('click', $scope.onDocumentClick);
}
};
}