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

Commit 96def3d

Browse files
bekospkozlowski-opensource
authored andcommitted
feat(modal): support custom template for modal window
Closes #2057
1 parent 00829b6 commit 96def3d

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/modal/docs/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The `$modal` service has only one method: `open(options)` where available option
1111
* `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.
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
14+
* `windowTemplateUrl` - a path to a template overriding modal's window template
1415

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

src/modal/modal.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
8383
},
8484
replace: true,
8585
transclude: true,
86-
templateUrl: 'template/modal/window.html',
86+
templateUrl: function(tElement, tAttrs) {
87+
return tAttrs.templateUrl || 'template/modal/window.html';
88+
},
8789
link: function (scope, element, attrs) {
8890
element.addClass(attrs.windowClass || '');
8991

@@ -226,10 +228,12 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
226228
}
227229

228230
var angularDomEl = angular.element('<div modal-window></div>');
229-
angularDomEl.attr('window-class', modal.windowClass);
230-
angularDomEl.attr('index', openedWindows.length() - 1);
231-
angularDomEl.attr('animate', 'animate');
232-
angularDomEl.html(modal.content);
231+
angularDomEl.attr({
232+
'template-url': modal.windowTemplateUrl,
233+
'window-class': modal.windowClass,
234+
'index': openedWindows.length() - 1,
235+
'animate': 'animate'
236+
}).html(modal.content);
233237

234238
var modalDomEl = $compile(angularDomEl)(modal.scope);
235239
openedWindows.top().value.modalDomEl = modalDomEl;
@@ -353,7 +357,8 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
353357
content: tplAndVars[0],
354358
backdrop: modalOptions.backdrop,
355359
keyboard: modalOptions.keyboard,
356-
windowClass: modalOptions.windowClass
360+
windowClass: modalOptions.windowClass,
361+
windowTemplateUrl: modalOptions.windowTemplateUrl
357362
});
358363

359364
}, function resolveError(reason) {

src/modal/test/modalWindow.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,14 @@ describe('modal window', function () {
1616
expect(windowEl).toHaveClass('test');
1717
expect(windowEl).toHaveClass('foo');
1818
});
19+
20+
it('should support custom template url', inject(function($templateCache) {
21+
$templateCache.put('window.html', '<div class="mywindow" ng-transclude></div>');
22+
23+
var windowEl = $compile('<div modal-window template-url="window.html" window-class="test">content</div>')($rootScope);
24+
$rootScope.$digest();
25+
26+
expect(windowEl).toHaveClass('mywindow');
27+
expect(windowEl).toHaveClass('test');
28+
}));
1929
});

0 commit comments

Comments
 (0)