Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2863f04

Browse files
committed
Avoid Content Security Policy violation
The setAttribute('style', foo) usage was violating the "child-src" CSP directive when the directive source is set to "self". This is functionally equivalent but avoids the violation.
1 parent ccc6ef1 commit 2863f04

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

intro.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -954,10 +954,10 @@
954954
}
955955

956956
//set new position to helper layer
957-
helperLayer.setAttribute('style', 'width: ' + (elementPosition.width + widthHeightPadding) + 'px; ' +
957+
helperLayer.style.cssText = 'width: ' + (elementPosition.width + widthHeightPadding) + 'px; ' +
958958
'height:' + (elementPosition.height + widthHeightPadding) + 'px; ' +
959959
'top:' + (elementPosition.top - widthHeightPadding / 2) + 'px;' +
960-
'left: ' + (elementPosition.left - widthHeightPadding / 2) + 'px;');
960+
'left: ' + (elementPosition.left - widthHeightPadding / 2) + 'px;';
961961

962962
}
963963
}
@@ -1078,7 +1078,7 @@
10781078
oldReferenceLayer.querySelector('.introjs-bullets li > a.active').className = '';
10791079
oldReferenceLayer.querySelector('.introjs-bullets li > a[data-stepnumber="' + targetElement.step + '"]').className = 'active';
10801080
}
1081-
oldReferenceLayer.querySelector('.introjs-progress .introjs-progressbar').setAttribute('style', 'width:' + _getProgress.call(self) + '%;');
1081+
oldReferenceLayer.querySelector('.introjs-progress .introjs-progressbar').style.cssText = 'width:' + _getProgress.call(self) + '%;';
10821082
oldReferenceLayer.querySelector('.introjs-progress .introjs-progressbar').setAttribute('aria-valuenow', _getProgress.call(self));
10831083

10841084
//show the tooltip
@@ -1172,7 +1172,7 @@
11721172
progressBar.setAttribute('aria-valuemin', 0);
11731173
progressBar.setAttribute('aria-valuemax', 100);
11741174
progressBar.setAttribute('aria-valuenow', _getProgress.call(this));
1175-
progressBar.setAttribute('style', 'width:' + _getProgress.call(this) + '%;');
1175+
progressBar.style.cssText = 'width:' + _getProgress.call(this) + '%;';
11761176

11771177
progressLayer.appendChild(progressBar);
11781178

@@ -1622,13 +1622,13 @@
16221622
//check if the target element is body, we should calculate the size of overlay layer in a better way
16231623
if (!targetElm.tagName || targetElm.tagName.toLowerCase() === 'body') {
16241624
styleText += 'top: 0;bottom: 0; left: 0;right: 0;position: fixed;';
1625-
overlayLayer.setAttribute('style', styleText);
1625+
overlayLayer.style.cssText = styleText;
16261626
} else {
16271627
//set overlay layer position
16281628
var elementPosition = _getOffset(targetElm);
16291629
if (elementPosition) {
16301630
styleText += 'width: ' + elementPosition.width + 'px; height:' + elementPosition.height + 'px; top:' + elementPosition.top + 'px;left: ' + elementPosition.left + 'px;';
1631-
overlayLayer.setAttribute('style', styleText);
1631+
overlayLayer.style.cssText = styleText;
16321632
}
16331633
}
16341634

@@ -1642,7 +1642,7 @@
16421642

16431643
window.setTimeout(function() {
16441644
styleText += 'opacity: ' + self._options.overlayOpacity.toString() + ';';
1645-
overlayLayer.setAttribute('style', styleText);
1645+
overlayLayer.style.cssText = styleText;
16461646
}, 10);
16471647

16481648
return true;

0 commit comments

Comments
 (0)