Skip to content

Commit 6f0371e

Browse files
authored
Merge pull request #724 from nicolethoen/modal_overlay
Modal overlay
2 parents b2ac31c + d7450fe commit 6f0371e

14 files changed

+774
-174
lines changed

src/modals/about-modal.component.js

Lines changed: 0 additions & 171 deletions
This file was deleted.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
angular.module('patternfly.modals')
2+
3+
.directive("pfAboutModalTransclude", function ($parse) {
4+
'use strict';
5+
return {
6+
link: function (scope, element, attrs) {
7+
element.append($parse(attrs.pfAboutModalTransclude)(scope));
8+
}
9+
};
10+
})
11+
.component('pfModalContent', {
12+
templateUrl: 'about-modal-template.html',
13+
bindings: {
14+
resolve: '<',
15+
close: '&',
16+
dismiss: '&'
17+
},
18+
controller: function () {
19+
'use strict';
20+
var $ctrl = this;
21+
22+
$ctrl.$onInit = function () {
23+
$ctrl.additionalInfo = $ctrl.resolve.additionalInfo;
24+
$ctrl.copyright = $ctrl.resolve.copyright;
25+
$ctrl.imgAlt = $ctrl.resolve.imgAlt;
26+
$ctrl.imgSrc = $ctrl.resolve.imgSrc;
27+
$ctrl.isOpen = $ctrl.resolve.isOpen;
28+
$ctrl.productInfo = $ctrl.resolve.productInfo;
29+
$ctrl.title = $ctrl.resolve.title;
30+
$ctrl.template = $ctrl.resolve.content;
31+
};
32+
}
33+
})
34+
.component('pfAboutModal', {
35+
bindings: {
36+
additionalInfo: '=?',
37+
copyright: '=?',
38+
close: "&onClose",
39+
imgAlt: '=?',
40+
imgSrc: '=?',
41+
isOpen: '<?',
42+
productInfo: '=',
43+
title: '=?'
44+
},
45+
templateUrl: 'modals/about-modal/about-modal.html',
46+
transclude: true,
47+
controller: function ($uibModal, $transclude) { //$uibModal, $transclude, $window
48+
'use strict';
49+
var ctrl = this;
50+
51+
// The ui-bootstrap modal only supports either template or templateUrl as a way to specify the content.
52+
// When the content is retrieved, it is compiled and linked against the provided scope by the $uibModal service.
53+
// Unfortunately, there is no way to provide transclusion there.
54+
//
55+
// The solution below embeds a placeholder directive (i.e., pfAboutModalTransclude) to append the transcluded DOM.
56+
// The transcluded DOM is from a different location than the modal, so it needs to be handed over to the
57+
// placeholder directive. Thus, we're passing the actual DOM, not the parsed HTML.
58+
ctrl.openModal = function () {
59+
$uibModal.open({
60+
component: 'pfModalContent',
61+
resolve: {
62+
content: function () {
63+
var transcludedContent;
64+
$transclude(function (clone) {
65+
transcludedContent = clone;
66+
});
67+
return transcludedContent;
68+
},
69+
additionalInfo: function () {
70+
return ctrl.additionalInfo;
71+
},
72+
copyright: function () {
73+
return ctrl.copyright;
74+
},
75+
close: function () {
76+
return ctrl.close;
77+
},
78+
imgAlt: function () {
79+
return ctrl.imgAlt;
80+
},
81+
imgSrc: function () {
82+
return ctrl.imgSrc;
83+
},
84+
isOpen: function () {
85+
return ctrl.isOpen;
86+
},
87+
productInfo: function () {
88+
return ctrl.productInfo;
89+
},
90+
title: function () {
91+
return ctrl.title;
92+
}
93+
}
94+
})
95+
.result.then(
96+
function () {
97+
ctrl.close(); // closed
98+
},
99+
function () {
100+
ctrl.close(); // dismissed
101+
}
102+
);
103+
};
104+
ctrl.$onInit = function () {
105+
if (ctrl.isOpen === undefined) {
106+
ctrl.isOpen = false;
107+
}
108+
};
109+
110+
ctrl.$onChanges = function (changesObj) {
111+
if (changesObj.isOpen && changesObj.isOpen.currentValue === true) {
112+
ctrl.openModal();
113+
}
114+
};
115+
}
116+
});

src/modals/examples/about-modal.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @ngdoc directive
3+
* @name patternfly.modals.component:pfAboutModal
4+
* @restrict E
5+
*
6+
* @description
7+
* Component for rendering modal windows.
8+
*
9+
* @param {string=} additionalInfo Text explaining the version or copyright
10+
* @param {string=} copyright Product copyright information
11+
* @param {string=} imgAlt The alt text for the corner grahpic
12+
* @param {string=} imgSrc The source for the corner grahpic
13+
* @param {boolean=} isOpen Flag indicating that the modal should be opened
14+
* @param {function=} onClose Function to call when modal is closed
15+
* @param {object=} productInfo data for the modal:<br/>
16+
* <ul style='list-style-type: none'>
17+
* <li>.product - the product label
18+
* <li>.version - the product version
19+
* </ul>
20+
* @param {string=} title The product title for the modal
21+
*
22+
* @example
23+
<example module="patternfly.modals">
24+
<file name="index.html">
25+
<div ng-controller="ModalCtrl">
26+
<button ng-click="open()" class="btn btn-default">Launch About Modal</button>
27+
<pf-about-modal is-open="isOpen" on-close="onClose()" additional-info="additionalInfo"
28+
product-info="productInfo" title="title" copyright="copyright" img-alt="imgAlt" img-src="imgSrc"></pf-about-modal>
29+
</div>
30+
</file>
31+
<file name="script.js">
32+
angular.module('patternfly.modals').controller('ModalCtrl', function ($scope) {
33+
$scope.additionalInfo = "Donec consequat dignissim neque, sed suscipit quam egestas in. Fusce bibendum " +
34+
"laoreet lectus commodo interdum. Vestibulum odio ipsum, tristique et ante vel, iaculis placerat nulla. " +
35+
"Suspendisse iaculis urna feugiat lorem semper, ut iaculis risus tempus.";
36+
$scope.copyright = "Trademark and Copyright Information";
37+
$scope.imgAlt = "Patternfly Symbol";
38+
$scope.imgSrc = "img/logo-alt.svg";
39+
$scope.title = "Product Title";
40+
$scope.productInfo = [
41+
{ name: 'Version', value: '1.0.0.0.20160819142038_51be77c' },
42+
{ name: 'Server Name', value: 'Localhost' },
43+
{ name: 'User Name', value: 'admin' },
44+
{ name: 'User Role', value: 'Administrator' }];
45+
$scope.open = function () {
46+
$scope.isOpen = true;
47+
};
48+
$scope.onClose = function() {
49+
$scope.isOpen = false;
50+
};
51+
});
52+
</file>
53+
</example>
54+
*/
55+

0 commit comments

Comments
 (0)