Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cleanup listeners #195

Merged
merged 4 commits into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src-relution/mwComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,19 @@ angular.module('mwComponents', ['ngSanitize','mwUI.Utils'])
restrict: 'A',
require: '?^form',
link: function (scope, elm, attr, ctrl) {
elm.parents('.modal').first().on('keyup', function (event) {
var modal = elm.parents('.modal').first();

var submit = function (event) {
validateEnterKeyUp.clickIfValid(elm, event, ctrl);
});
};

if (modal) {
modal.on('keyup', submit);

scope.$on('$destroy', function () {
modal.off('keyup', submit);
});
}
}
};
})
Expand Down
12 changes: 8 additions & 4 deletions src-relution/mwComponentsBb.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ angular.module('mwComponentsBb', [])
el.children().removeClass('is-focused');
});

el.on('mousedown touch', function(ev){
el.on('mousedown touch', function (ev) {
var searchBtn = el.find('.trigger-search'),
resetBtn = el.find('.reset-search');
resetBtn = el.find('.reset-search');

if(resetBtn.find(ev.target).length !== 0){
if (resetBtn.find(ev.target).length !== 0) {
scope.reset();
} else if(searchBtn.find(ev.target).length !== 0){
} else if (searchBtn.find(ev.target).length !== 0) {
scope.search();
}
});
Expand All @@ -125,6 +125,10 @@ angular.module('mwComponentsBb', [])
}, function (val) {
scope.viewModel.searchVal = val;
});

scope.$on('$destroy', function () {
el.off();
});
}
};
})
Expand Down
7 changes: 7 additions & 0 deletions src-relution/mwDatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ angular.module('mwUI.Relution')
scope.stopDecrementCounter();
scope.stopIncrementCounter();
});

scope.$on('$destroy', function(){
if (_datePicker && _datePicker.datepicker) {
_datePicker.datepicker('destroy');
}
el.off();
});
}
};
});
12 changes: 9 additions & 3 deletions src-relution/mwHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ angular.module('mwHelper', [])
elm.on(scope.mwSetDirtyOn, function(){
formCtrl.$setDirty();
});

scope.$on('$destroy', function(){
elm.off();
});
}
};
})
Expand Down Expand Up @@ -128,9 +132,10 @@ angular.module('mwHelper', [])
scopedCallback.callback.apply(scopedCallback.scope);
});
};
angular.element('body').on('DOMNodeInserted',_.throttle(_notify, 300));
angular.element('body').on('DOMNodeRemoved',_.throttle(_notify, 300));
angular.element($window).on('resize', _.throttle(_notify, 300));
var _throttledNotify = _.throttle(_notify, 300);
angular.element('body').on('DOMNodeInserted',_throttledNotify);
angular.element('body').on('DOMNodeRemoved',_throttledNotify);
angular.element($window).on('resize', _throttledNotify);
$timeout(_notify,500);
return {
registerCallback: function(cb,scope){
Expand Down Expand Up @@ -252,6 +257,7 @@ angular.module('mwHelper', [])

scope.$on('$destroy', function(){
$interval.cancel(stopInterval);
inputElements.off();
});
}
};
Expand Down
8 changes: 8 additions & 0 deletions src-relution/mwListable.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ angular.module('mwListable', [])

if(scope.property){
elm.find('.title').on('click',scope.toggleSortOrder);

scope.$on('$destroy', function(){
elm.find('.title').off('click',scope.toggleSortOrder);
});
}

mwListableCtrl.registerColumn(scope);
Expand Down Expand Up @@ -357,6 +361,10 @@ angular.module('mwListable', [])
scope.isDisabled = function () {
return scope.$eval(attr.mwListableDisabled, { item: scope.item });
};

scope.$on('$destroy', function(){
elm.off();
});
};
}
};
Expand Down
16 changes: 12 additions & 4 deletions src-relution/mwNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ angular.module('mwNav', [])
elm.collapse('hide');
}
});

scope.$on('$destroy', function(){
elm.off();
});
}
};
})
Expand All @@ -79,8 +83,10 @@ angular.module('mwNav', [])
isActive();
$rootScope.$on('$routeChangeSuccess', isActive);

elm.find('a').on('click', function() {
scope.uncollapse();
elm.find('a').on('click', scope.uncollapse);

scope.$on('$destroy', function(){
elm.find('a').off('click', scope.uncollapse);
});
}
};
Expand Down Expand Up @@ -154,8 +160,10 @@ angular.module('mwNav', [])

$rootScope.$on('$routeChangeSuccess', isActive);

elm.find('a').on('click', function() {
scope.uncollapse();
elm.find('a').on('click', scope.uncollapse);

scope.$on('$destroy', function(){
elm.find('a').off('click', scope.uncollapse);
});
}
};
Expand Down
14 changes: 9 additions & 5 deletions src-relution/mwPopover.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ angular.module('mwPopover', [])
var visible = false,
content = '';

var destroyPopOver = function () {
if(el.popover){
el.popover('destroy');
}
};

var buildPopover = function () {
el.popover('destroy');
destroyPopOver();
el.popover({
trigger: attr.popoverTrigger || 'hover',
title: attr.popoverTitle,
Expand Down Expand Up @@ -98,10 +104,8 @@ angular.module('mwPopover', [])
});

scope.$on('$destroy', function () {
var popover = el.data('bs.popover');
if(popover && popover.tip()){
popover.tip().detach().remove();
}
destroyPopOver();
el.off();
});
}
};
Expand Down
1 change: 0 additions & 1 deletion src/mw-backbone/collection/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mwUI.Backbone.Filter = function () {
var returnNullOrObjectForMultipleValues = function (values, object) {
var hasValue = false;
if(!_.isObject(values)){
console.log(values);
throw new Error('The argument values has to be an object');
}
for(var key in values){
Expand Down
1 change: 1 addition & 0 deletions src/mw-form/directives/mw_form_leave_confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ angular.module('mwUI.Form')

scope.$on('$destroy', function () {
isActive = false;
elm.off();
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/mw-layout/directives/mw_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ angular.module('mwUI.Layout')
mwTitleIcon: '@?',
showBackButton: '=?',
mwBreadCrumbs: '=?',
description: '@?',
description: '@?'
},
require: '^?mwUi',
templateUrl: 'uikit/mw-layout/directives/templates/mw_header.html',
Expand Down
4 changes: 4 additions & 0 deletions src/mw-layout/directives/mw_sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ angular.module('mwUI.Layout')

setMaxHeight();
angular.element(window).on('resize', throttledSetMaxHeight);

scope.$on('$destroy', function () {
angular.element(window).off('resize', throttledSetMaxHeight);
});
}
};
});
8 changes: 6 additions & 2 deletions src/mw-list/directives/mw_list_body_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ angular.module('mwUI.List')
.directive('mwListableBodyRowBb', function ($timeout) {
return {
require: '^mwListableBb',
controller: function($scope){
this.getId = function(){
controller: function ($scope) {
this.getId = function () {
return $scope.$id;
};
},
Expand Down Expand Up @@ -56,6 +56,10 @@ angular.module('mwUI.List')
elm.removeClass(selectedClass);
}
});

scope.$on('$destroy', function () {
elm.off();
});
};
}
};
Expand Down
5 changes: 5 additions & 0 deletions src/mw-list/directives/mw_list_column_configurator.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ angular.module('mwUI.List')
dropDownToggle.on('hide.bs.dropdown', function () {
angular.element(window).off(hideDropDownEvents, hide);
});

scope.$on('$destroy', function(){
dropDownToggle.off();
angular.element(window).off(hideDropDownEvents, hide);
});
}
};
});
14 changes: 5 additions & 9 deletions src/mw-list/directives/mw_list_head.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,6 @@ angular.module('mwUI.List')

scrollEl.on('resize', throttledRecalculate);

// Deregister scroll callback if scope is destroyed
scope.$on('$destroy', function () {
scrollEl.off('scroll', throttledScrollFn);
});

scope.$on('$destroy', function () {
scrollEl.off('resize', throttledRecalculate);
});

el.on('focus', 'input[type=text]', function () {
el.find('.search-bar').addClass('focused');
});
Expand Down Expand Up @@ -287,6 +278,11 @@ angular.module('mwUI.List')
}
});

scope.$on('$destroy', function(){
el.off();
scrollEl.off();
});

if (scope.mwListCollection) {
collection = scope.mwListCollection.getCollection();
} else if (scope.collection) {
Expand Down
15 changes: 11 additions & 4 deletions src/mw-list/directives/mw_list_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ angular.module('mwUI.List')
scope.$on('mwList:unRegisterColumn', throttledUpdateCol);
scope.$watch('hidden', throttledUpdateVisibility);
attr.$observe('title', throttledUpdateCol);
$rootScope.$on('i18n:localeChanged', throttledUpdateCol);
$rootScope.$on('mwBootstrapBreakpoint:changed', throttledUpdateCol);
$rootScope.$on('mwBootstrapBreakpoint:changed', throttledUpdateVisibility);
$rootScope.$on('$modalOpenSuccess', throttledUpdateVisibility);
var unbindLocaleChange = $rootScope.$on('i18n:localeChanged', throttledUpdateCol);
var unbindBootstrapChangeUpdateCol = $rootScope.$on('mwBootstrapBreakpoint:changed', throttledUpdateCol);
var unbindBootstrapChangeUpdateVisibility = $rootScope.$on('mwBootstrapBreakpoint:changed', throttledUpdateVisibility);
var unbindModalOpen = $rootScope.$on('$modalOpenSuccess', throttledUpdateVisibility);

if (tableConfigurator) {
var persistedCol = tableConfigurator.get('columns').get(persistId);
Expand All @@ -198,6 +198,13 @@ angular.module('mwUI.List')
updateVisibility();
mwListCtrl.registerColumn(getColumn());
});

scope.$on('$destroy', function(){
unbindLocaleChange();
unbindBootstrapChangeUpdateCol();
unbindBootstrapChangeUpdateVisibility();
unbindModalOpen();
});
}
};
});
12 changes: 9 additions & 3 deletions src/mw-menu/directives/mw_menu_toggle_active_class.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ angular.module('mwUI.Menu')
}

setIsActiveState();
$rootScope.$on('menu-toggle-active-class-changed', setIsActiveState);
$rootScope.$on('$locationChangeSuccess', setIsActiveState);
$rootScope.$on('$routeChangeError', setIsActiveState);
var unbindMenuToggleStateListener = $rootScope.$on('menu-toggle-active-class-changed', setIsActiveState);
var unbindLocationChangeListener = $rootScope.$on('$locationChangeSuccess', setIsActiveState);
var unbindLocationErrorListener = $rootScope.$on('$routeChangeError', setIsActiveState);

scope.$on('$destroy', function(){
unbindMenuToggleStateListener();
unbindLocationChangeListener();
unbindLocationErrorListener();
});
}
};
});
8 changes: 4 additions & 4 deletions src/mw-menu/directives/mw_menu_top_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ angular.module('mwUI.Menu')
},
templateUrl: 'uikit/mw-menu/directives/templates/mw_menu_top_bar.html',
require: '^?mwUi',
link: function(scope, el, attrs, mwUiCtrl){
if(mwUiCtrl){
link: function (scope, el, attrs, mwUiCtrl) {
if (mwUiCtrl) {
mwUiCtrl.addClass('has-mw-menu-top-bar');
}

Expand All @@ -26,10 +26,10 @@ angular.module('mwUI.Menu')

angular.element(window).on('resize', throttledCloseMenu);

scope.$on('$destroy', function(){
scope.$on('$destroy', function () {
unBindLocationListener();
angular.element(window).off('resize', throttledCloseMenu);
if(mwUiCtrl){
if (mwUiCtrl) {
mwUiCtrl.removeClass('has-mw-menu-top-bar');
}
});
Expand Down
Loading