Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

feat(modal): remove deprecated code #4709

Closed
wants to merge 1 commit into from
Closed
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
242 changes: 2 additions & 240 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
backdrop: true, //can also be false or 'static'
keyboard: true
},
$get: ['$injector', '$rootScope', '$q', '$templateRequest', '$controller', '$uibModalStack', '$modalSuppressWarning', '$log',
function ($injector, $rootScope, $q, $templateRequest, $controller, $modalStack, $modalSuppressWarning, $log) {
$get: ['$injector', '$rootScope', '$q', '$templateRequest', '$controller', '$uibModalStack',
function ($injector, $rootScope, $q, $templateRequest, $controller, $modalStack) {
var $modal = {};

function getTemplatePromise(options) {
Expand Down Expand Up @@ -642,15 +642,6 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
if (modalOptions.controller) {
ctrlLocals.$scope = modalScope;
ctrlLocals.$uibModalInstance = modalInstance;
Object.defineProperty(ctrlLocals, '$modalInstance', {
get: function() {
if (!$modalSuppressWarning) {
$log.warn('$modalInstance is now deprecated. Use $uibModalInstance instead.');
}

return modalInstance;
}
});
angular.forEach(modalOptions.resolve, function(value, key) {
ctrlLocals[key] = tplAndVars[resolveIter++];
});
Expand Down Expand Up @@ -702,232 +693,3 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])

return $modalProvider;
});

/* deprecated modal below */

angular.module('ui.bootstrap.modal')

.value('$modalSuppressWarning', false)

/**
* A helper directive for the $modal service. It creates a backdrop element.
*/
.directive('modalBackdrop', [
'$animate', '$injector', '$modalStack', '$log', '$modalSuppressWarning',
function($animate , $injector, $modalStack, $log, $modalSuppressWarning) {
var $animateCss = null;

if ($injector.has('$animateCss')) {
$animateCss = $injector.get('$animateCss');
}

return {
replace: true,
templateUrl: 'template/modal/backdrop.html',
compile: function(tElement, tAttrs) {
tElement.addClass(tAttrs.backdropClass);
return linkFn;
}
};

function linkFn(scope, element, attrs) {
if (!$modalSuppressWarning) {
$log.warn('modal-backdrop is now deprecated. Use uib-modal-backdrop instead.');
}
element.addClass('modal-backdrop');

if (attrs.modalInClass) {
if ($animateCss) {
$animateCss(element, {
addClass: attrs.modalInClass
}).start();
} else {
$animate.addClass(element, attrs.modalInClass);
}

scope.$on($modalStack.NOW_CLOSING_EVENT, function(e, setIsAsync) {
var done = setIsAsync();
if ($animateCss) {
$animateCss(element, {
removeClass: attrs.modalInClass
}).start().then(done);
} else {
$animate.removeClass(element, attrs.modalInClass).then(done);
}
});
}
}
}])

.directive('modalWindow', [
'$modalStack', '$q', '$animate', '$injector', '$log', '$modalSuppressWarning',
function($modalStack , $q , $animate, $injector, $log, $modalSuppressWarning) {
var $animateCss = null;

if ($injector.has('$animateCss')) {
$animateCss = $injector.get('$animateCss');
}

return {
scope: {
index: '@'
},
replace: true,
transclude: true,
templateUrl: function(tElement, tAttrs) {
return tAttrs.templateUrl || 'template/modal/window.html';
},
link: function(scope, element, attrs) {
if (!$modalSuppressWarning) {
$log.warn('modal-window is now deprecated. Use uib-modal-window instead.');
}
element.addClass(attrs.windowClass || '');
element.addClass(attrs.windowTopClass || '');
scope.size = attrs.size;

scope.close = function(evt) {
var modal = $modalStack.getTop();
if (modal && modal.value.backdrop && modal.value.backdrop !== 'static' && (evt.target === evt.currentTarget)) {
evt.preventDefault();
evt.stopPropagation();
$modalStack.dismiss(modal.key, 'backdrop click');
}
};

// moved from template to fix issue #2280
element.on('click', scope.close);

// This property is only added to the scope for the purpose of detecting when this directive is rendered.
// We can detect that by using this property in the template associated with this directive and then use
// {@link Attribute#$observe} on it. For more details please see {@link TableColumnResize}.
scope.$isRendered = true;

// Deferred object that will be resolved when this modal is render.
var modalRenderDeferObj = $q.defer();
// Observe function will be called on next digest cycle after compilation, ensuring that the DOM is ready.
// In order to use this way of finding whether DOM is ready, we need to observe a scope property used in modal's template.
attrs.$observe('modalRender', function(value) {
if (value == 'true') {
modalRenderDeferObj.resolve();
}
});

modalRenderDeferObj.promise.then(function() {
var animationPromise = null;

if (attrs.modalInClass) {
if ($animateCss) {
animationPromise = $animateCss(element, {
addClass: attrs.modalInClass
}).start();
} else {
animationPromise = $animate.addClass(element, attrs.modalInClass);
}

scope.$on($modalStack.NOW_CLOSING_EVENT, function(e, setIsAsync) {
var done = setIsAsync();
if ($animateCss) {
$animateCss(element, {
removeClass: attrs.modalInClass
}).start().then(done);
} else {
$animate.removeClass(element, attrs.modalInClass).then(done);
}
});
}


$q.when(animationPromise).then(function() {
var inputWithAutofocus = element[0].querySelector('[autofocus]');
/**
* Auto-focusing of a freshly-opened modal element causes any child elements
* with the autofocus attribute to lose focus. This is an issue on touch
* based devices which will show and then hide the onscreen keyboard.
* Attempts to refocus the autofocus element via JavaScript will not reopen
* the onscreen keyboard. Fixed by updated the focusing logic to only autofocus
* the modal element if the modal does not contain an autofocus element.
*/
if (inputWithAutofocus) {
inputWithAutofocus.focus();
} else {
element[0].focus();
}
});

// Notify {@link $modalStack} that modal is rendered.
var modal = $modalStack.getTop();
if (modal) {
$modalStack.modalRendered(modal.key);
}
});
}
};
}])

.directive('modalAnimationClass', [
'$log', '$modalSuppressWarning',
function ($log, $modalSuppressWarning) {
return {
compile: function(tElement, tAttrs) {
if (!$modalSuppressWarning) {
$log.warn('modal-animation-class is now deprecated. Use uib-modal-animation-class instead.');
}
if (tAttrs.modalAnimation) {
tElement.addClass(tAttrs.modalAnimationClass);
}
}
};
}])

.directive('modalTransclude', [
'$log', '$modalSuppressWarning',
function ($log, $modalSuppressWarning) {
return {
link: function($scope, $element, $attrs, controller, $transclude) {
if (!$modalSuppressWarning) {
$log.warn('modal-transclude is now deprecated. Use uib-modal-transclude instead.');
}
$transclude($scope.$parent, function(clone) {
$element.empty();
$element.append(clone);
});
}
};
}])

.service('$modalStack', [
'$animate', '$timeout', '$document', '$compile', '$rootScope',
'$q',
'$injector',
'$$multiMap',
'$$stackedMap',
'$uibModalStack',
'$log',
'$modalSuppressWarning',
function($animate , $timeout , $document , $compile , $rootScope ,
$q,
$injector,
$$multiMap,
$$stackedMap,
$uibModalStack,
$log,
$modalSuppressWarning) {
if (!$modalSuppressWarning) {
$log.warn('$modalStack is now deprecated. Use $uibModalStack instead.');
}

angular.extend(this, $uibModalStack);
}])

.provider('$modal', ['$uibModalProvider', function($uibModalProvider) {
angular.extend(this, $uibModalProvider);

this.$get = ['$injector', '$log', '$modalSuppressWarning',
function ($injector, $log, $modalSuppressWarning) {
if (!$modalSuppressWarning) {
$log.warn('$modal is now deprecated. Use $uibModal instead.');
}

return $injector.invoke($uibModalProvider.$get);
}];
}]);
69 changes: 0 additions & 69 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1184,72 +1184,3 @@ describe('$uibModal', function () {
});
});
});

/* deprecation tests below */

describe('$modal deprecation', function() {
beforeEach(module('ngAnimateMock'));
beforeEach(module('ui.bootstrap.modal'));
beforeEach(module('template/modal/backdrop.html'));
beforeEach(module('template/modal/window.html'));

it('should suppress warning', function() {
module(function($provide) {
$provide.value('$modalSuppressWarning', true);
});

inject(function($modal, $timeout, $log, $rootScope) {
spyOn($log, 'warn');

$modal.open({template: '<div>Foo</div>', controller: function($modalInstance) {}});
$rootScope.$digest();
$timeout.flush(0);
expect($log.warn.calls.count()).toBe(0);
});
});

it('should give warning by default', inject(function($log) {
spyOn($log, 'warn');

inject(function($compile, $templateCache, $rootScope, $modal, $timeout) {
var backdropTemplate =
'<div class="modal-backdrop"' +
'modal-animation-class="fade"' +
'modal-in-class="in"' +
'ng-style="{\'z-index\': 1040 + (index && 1 || 0) + index*10}"' +
'></div>';
$templateCache.put('template/modal/backdrop.html', backdropTemplate);

var windowTemplate =
'<div modal-render="{{$isRendered}}" tabindex="-1" role="dialog" class="modal"' +
'modal-animation-class="fade"' +
'modal-in-class="in"' +
'ng-style="{\'z-index\': 1050 + index*10, display: \'block\'}">' +
'<div class="modal-dialog" ng-class="size ? \'modal-\' + size : \'\'"><div class="modal-content" modal-transclude></div></div>' +
'</div>';
$templateCache.put('template/modal/window.html', windowTemplate);

$modal.open({template: '<div>Foo</div>', controller: function($modalInstance) {}});
$rootScope.$digest();
$timeout.flush(0);

expect($log.warn.calls.count()).toBe(6);
expect($log.warn.calls.argsFor(0)).toEqual(['$modal is now deprecated. Use $uibModal instead.']);
expect($log.warn.calls.argsFor(1)).toEqual(['$modalInstance is now deprecated. Use $uibModalInstance instead.']);
expect($log.warn.calls.argsFor(2)).toEqual(['$modalStack is now deprecated. Use $uibModalStack instead.']);
expect($log.warn.calls.argsFor(3)).toEqual(['modal-animation-class is now deprecated. Use uib-modal-animation-class instead.']);
expect($log.warn.calls.argsFor(4)).toEqual(['modal-animation-class is now deprecated. Use uib-modal-animation-class instead.']);
expect($log.warn.calls.argsFor(5)).toEqual(['modal-transclude is now deprecated. Use uib-modal-transclude instead.']);

$log.warn.calls.reset();
$compile('<div modal-backdrop></div>')($rootScope);
$rootScope.$digest();
expect($log.warn.calls.argsFor(1)).toEqual(['modal-backdrop is now deprecated. Use uib-modal-backdrop instead.']);

$log.warn.calls.reset();
$compile('<div modal-window></div>')($rootScope);
$rootScope.$digest();
expect($log.warn.calls.argsFor(2)).toEqual(['modal-window is now deprecated. Use uib-modal-window instead.']);
});
}));
});