1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

remove inline fallback code for CSP

This commit is contained in:
Kyle Spearrin
2017-06-17 10:08:47 -04:00
parent 00007c20a7
commit ce1352cb9f
4 changed files with 49 additions and 12 deletions

View File

@@ -43,12 +43,9 @@
<script src="https://js.stripe.com/v2/"></script>
<!-- @if true !>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<meta name="x-stylesheet-test-bs" content="" class="invisible" />
<script>!function(a,b,c){var d,e=document,f=e.getElementsByTagName('SCRIPT'),g=f[f.length-1].previousElementSibling,h=e.defaultView&&e.defaultView.getComputedStyle?e.defaultView.getComputedStyle(g):g.currentStyle;if(h&&h[a]!==b)for(d=0;d<c.length;d++)e.write('<link rel="stylesheet" href="'+c[d]+'"/>')}('visibility','hidden',['lib\/bootstrap\/css\/bootstrap.min.css?v=<!-- @echo cacheTag !>']);</script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<meta name="x-stylesheet-test-fa" content="" class="fa" />
<script>!function(a,b,c){var d,e=document,f=e.getElementsByTagName('SCRIPT'),g=f[f.length-1].previousElementSibling,h=e.defaultView&&e.defaultView.getComputedStyle?e.defaultView.getComputedStyle(g):g.currentStyle;if(h&&h[a]!==b)for(d=0;d<c.length;d++)e.write('<link rel="stylesheet" href="'+c[d]+'"/>')}('font-family','FontAwesome',['lib\/font-awesome\/css\/font-awesome.min.css?v=<!-- @echo cacheTag !>']);</script>
<meta name="x-stylesheet-test" content="" class="fa invisible" />
<script src="js/fallback-styles.min.js?v=<!-- @echo cacheTag !>"></script>
<link rel="stylesheet" href="css/vault.min.css?v=<!-- @echo cacheTag !>" />
<!-- @endif -->
@@ -66,13 +63,9 @@
<!-- @if true !>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>(window.jQuery||document.write('<script src="lib\/jquery\/jquery.min.js?v=<!-- @echo cacheTag !>"><\/script>'));</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>((window.jQuery&&window.jQuery.fn&&window.jQuery.fn.modal)||document.write('<script src="lib\/bootstrap\/js\/bootstrap.min.js?v=<!-- @echo cacheTag !>"><\/script>'));</script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular.min.js"></script>
<script>(window.angular||document.write('<script src="lib\/angular\/angular.min.js?v=<!-- @echo cacheTag !>"><\/script>'));</script>
<script src="js/fallback-scripts.min.js?v=<!-- @echo cacheTag !>"></script>
<script src="js/lib.min.js?v=<!-- @echo cacheTag !>"></script>
<script src="js/bw.min.js?v=<!-- @echo cacheTag !>"></script>

View File

@@ -0,0 +1,9 @@
function loadScriptIfMissing(condition, path) {
if (!condition) {
document.write('<script src="' + path + '?v=' + cacheTag + '"><\/script>');
}
}
loadScriptIfMissing(window.jQuery, 'lib\/jquery\/jquery.min.js');
loadScriptIfMissing(window.jQuery && window.jQuery.fn && window.jQuery.fn.modal, 'lib\/bootstrap\/js\/bootstrap.min.js');
loadScriptIfMissing(window.angular, 'lib\/angular\/angular.min.js');

17
src/js/fallback-styles.js Normal file
View File

@@ -0,0 +1,17 @@
var cacheTag = '/* @echo cacheTag */' || '';
function loadStylesheetIfMissing(property, value, paths) {
var scripts = document.getElementsByTagName('SCRIPT'),
siblings = scripts[scripts.length - 1].previousElementSibling,
meta = document.defaultView && document.defaultView.getComputedStyle ?
document.defaultView.getComputedStyle(siblings) : siblings.currentStyle;
if (meta && meta[property] !== value) {
for (var i = 0; i < paths.length; i++) {
document.write('<link rel="stylesheet" href="' + paths[i] + '?v=' + cacheTag + '" />');
}
}
}
loadStylesheetIfMissing('visibility', 'hidden', ['lib\/bootstrap\/css\/bootstrap.min.css']);
loadStylesheetIfMissing('fontFamily', 'FontAwesome', ['lib\/font-awesome\/css\/font-awesome.min.css']);