|
| 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 | + }); |
0 commit comments