Skip to content

Commit

Permalink
Fix wording and add a note explaining the sample
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrunel committed Feb 7, 2019
1 parent 0f3b844 commit 1a380ee
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/getting-started/integration.md
Expand Up @@ -85,9 +85,9 @@ require(['moment'], function() {
});
```

## Content-Security-Policy
## Content Security Policy

By default, Chart.js injects CSS directly into the DOM. For webpages secured using [Content-Security-Policy (CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy), this requires to allow `style-src 'unsafe-inline'`. For stricter CSP environments, where only `style-src 'self'` is allowed, the following CSS file needs to be manually added to your webpage:
By default, Chart.js injects CSS directly into the DOM. For webpages secured using [`Content-Security-Policy` (CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy), this requires to allow `style-src 'unsafe-inline'`. For stricter CSP environments, where only `style-src 'self'` is allowed, the following CSS file needs to be manually added to your webpage:

```html
<link rel="stylesheet" type="text/css" href="path/to/chartjs/dist/Chart.min.css">
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Expand Up @@ -29,7 +29,7 @@ module.exports = [
}),
optional({
include: ['moment']
}),
})
],
output: {
name: 'Chart',
Expand Down
17 changes: 16 additions & 1 deletion samples/advanced/content-security-policy.css
@@ -1,5 +1,20 @@
.content {
max-width: 640px;
margin: auto;
padding: 16px 32px;
padding: 1rem;
}

.note {
font-family: sans-serif;
color: #5050a0;
line-height: 1.4;
margin-bottom: 1rem;
padding: 1rem;
}

code {
background-color: #f5f5ff;
border: 1px solid #d0d0fa;
border-radius: 4px;
padding: 0.05rem 0.25rem;
}
5 changes: 5 additions & 0 deletions samples/advanced/content-security-policy.html
Expand Up @@ -14,6 +14,11 @@
</head>
<body>
<div class="content">
<div class="note">
In order to support a strict content security policy (<code>default-src 'self'</code>),
this page manually loads <code>Chart.min.css</code> and turns off the automatic style
injection by setting <code>Chart.platform.useExternalStylesheet = true;</code>.
</div>
<div class="wrapper">
<canvas id="chart-0"></canvas>
</div>
Expand Down
2 changes: 1 addition & 1 deletion samples/samples.js
Expand Up @@ -188,7 +188,7 @@
title: 'Progress bar',
path: 'advanced/progress-bar.html'
}, {
title: 'Content-Security-Policy',
title: 'Content Security Policy',
path: 'advanced/content-security-policy.html'
}]
}];
Expand Down
1 change: 0 additions & 1 deletion samples/style.css
@@ -1,4 +1,3 @@

@import url('https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900');

body, html {
Expand Down
5 changes: 0 additions & 5 deletions src/platforms/platform.dom.css
Expand Up @@ -2,17 +2,12 @@
* DOM element rendering detection
* https://davidwalsh.name/detect-node-insertion
*/
@-webkit-keyframes chartjs-render-animation {
from { opacity: 0.99; }
to { opacity: 1; }
}
@keyframes chartjs-render-animation {
from { opacity: 0.99; }
to { opacity: 1; }
}

.chartjs-render-monitor {
-webkit-animation: chartjs-render-animation 0.001s;
animation: chartjs-render-animation 0.001s;
}

Expand Down

0 comments on commit 1a380ee

Please sign in to comment.