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

Commit 976f608

Browse files
gazoakleypkozlowski-opensource
authored andcommitted
feat(modal): support modal window sizes
Allows use of the size modifier classes shipped with Bootstrap 3.1 onwards. Specify either 'sm' or 'lg' to get a small/large modal dialog. Defaults to normal size dialog if not specified. Closes #2084
1 parent da95122 commit 976f608

File tree

7 files changed

+33
-5
lines changed

7 files changed

+33
-5
lines changed

Gruntfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = function(grunt) {
1717

1818
grunt.initConfig({
1919
ngversion: '1.2.10',
20-
bsversion: '3.0.3',
20+
bsversion: '3.1.1',
2121
modules: [],//to be filled in by build task
2222
pkg: grunt.file.readJSON('package.json'),
2323
dist: 'dist',

src/modal/docs/demo.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div ng-controller="ModalDemoCtrl">
22
<script type="text/ng-template" id="myModalContent.html">
33
<div class="modal-header">
4-
<h3>I'm a modal!</h3>
4+
<h3 class="modal-title">I'm a modal!</h3>
55
</div>
66
<div class="modal-body">
77
<ul>
@@ -18,5 +18,7 @@ <h3>I'm a modal!</h3>
1818
</script>
1919

2020
<button class="btn btn-default" ng-click="open()">Open me!</button>
21+
<button class="btn btn-default" ng-click="open('lg')">Large modal</button>
22+
<button class="btn btn-default" ng-click="open('sm')">Small modal</button>
2123
<div ng-show="selected">Selection from a modal: {{ selected }}</div>
2224
</div>

src/modal/docs/demo.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ var ModalDemoCtrl = function ($scope, $modal, $log) {
22

33
$scope.items = ['item1', 'item2', 'item3'];
44

5-
$scope.open = function () {
5+
$scope.open = function (size) {
66

77
var modalInstance = $modal.open({
88
templateUrl: 'myModalContent.html',
99
controller: ModalInstanceCtrl,
10+
size: size,
1011
resolve: {
1112
items: function () {
1213
return $scope.items;

src/modal/docs/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The `$modal` service has only one method: `open(options)` where available option
1212
* `keyboard` - indicates whether the dialog should be closable by hitting the ESC key, defaults to true
1313
* `windowClass` - additional CSS class(es) to be added to a modal window template
1414
* `windowTemplateUrl` - a path to a template overriding modal's window template
15+
* `size` - optional size of modal window. Allowed values: `'sm'` (small) or `'lg'` (large). Requires Bootstrap 3.1.0 or later
1516

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

src/modal/modal.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
8888
},
8989
link: function (scope, element, attrs) {
9090
element.addClass(attrs.windowClass || '');
91+
scope.size = attrs.size;
9192

9293
$timeout(function () {
9394
// trigger CSS transitions
@@ -232,6 +233,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
232233
angularDomEl.attr({
233234
'template-url': modal.windowTemplateUrl,
234235
'window-class': modal.windowClass,
236+
'size': modal.size,
235237
'index': openedWindows.length() - 1,
236238
'animate': 'animate'
237239
}).html(modal.content);
@@ -359,7 +361,8 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
359361
backdrop: modalOptions.backdrop,
360362
keyboard: modalOptions.keyboard,
361363
windowClass: modalOptions.windowClass,
362-
windowTemplateUrl: modalOptions.windowTemplateUrl
364+
windowTemplateUrl: modalOptions.windowTemplateUrl,
365+
size: modalOptions.size
363366
});
364367

365368
}, function resolveError(reason) {

src/modal/test/modal.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,27 @@ describe('$modal', function () {
431431
expect($document.find('div.modal')).toHaveClass('additional');
432432
});
433433
});
434+
435+
describe('size', function () {
436+
437+
it('should support creating small modal dialogs', function () {
438+
open({
439+
template: '<div>Small modal dialog</div>',
440+
size: 'sm'
441+
});
442+
443+
expect($document.find('div.modal-dialog')).toHaveClass('modal-sm');
444+
});
445+
446+
it('should support creating large modal dialogs', function () {
447+
open({
448+
template: '<div>Large modal dialog</div>',
449+
size: 'lg'
450+
});
451+
452+
expect($document.find('div.modal-dialog')).toHaveClass('modal-lg');
453+
});
454+
});
434455
});
435456

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

template/modal/window.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div tabindex="-1" class="modal fade" ng-class="{in: animate}" ng-style="{'z-index': 1050 + index*10, display: 'block'}" ng-click="close($event)">
2-
<div class="modal-dialog"><div class="modal-content" ng-transclude></div></div>
2+
<div class="modal-dialog" ng-class="{'modal-sm': size == 'sm', 'modal-lg': size == 'lg'}"><div class="modal-content" ng-transclude></div></div>
33
</div>

0 commit comments

Comments
 (0)