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

Commit

Permalink
feat(modal): support modal window sizes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gazoakley authored and pkozlowski-opensource committed Apr 20, 2014
1 parent da95122 commit 976f608
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function(grunt) {

grunt.initConfig({
ngversion: '1.2.10',
bsversion: '3.0.3',
bsversion: '3.1.1',
modules: [],//to be filled in by build task
pkg: grunt.file.readJSON('package.json'),
dist: 'dist',
Expand Down
4 changes: 3 additions & 1 deletion src/modal/docs/demo.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div ng-controller="ModalDemoCtrl">
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3>I'm a modal!</h3>
<h3 class="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body">
<ul>
Expand All @@ -18,5 +18,7 @@ <h3>I'm a modal!</h3>
</script>

<button class="btn btn-default" ng-click="open()">Open me!</button>
<button class="btn btn-default" ng-click="open('lg')">Large modal</button>
<button class="btn btn-default" ng-click="open('sm')">Small modal</button>
<div ng-show="selected">Selection from a modal: {{ selected }}</div>
</div>
3 changes: 2 additions & 1 deletion src/modal/docs/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ var ModalDemoCtrl = function ($scope, $modal, $log) {

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

$scope.open = function () {
$scope.open = function (size) {

var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
size: size,
resolve: {
items: function () {
return $scope.items;
Expand Down
1 change: 1 addition & 0 deletions src/modal/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The `$modal` service has only one method: `open(options)` where available option
* `keyboard` - indicates whether the dialog should be closable by hitting the ESC key, defaults to true
* `windowClass` - additional CSS class(es) to be added to a modal window template
* `windowTemplateUrl` - a path to a template overriding modal's window template
* `size` - optional size of modal window. Allowed values: `'sm'` (small) or `'lg'` (large). Requires Bootstrap 3.1.0 or later

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

Expand Down
5 changes: 4 additions & 1 deletion src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
},
link: function (scope, element, attrs) {
element.addClass(attrs.windowClass || '');
scope.size = attrs.size;

$timeout(function () {
// trigger CSS transitions
Expand Down Expand Up @@ -232,6 +233,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
angularDomEl.attr({
'template-url': modal.windowTemplateUrl,
'window-class': modal.windowClass,
'size': modal.size,
'index': openedWindows.length() - 1,
'animate': 'animate'
}).html(modal.content);
Expand Down Expand Up @@ -359,7 +361,8 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
backdrop: modalOptions.backdrop,
keyboard: modalOptions.keyboard,
windowClass: modalOptions.windowClass,
windowTemplateUrl: modalOptions.windowTemplateUrl
windowTemplateUrl: modalOptions.windowTemplateUrl,
size: modalOptions.size
});

}, function resolveError(reason) {
Expand Down
21 changes: 21 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,27 @@ describe('$modal', function () {
expect($document.find('div.modal')).toHaveClass('additional');
});
});

describe('size', function () {

it('should support creating small modal dialogs', function () {
open({
template: '<div>Small modal dialog</div>',
size: 'sm'
});

expect($document.find('div.modal-dialog')).toHaveClass('modal-sm');
});

it('should support creating large modal dialogs', function () {
open({
template: '<div>Large modal dialog</div>',
size: 'lg'
});

expect($document.find('div.modal-dialog')).toHaveClass('modal-lg');
});
});
});

describe('multiple modals', function () {
Expand Down
2 changes: 1 addition & 1 deletion template/modal/window.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div tabindex="-1" class="modal fade" ng-class="{in: animate}" ng-style="{'z-index': 1050 + index*10, display: 'block'}" ng-click="close($event)">
<div class="modal-dialog"><div class="modal-content" ng-transclude></div></div>
<div class="modal-dialog" ng-class="{'modal-sm': size == 'sm', 'modal-lg': size == 'lg'}"><div class="modal-content" ng-transclude></div></div>
</div>

0 comments on commit 976f608

Please sign in to comment.