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

Commit 015625d

Browse files
feat(modal): add support for custom window settings
Closes #892
1 parent 37777ca commit 015625d

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

src/modal/docs/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The `$modal` service has only one method: `open(options)` where available option
99
* `resolve` - members that will be resolved and passed to the controller as locals; it is equivalent of the `resolve` property for AngularJS routes
1010
* `backdrop` - controls presence of a backdrop. Allowed values: true (default), false (no backdrop), `'static'` - backdrop is present but modal window is not closed when clicking outside of the modal window.
1111
* `keyboard` - indicates whether the dialog should be closable by hitting the ESC key, defaults to true
12+
* `windowClass` - additional CSS class(es) to be added to a modal window template
1213

1314
The `open` method returns a modal instance, an object with the following properties:
1415

src/modal/modal.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ angular.module('ui.bootstrap.modal', [])
8484
transclude: true,
8585
templateUrl: 'template/modal/window.html',
8686
link: function (scope, element, attrs) {
87+
scope.windowClass = attrs.windowClass || '';
88+
8789
//trigger CSS transitions
8890
$timeout(function () {
8991
scope.animate = true;
@@ -138,10 +140,13 @@ angular.module('ui.bootstrap.modal', [])
138140
backdropDomEl = $compile(angular.element('<div modal-backdrop></div>'))($rootScope);
139141
body.append(backdropDomEl);
140142
}
141-
var modalDomEl = $compile(angular.element('<div modal-window></div>').html(modal.content))(modal.scope);
142-
body.append(modalDomEl);
143143

144-
144+
var angularDomEl = angular.element('<div modal-window></div>');
145+
angularDomEl.attr('window-class', modal.windowClass);
146+
angularDomEl.html(modal.content);
147+
148+
var modalDomEl = $compile(angularDomEl)(modal.scope);
149+
body.append(modalDomEl);
145150

146151
openedWindows.add(modalInstance, {
147152
deferred: modal.deferred,
@@ -266,7 +271,8 @@ angular.module('ui.bootstrap.modal', [])
266271
deferred: modalResultDeferred,
267272
content: tplAndVars[0],
268273
backdrop: modalOptions.backdrop,
269-
keyboard: modalOptions.keyboard
274+
keyboard: modalOptions.keyboard,
275+
windowClass: modalOptions.windowClass
270276
});
271277

272278
}, function resolveError(reason) {

src/modal/test/modal.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,18 @@ describe('$modal', function () {
360360
expect($document).toHaveBackdrop();
361361
});
362362
});
363+
364+
describe('custom window classes', function () {
365+
366+
it('should support additional window class as string', function () {
367+
open({
368+
template: '<div>With custom window class</div>',
369+
windowClass: 'additional'
370+
});
371+
372+
expect($document.find('div.modal')).toHaveClass('additional');
373+
});
374+
});
363375
});
364376

365377
describe('multiple modals', function () {

src/modal/test/modalWindow.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
describe('modal window', function () {
2+
3+
var $rootScope, $compile;
4+
5+
beforeEach(module('ui.bootstrap.modal'));
6+
beforeEach(module('template/modal/window.html'));
7+
beforeEach(inject(function (_$rootScope_, _$compile_) {
8+
$rootScope = _$rootScope_;
9+
$compile = _$compile_;
10+
}));
11+
12+
it('should support custom CSS classes as string', function () {
13+
var windowEl = $compile('<div modal-window window-class="test">content</div>')($rootScope);
14+
$rootScope.$digest();
15+
16+
expect(windowEl).toHaveClass('test');
17+
});
18+
});

template/modal/window.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div class="modal fade" ng-class="{in: animate}" ng-transclude></div>
1+
<div class="modal fade {{ windowClass }}" ng-class="{in: animate}" ng-transclude></div>

0 commit comments

Comments
 (0)