Permalink
Browse files

fix(modal): jquery modal pollutes document with copies of modal dialo…

…g divs

This led to divs with duplicate ids when someone switched between tabs.
  • Loading branch information...
1 parent 5889257 commit fd84819733ae0cdd9ecb918fce48cc760ae9c9d7 @beregovoy68 beregovoy68 committed Nov 29, 2016
@@ -1,13 +1,16 @@
(function () {
'use strict';
- function WavesTabController($scope) {
+ function WavesTabController($scope, dialogService) {
$scope.isSelected = function () {
return $scope.pageId === $scope.currentPageId;
};
$scope.onClick = function () {
$scope.onSelect({pageId: $scope.pageId});
+
+ // cleaning unused modal dialog divs, created by previous tab
+ dialogService.cleanup();
};
}
@@ -20,7 +23,7 @@
.directive('wavesTab', function WavesTabDirective() {
return {
restrict: 'A',
- controller: ['$scope', WavesTabController],
+ controller: ['$scope', 'dialogService', WavesTabController],
scope: {
pageId: '@',
caption: '<',
@@ -1,9 +1,11 @@
(function () {
'use strict';
- function WavesAssetDetailsController($scope, events, applicationContext, dialogService) {
+ function WavesAssetDetailsController($scope, $timeout, events, applicationContext, dialogService) {
var details = this;
+ details.cleanup = cleanup;
+
function transformAddress(address) {
var result = address;
@@ -31,11 +33,13 @@
details.totalTokens = asset.totalTokens.formatAmount();
details.reissuable = asset.reissuable ? 'Yes' : 'No';
- dialogService.open('#asset-details-dialog');
+ $timeout(function () {
+ dialogService.open('#asset-details-dialog');
+ }, 1);
});
}
- WavesAssetDetailsController.$inject = ['$scope', 'portfolio.events', 'applicationContext', 'dialogService'];
+ WavesAssetDetailsController.$inject = ['$scope', '$timeout', 'portfolio.events', 'applicationContext', 'dialogService'];
angular
.module('app.portfolio')
@@ -3,7 +3,7 @@
angular
.module('app.shared')
- .service('dialogService', [function () {
+ .service('dialogService', ['$document', function ($document) {
this.open = function (elementAccessor, options) {
angular.element(elementAccessor).modal(options);
};
@@ -19,5 +19,17 @@
this.close = function () {
angular.element.modal.close();
};
+
+ /**
+ jquery.modal pollutes document body with copied modal dialog divs
+ This creates several items with the same "id" and dialogService opens
+ dialogs with outdated data
+ */
+ this.cleanup = function () {
+ var result = $document.find('body > div.modal');
+ _.forEach(result, function (divNode) {
+ divNode.remove();
+ })
+ };
}]);
})();

0 comments on commit fd84819

Please sign in to comment.