Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(modal): Fix use of inline styles for Content Security Policy #310

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
restrict: 'EA',
scope: {
index: '@',
animate: '='
animate: '=',
mmTop: '@'
},
replace: true,
transclude: true,
templateUrl: 'template/modal/window.html',
link: function (scope, element, attrs) {
scope.windowClass = attrs.windowClass || '';

// Set the `top` style using element.css to avoid Content Security Policy
// issues when using inline-styles
if (scope.mmTop) {
element.css('top', scope.mmTop);
element.css('visibility', 'visible');
}

$timeout(function () {
// trigger CSS transitions
scope.animate = true;
Expand Down Expand Up @@ -241,18 +249,21 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
}

// Create a faux modal div just to measure its
// distance to top
var faux = angular.element('<div class="reveal-modal" style="z-index:-1""></div>');
// distance to top. Note that we set the style using element.css()
// rather than using inline style="..." to avoid issue with Content Security Policy
var faux = angular.element('<div class="reveal-modal"></div>');
faux.css("z-index", "-1");
parent.append(faux[0]);
cssTop = parseInt($window.getComputedStyle(faux[0]).top) || 0;
var openAt = calculateModalTop(faux, cssTop);
faux.remove();

var angularDomEl = angular.element('<div modal-window style="visibility: visible; top:' + openAt +'px;"></div>')
var angularDomEl = angular.element('<div modal-window></div>')
.attr({
'window-class': modal.windowClass,
'index': openedWindows.length() - 1,
'animate': 'animate'
'animate': 'animate',
'mm-top': '' + openAt + 'px' // Pass the top position to modal-window directive
});
angularDomEl.html(modal.content);

Expand Down