ApplicationManager and better memory management
This commit is contained in:
@@ -3,27 +3,38 @@ export function clickOutside($document) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
replace: false,
|
||||
link: function($scope, $element, attrs) {
|
||||
var didApplyClickOutside = false;
|
||||
link: function ($scope, $element, attrs) {
|
||||
// Causes memory leak as-is:
|
||||
// let didApplyClickOutside = false;
|
||||
|
||||
$element.bind('click', function(e) {
|
||||
didApplyClickOutside = false;
|
||||
if (attrs.isOpen) {
|
||||
e.stopPropagation();
|
||||
}
|
||||
});
|
||||
// $scope.$on('$destroy', () => {
|
||||
// attrs.clickOutside = null;
|
||||
// $element.unbind('click', $scope.onElementClick);
|
||||
// $document.unbind('click', $scope.onDocumentClick);
|
||||
// $scope.onElementClick = null;
|
||||
// $scope.onDocumentClick = null;
|
||||
// });
|
||||
|
||||
$document.bind('click', function() {
|
||||
// Ignore click if on SKAlert
|
||||
if (event.target.closest(".sk-modal")) {
|
||||
return;
|
||||
}
|
||||
// $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;
|
||||
// }
|
||||
// };
|
||||
|
||||
if (!didApplyClickOutside) {
|
||||
$scope.$apply(attrs.clickOutside);
|
||||
didApplyClickOutside = true;
|
||||
}
|
||||
});
|
||||
// $element.bind('click', $scope.onElementClick);
|
||||
// $document.bind('click', $scope.onDocumentClick);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
/* @ngInject */
|
||||
export function infiniteScroll($rootScope, $window, $timeout) {
|
||||
export function infiniteScroll() {
|
||||
return {
|
||||
link: function(scope, elem, attrs) {
|
||||
const offset = parseInt(attrs.threshold) || 0;
|
||||
const e = elem[0];
|
||||
elem.on('scroll', function() {
|
||||
scope.onScroll = () => {
|
||||
if (
|
||||
scope.$eval(attrs.canLoad) &&
|
||||
e.scrollTop + e.offsetHeight >= e.scrollHeight - offset
|
||||
) {
|
||||
scope.$apply(attrs.infiniteScroll);
|
||||
}
|
||||
};
|
||||
elem.on('scroll', scope.onScroll);
|
||||
scope.$on('$destroy', () => {
|
||||
elem.off('scroll', scope.onScroll);;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user