Skip to content

Commit

Permalink
Added Nonce to inline script
Browse files Browse the repository at this point in the history
Safari blocks inline script
  • Loading branch information
timpea-splat authored and cblanc committed Jun 17, 2024
1 parent 2a61e34 commit 0ce47ee
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions view/frontend/templates/store.phtml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php
$helper = $this->helper('Idealpostcodes\Ukaddresssearch\Helper\Data'); ?>

<script type="text/javascript" name="Ideal_Postcodes">
document.addEventListener('DOMContentLoaded', function() {
var apiKey = "<?php echo $helper->getConfig('api_key'); ?>";
var postcodeLookup = <?php echo $helper->getConfig('postcodeLookup'); ?>;
var autocomplete = <?php echo $helper->getConfig('addressAutocomplete'); ?>;
var populateOrganisation = <?php echo $helper->getConfig('populateOrganisation'); ?>;
var hoistCountry = <?php echo $helper->getConfig('hoistCountryField'); ?>;
var populateCounty = <?php echo $helper->getConfig('requireCounty'); ?>;
var autocompleteOverride = <?php echo $helper->getConfig('autocompleteOverride'); ?>;
var postcodeLookupOverride = <?php echo $helper->getConfig('postcodeLookupOverride'); ?>;
var enabled = <?php echo $helper->getConfig('enabled'); ?>;
var customFields = <?php echo trim(preg_replace('/\r|\n/', '', $helper->getConfig('customFields'))); ?>;
<?php
$script = '
document.addEventListener(\'DOMContentLoaded\', function() {
var apiKey = "' . $helper->getConfig('api_key') . '";
var postcodeLookup = ' . $helper->getConfig('postcodeLookup') . ';
var autocomplete = ' . $helper->getConfig('addressAutocomplete') . ';
var populateOrganisation = ' . $helper->getConfig('populateOrganisation') . ';
var hoistCountry = ' . $helper->getConfig('hoistCountryField') . ';
var populateCounty = ' . $helper->getConfig('requireCounty') . ';
var autocompleteOverride = ' . $helper->getConfig('autocompleteOverride') . ';
var postcodeLookupOverride = ' . $helper->getConfig('postcodeLookupOverride') . ';
var enabled = ' . $helper->getConfig('enabled') . ';
var customFields = ' . trim(preg_replace("/\r|\n/", "", $helper->getConfig('customFields'))) . ';
// Exit early if disabled
if (enabled === false) return;
window.idpcConfig = {
Expand All @@ -28,4 +29,6 @@ document.addEventListener('DOMContentLoaded', function() {
};
window.idpcStart();
});
</script>
';
?>
<?= $secureRenderer->renderTag('script', [], $script, false); ?>

0 comments on commit 0ce47ee

Please sign in to comment.