Skip to content

Commit

Permalink
Release v0.8.0-csp.1
Browse files Browse the repository at this point in the history
Fixes some CSP issues.
See yalabot/angular-foundation#310
  • Loading branch information
farrago committed Aug 25, 2016
1 parent f95d572 commit 374b85b
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 34 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Pinecone, LLC"
},
"name": "angular-foundation",
"version": "0.8.0",
"version": "0.8.0-csp.1",
"main": ["./mm-foundation-tpls.js"],
"dependencies": {
"angular": ">=1.3.0"
Expand Down
40 changes: 29 additions & 11 deletions mm-foundation-tpls.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* angular-mm-foundation
* http://pineconellc.github.io/angular-foundation/
* https://github.com/farrago/angular-foundation-bower
* Version: 0.8.0 - 2015-10-13
* Version: 0.8.0-csp.1 - 2016-08-25
* License: MIT
* (c) Pinecone, LLC
*/
Expand Down Expand Up @@ -958,14 +958,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 @@ -1111,18 +1119,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 Expand Up @@ -2757,8 +2768,8 @@ angular.module("mm.foundation.topbar", ['mm.foundation.mediaQueries'])
angular.element($window).bind('scroll', onScroll);

scope.$on('$destroy', function() {
angular.element($window).unbind('scroll', onResize);
angular.element($window).unbind('resize', onScroll);
angular.element($window).unbind('resize', onResize);
angular.element($window).unbind('scroll', onScroll);
});

if (topbarContainer.hasClass('fixed')) {
Expand Down Expand Up @@ -3116,6 +3127,8 @@ angular.module('mm.foundation.typeahead', ['mm.foundation.position', 'mm.foundat

var appendToBody = attrs.typeaheadAppendToBody ? $parse(attrs.typeaheadAppendToBody) : false;

var focusFirst = originalScope.$eval(attrs.typeaheadFocusFirst) !== false;

//INTERNAL VARIABLES

//model setter executed upon match selection
Expand Down Expand Up @@ -3163,7 +3176,7 @@ angular.module('mm.foundation.typeahead', ['mm.foundation.position', 'mm.foundat
if (inputValue === modelCtrl.$viewValue && hasFocus) {
if (matches.length > 0) {

scope.activeIdx = 0;
scope.activeIdx = focusFirst ? 0 : -1;
scope.matches.length = 0;

//transform labels
Expand Down Expand Up @@ -3288,14 +3301,19 @@ angular.module('mm.foundation.typeahead', ['mm.foundation.position', 'mm.foundat
return;
}

// if there's nothing selected (i.e. focusFirst) and enter is hit, don't do anything
if (scope.activeIdx == -1 && (evt.which === 13 || evt.which === 9)) {
return;
}

evt.preventDefault();

if (evt.which === 40) {
scope.activeIdx = (scope.activeIdx + 1) % scope.matches.length;
scope.$digest();

} else if (evt.which === 38) {
scope.activeIdx = (scope.activeIdx ? scope.activeIdx : scope.matches.length) - 1;
scope.activeIdx = (scope.activeIdx > 0 ? scope.activeIdx : scope.matches.length) - 1;
scope.$digest();

} else if (evt.which === 13 || evt.which === 9) {
Expand Down
8 changes: 4 additions & 4 deletions mm-foundation-tpls.min.js

Large diffs are not rendered by default.

40 changes: 29 additions & 11 deletions mm-foundation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* angular-mm-foundation
* http://pineconellc.github.io/angular-foundation/
* https://github.com/farrago/angular-foundation-bower
* Version: 0.8.0 - 2015-10-13
* Version: 0.8.0-csp.1 - 2016-08-25
* License: MIT
* (c) Pinecone, LLC
*/
Expand Down Expand Up @@ -957,14 +957,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 @@ -1110,18 +1118,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 Expand Up @@ -2756,8 +2767,8 @@ angular.module("mm.foundation.topbar", ['mm.foundation.mediaQueries'])
angular.element($window).bind('scroll', onScroll);

scope.$on('$destroy', function() {
angular.element($window).unbind('scroll', onResize);
angular.element($window).unbind('resize', onScroll);
angular.element($window).unbind('resize', onResize);
angular.element($window).unbind('scroll', onScroll);
});

if (topbarContainer.hasClass('fixed')) {
Expand Down Expand Up @@ -3115,6 +3126,8 @@ angular.module('mm.foundation.typeahead', ['mm.foundation.position', 'mm.foundat

var appendToBody = attrs.typeaheadAppendToBody ? $parse(attrs.typeaheadAppendToBody) : false;

var focusFirst = originalScope.$eval(attrs.typeaheadFocusFirst) !== false;

//INTERNAL VARIABLES

//model setter executed upon match selection
Expand Down Expand Up @@ -3162,7 +3175,7 @@ angular.module('mm.foundation.typeahead', ['mm.foundation.position', 'mm.foundat
if (inputValue === modelCtrl.$viewValue && hasFocus) {
if (matches.length > 0) {

scope.activeIdx = 0;
scope.activeIdx = focusFirst ? 0 : -1;
scope.matches.length = 0;

//transform labels
Expand Down Expand Up @@ -3287,14 +3300,19 @@ angular.module('mm.foundation.typeahead', ['mm.foundation.position', 'mm.foundat
return;
}

// if there's nothing selected (i.e. focusFirst) and enter is hit, don't do anything
if (scope.activeIdx == -1 && (evt.which === 13 || evt.which === 9)) {
return;
}

evt.preventDefault();

if (evt.which === 40) {
scope.activeIdx = (scope.activeIdx + 1) % scope.matches.length;
scope.$digest();

} else if (evt.which === 38) {
scope.activeIdx = (scope.activeIdx ? scope.activeIdx : scope.matches.length) - 1;
scope.activeIdx = (scope.activeIdx > 0 ? scope.activeIdx : scope.matches.length) - 1;
scope.$digest();

} else if (evt.which === 13 || evt.which === 9) {
Expand Down
8 changes: 4 additions & 4 deletions mm-foundation.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "angular-foundation",
"version": "0.8.0",
"version": "0.8.0-csp.1",
"description": "Angular components for Foundation",
"author": "Pinecone, LLC",
"license": "MIT",
"homepage": "http://pineconellc.github.io/angular-foundation/",
"homepage": "https://github.com/farrago/angular-foundation",
"repository": {
"type": "git",
"url": "git://github.com/pineconellc/angular-foundation.git"
"url": "git@github.com:farrago/angular-foundation.git"
},
"keywords": [
"angular",
Expand Down

0 comments on commit 374b85b

Please sign in to comment.