Skip to content

Commit

Permalink
fix(inline-script): Fix problem with inline script tag in safari
Browse files Browse the repository at this point in the history
  • Loading branch information
mfilip committed Jun 18, 2024
1 parent 0ce47ee commit ca601e0
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions view/adminhtml/templates/admin.phtml
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
<?php /** @var Magento\Framework\View\TemplateEngine\Php $this */
$helper = $this->helper('Idealpostcodes\Ukaddresssearch\Helper\Data');

$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 autocomplete = <?php echo $helper->getAdminConfig('addressAutocomplete'); ?>;
var populateOrganisation = <?php echo $helper->getConfig('populateOrganisation'); ?>;
var populateCounty = <?php echo $helper->getConfig('requireCounty'); ?>;
var enabled = <?php echo $helper->getConfig('enabled'); ?>;
var customFields = <?php echo trim(preg_replace('/\r|\n/', '',$helper->getConfig('customFields'))); ?>;

$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 = {
apiKey: apiKey,
postcodeLookup: false,
postcodeLookup: postcodeLookup,
autocomplete: autocomplete,
populateCounty: populateCounty,
populateOrganisation: populateOrganisation,
hoistCountry: false,
hoistCountry: hoistCountry,
autocompleteOverride: autocompleteOverride,
postcodeLookupOverride: postcodeLookupOverride,
customFields: customFields
};

if (window.idpcStart) window.idpcStart();
window.idpcStart();
});
</script>
';

$secureRenderer->renderTag('script', [], $script, false);
?>

0 comments on commit ca601e0

Please sign in to comment.