Skip to content

Commit 96d3d8d

Browse files
ldurswSamuell1
authored andcommitted
fix(MdProgressSpinner): fix CSP error (#1850)
* MdProgressSpinner: Replace CSS with variables * Delete MdProgressSpinnerAnimation.js * MdProgressSpinner: Fix style in Firefox * Change getElementsByClassName to $refs
1 parent 87cf617 commit 96d3d8d

File tree

2 files changed

+101
-129
lines changed

2 files changed

+101
-129
lines changed

src/components/MdProgress/MdProgressSpinner/MdProgressSpinner.vue

+101-46
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
preserveAspectRatio="xMidYMid meet"
77
focusable="false"
88
:viewBox="`0 0 ${mdDiameter} ${mdDiameter}`"
9-
:style="svgStyles">
10-
<circle class="md-progress-spinner-circle" cx="50%" cy="50%" :r="circleRadius" :style="circleStyles"></circle>
9+
ref="md-progress-spinner-draw">
10+
<circle class="md-progress-spinner-circle" cx="50%" cy="50%" :r="circleRadius" ref="md-progress-spinner-circle"></circle>
1111
</svg>
1212
</div>
1313
</transition>
@@ -16,7 +16,6 @@
1616
<script>
1717
import MdComponent from 'core/MdComponent'
1818
import MdPropValidator from 'core/utils/MdPropValidator'
19-
import INDETERMINATE_ANIMATION_TEMPLATE from './MdProgressSpinnerAnimation'
2019
2120
const MdProgressSpinner = {
2221
styleTag: null,
@@ -72,22 +71,6 @@
7271
['md-' + this.mdMode]: true
7372
}
7473
},
75-
svgStyles () {
76-
const size = `${this.mdDiameter}px`
77-
78-
return {
79-
width: size,
80-
height: size
81-
}
82-
},
83-
circleStyles () {
84-
return {
85-
'stroke-dashoffset': this.circleStrokeDashOffset,
86-
'stroke-dasharray': this.circleStrokeDashArray,
87-
'stroke-width': this.circleStrokeWidth,
88-
'animation-name': 'md-progress-spinner-stroke-rotate-' + this.mdDiameter
89-
}
90-
},
9174
circleRadius () {
9275
return (this.mdDiameter - this.mdStroke) / 2
9376
},
@@ -114,40 +97,29 @@
11497
},
11598
watch: {
11699
mdDiameter () {
117-
this.attachStyleTag()
100+
this.attachSvgStyle()
101+
this.attachCircleStyle()
118102
}
119103
},
120104
methods: {
121-
getAnimationCSS () {
122-
return INDETERMINATE_ANIMATION_TEMPLATE
123-
.replace(/START_VALUE/g, `${0.95 * this.circleCircumference}`)
124-
.replace(/END_VALUE/g, `${0.2 * this.circleCircumference}`)
125-
.replace(/DIAMETER/g, `${this.mdDiameter}`);
105+
attachSvgStyle () {
106+
const svg = this.$refs['md-progress-spinner-draw']
107+
const size = `${this.mdDiameter}px`
108+
svg.style.width = size
109+
svg.style.height = size
126110
},
127-
attachStyleTag () {
128-
let styleTag = MdProgressSpinner.styleTag
129-
130-
if (!styleTag) {
131-
styleTag = document.getElementById('md-progress-spinner-styles')
132-
}
133-
134-
if (!styleTag) {
135-
styleTag = document.createElement('style')
136-
137-
styleTag.id = 'md-progress-spinner-styles'
138-
document.head.appendChild(styleTag)
139-
MdProgressSpinner.styleTag = styleTag
140-
}
141-
142-
if (styleTag && styleTag.sheet) {
143-
styleTag.sheet.insertRule(this.getAnimationCSS(), 0)
144-
}
145-
146-
MdProgressSpinner.diameters.add(this.mdDiameter)
111+
attachCircleStyle () {
112+
const circle = this.$refs['md-progress-spinner-circle']
113+
circle.style.strokeDashoffset = this.circleStrokeDashOffset
114+
circle.style.strokeDasharray = this.circleStrokeDashArray
115+
circle.style.strokeWidth = this.circleStrokeWidth;
116+
circle.style.setProperty('--md-progress-spinner-start-value', 0.95 * this.circleCircumference)
117+
circle.style.setProperty('--md-progress-spinner-end-value', 0.2 * this.circleCircumference)
147118
}
148119
},
149120
mounted () {
150-
this.attachStyleTag()
121+
this.attachSvgStyle()
122+
this.attachCircleStyle()
151123
}
152124
})
153125
</script>
@@ -197,6 +169,88 @@
197169
transform: rotate(4680deg)
198170
}
199171
}
172+
173+
@keyframes md-progress-spinner-stroke-rotate {
174+
0% {
175+
stroke-dashoffset: var(--md-progress-spinner-start-value);
176+
transform: rotate(0);
177+
}
178+
179+
12.5% {
180+
stroke-dashoffset: var(--md-progress-spinner-end-value);
181+
transform: rotate(0);
182+
}
183+
184+
12.51% {
185+
stroke-dashoffset: var(--md-progress-spinner-end-value);
186+
transform: rotateX(180deg) rotate(72.5deg);
187+
}
188+
189+
25% {
190+
stroke-dashoffset: var(--md-progress-spinner-start-value);
191+
transform: rotateX(180deg) rotate(72.5deg);
192+
}
193+
194+
25.1% {
195+
stroke-dashoffset: var(--md-progress-spinner-start-value);
196+
transform: rotate(270deg);
197+
}
198+
199+
37.5% {
200+
stroke-dashoffset: var(--md-progress-spinner-end-value);
201+
transform: rotate(270deg);
202+
}
203+
204+
37.51% {
205+
stroke-dashoffset: var(--md-progress-spinner-end-value);
206+
transform: rotateX(180deg) rotate(161.5deg);
207+
}
208+
209+
50% {
210+
stroke-dashoffset: var(--md-progress-spinner-start-value);
211+
transform: rotateX(180deg) rotate(161.5deg);
212+
}
213+
214+
50.01% {
215+
stroke-dashoffset: var(--md-progress-spinner-start-value);
216+
transform: rotate(180deg);
217+
}
218+
219+
62.5% {
220+
stroke-dashoffset: var(--md-progress-spinner-end-value);
221+
transform: rotate(180deg);
222+
}
223+
224+
62.51% {
225+
stroke-dashoffset: var(--md-progress-spinner-end-value);
226+
transform: rotateX(180deg) rotate(251.5deg);
227+
}
228+
229+
75% {
230+
stroke-dashoffset: var(--md-progress-spinner-start-value);
231+
transform: rotateX(180deg) rotate(251.5deg);
232+
}
233+
234+
75.01% {
235+
stroke-dashoffset: var(--md-progress-spinner-start-value);
236+
transform: rotate(90deg);
237+
}
238+
239+
87.5% {
240+
stroke-dashoffset: var(--md-progress-spinner-end-value);
241+
transform: rotate(90deg);
242+
}
243+
244+
87.51% {
245+
stroke-dashoffset: var(--md-progress-spinner-end-value);
246+
transform: rotateX(180deg) rotate(341.5deg);
247+
}
248+
249+
100% {
250+
stroke-dashoffset: var(--md-progress-spinner-start-value);
251+
transform: rotateX(180deg) rotate(341.5deg);
252+
}
253+
}
200254
201255
.md-progress-spinner {
202256
display: inline-flex;
@@ -217,6 +271,7 @@
217271
218272
.md-progress-spinner-circle {
219273
animation: 4s infinite $md-transition-stand-timing;
274+
animation-name: md-progress-spinner-stroke-rotate;
220275
}
221276
}
222277

src/components/MdProgress/MdProgressSpinner/MdProgressSpinnerAnimation.js

-83
This file was deleted.

0 commit comments

Comments
 (0)