Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inline-script): Fix problem with inline script tag in safari #536

Merged
merged 5 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,21 @@ public function usesAutocomplete(
);
}

public function populateOrganisation(
public function removeOrganisation(
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $storeId = null
) {
return $this->scopeConfig->isSetFlag(
'idealpostcodes/settings/populate_organisation',
'idealpostcodes/settings/remove_organisation_store',
$scope,
$storeId
);
}

public function removeOrganisationAdmin(
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $storeId = null
) {
return $this->scopeConfig->isSetFlag(
'idealpostcodes/settings/remove_organisation_admin',
$scope,
$storeId
);
Expand Down Expand Up @@ -210,7 +220,7 @@ public function toConfiguration(
'api_key' => $this->getApiKey($scope, $storeId),
'postcodeLookup' => $this->usesPostcodeLookup($scope, $storeId),
'addressAutocomplete' => $this->usesAutocomplete($scope, $storeId),
'populateOrganisation' => $this->populateOrganisation($scope, $storeId),
'removeOrganisation' => $this->removeOrganisation($scope, $storeId),
'hoistCountryField' => $this->hoistCountry($scope, $storeId),
'requireCounty' => $this->requireCounty($scope, $storeId),
'autocompleteOverride' => $this->getAutocompleteOverride($scope, $storeId),
Expand All @@ -229,9 +239,10 @@ public function toAdminConfiguration(
'enabled' => $this->isEnabled($scope),
'api_key' => $this->getApiKey($scope),
'addressAutocomplete' => $this->isEnabledAdminAutocomplete($scope),
'populateOrganisation' => $this->populateOrganisation($scope),
'removeOrganisation' => $this->removeOrganisationAdmin($scope),
'hoistCountryField' => $this->hoistCountry($scope),
'requireCounty' => $this->requireCounty($scope)
'requireCounty' => $this->requireCounty($scope),
"customFields" => $this->customFields($scope),
);
return $config;
}
Expand Down
51 changes: 34 additions & 17 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,6 @@
showInStore="1"
>
<label>Data</label>
<field
id="populate_organisation"
type="select"
translate="label,comment"
sortOrder="60"
showInDefault="1"
showInWebsite="1"
showInStore="1"
>
<label>Populate Organisation</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>idealpostcodes/settings/populate_organisation</config_path>
<comment>Fill the Company field based on selected address.</comment>
<depends>
<field id="enabled">1</field>
</depends>
</field>
<field
id="require_county"
type="select"
Expand Down Expand Up @@ -167,6 +150,23 @@
<field id="enabled">1</field>
</depends>
</field>
<field
id="remove_organisation_store"
type="select"
translate="label,comment"
sortOrder="90"
showInDefault="1"
showInWebsite="1"
showInStore="1"
>
<label>Remove Organisation</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>idealpostcodes/settings/remove_organisation_store</config_path>
<comment>Remove organisation name from first line of address.</comment>
<depends>
<field id="enabled">1</field>
</depends>
</field>
</group>
<group
id="store_admin_configuration"
Expand Down Expand Up @@ -196,6 +196,23 @@
<field id="enabled">1</field>
</depends>
</field>
<field
id="remove_organisation_admin"
type="select"
translate="label,comment"
sortOrder="90"
showInDefault="1"
showInWebsite="1"
showInStore="1"
>
<label>Remove Organisation</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>idealpostcodes/settings/remove_organisation_admin</config_path>
<comment>Remove organisation name from first line of address.</comment>
<depends>
<field id="enable_admin_integration">1</field>
</depends>
</field>
</group>
<group
id="admin"
Expand Down
3 changes: 2 additions & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<postcode_lookup>1</postcode_lookup>
<autocomplete>1</autocomplete>
<admin_autocomplete>1</admin_autocomplete>
<populate_organisation>1</populate_organisation>
<remove_organisation_store>0</remove_organisation_store>
<remove_organisation_admin>0</remove_organisation_admin>
<require_county>0</require_county>
<hoist_country>1</hoist_country>
<autocomplete_override>{}</autocomplete_override>
Expand Down
3 changes: 2 additions & 1 deletion lib/admin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { config } from "@ideal-postcodes/jsutil";
import { Config } from "./extension";

import { bind as orders } from "./admin-orders";
import { bind as ordersEdit } from "./admin-orders-edit";
Expand All @@ -8,5 +9,5 @@ import { bind as custom } from "./admin-custom";
window.idpcStart = () =>
[orders, customers, ordersEdit, custom].forEach((bind) => {
const conf = config();
if (conf) bind(conf);
if (conf) bind(conf as Config);
});
5 changes: 5 additions & 0 deletions lib/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { PostcodeLookup } from "@ideal-postcodes/postcode-lookup";

export interface Config extends BaseConfig {
hoistCountry?: boolean;
removeOrganisation: boolean;
customFields?: OutputFields[];
}

Expand Down Expand Up @@ -160,6 +161,8 @@ export const setupPostcodeLookup = (
checkKey: true,
context: "div.idpc_lookup",
outputFields,
removeOrganisation: config.removeOrganisation,
populateCounty: config.populateCounty,
selectStyle: {
"margin-top": "5px",
"margin-bottom": "5px",
Expand Down Expand Up @@ -223,6 +226,8 @@ export const setupAutocomplete = async (
{
apiKey: config.apiKey,
checkKey: true,
removeOrganisation: config.removeOrganisation,
populateCounty: config.populateCounty,
onLoaded() {
//@ts-expect-error
this.options.outputFields = getFields(outputFields, this.scope);
Expand Down
3 changes: 2 additions & 1 deletion lib/store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { config } from "@ideal-postcodes/jsutil";
import { Config } from "./extension";

import { bind as shipping } from "./shipping";
import { bind as billing } from "./billing";
Expand All @@ -9,6 +10,6 @@ import { bind as custom } from "./custom";
window.idpcStart = () => {
[shipping, billing, customer, multishipping, custom].forEach((bind) => {
const conf = config();
if (conf) bind(conf);
if (conf) bind(conf as Config);
});
};
77 changes: 50 additions & 27 deletions view/adminhtml/templates/admin.phtml
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
<?php /** @var Magento\Framework\View\TemplateEngine\Php $this */

$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'))); ?>;

// Exit early if disabled
if (enabled === false) return;
window.idpcConfig = {
apiKey: apiKey,
postcodeLookup: false,
autocomplete: autocomplete,
populateCounty: populateCounty,
populateOrganisation: populateOrganisation,
hoistCountry: false,
customFields: customFields
};

if (window.idpcStart) window.idpcStart();
});
</script>
$helper = $this->helper('Idealpostcodes\Ukaddresssearch\Helper\Data');
?>
<?php if(!isset($secureRenderer)) { ?>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var apiKey = "<?= $helper->getAdminConfig('api_key') ?>";
var autocomplete = <?= $helper->getAdminConfig('addressAutocomplete') ?>;
var removeOrganisation = <?= $helper->getAdminConfig('removeOrganisation') ?>;
var populateCounty = <?= $helper->getAdminConfig('requireCounty') ?>;
var enabled = <?= $helper->getAdminConfig('enabled') ?>;
var customFields = <?= trim(preg_replace("/\r|\n/", "", $helper->getAdminConfig('customFields'))) ?>;
// Exit early if disabled
if (enabled === false) return;
window.idpcConfig = {
apiKey: apiKey,
postcodeLookup: false,
autocomplete: autocomplete,
populateCounty: populateCounty,
removeOrganisation: removeOrganisation,
hoistCountry: false,
customFields: customFields
};
window.idpcStart();
});
</script>
<?php } else {
echo $secureRenderer->renderTag('script', [], '
document.addEventListener("DOMContentLoaded", function() {
var apiKey = "' . $helper->getAdminConfig('api_key') . '";
var autocomplete = ' . $helper->getAdminConfig('addressAutocomplete') . ';
var removeOrganisation = ' . $helper->getAdminConfig('removeOrganisation') . ';
var populateCounty = ' . $helper->getAdminConfig('requireCounty') . ';
var enabled = ' . $helper->getAdminConfig('enabled') . ';
var customFields = ' . trim(preg_replace("/\r|\n/", "", $helper->getAdminConfig('customFields'))) . ';
// Exit early if disabled
if (enabled === false) return;
window.idpcConfig = {
apiKey: apiKey,
postcodeLookup: false,
autocomplete: autocomplete,
populateCounty: populateCounty,
removeOrganisation: removeOrganisation,
hoistCountry: false,
customFields: customFields
};
window.idpcStart();
});
', false);
}
?>
2 changes: 1 addition & 1 deletion view/base/web/admin.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion view/base/web/binding.min.js

Large diffs are not rendered by default.

65 changes: 47 additions & 18 deletions view/frontend/templates/store.phtml
Original file line number Diff line number Diff line change
@@ -1,34 +1,63 @@
<?php
$helper = $this->helper('Idealpostcodes\Ukaddresssearch\Helper\Data'); ?>

<?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'))) . ';
$helper = $this->helper('Idealpostcodes\Ukaddresssearch\Helper\Data');
?>
<?php if(!isset($secureRenderer)) { ?>
<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 removeOrganisation = <?php echo $helper->getConfig('removeOrganisation'); ?>;
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'))); ?>;
// Exit early if disabled
if (enabled === false) return;
window.idpcConfig = {
apiKey: apiKey,
postcodeLookup: postcodeLookup,
autocomplete: autocomplete,
populateCounty: populateCounty,
populateOrganisation: populateOrganisation,
removeOrganisation: removeOrganisation,
hoistCountry: hoistCountry,
autocompleteOverride: autocompleteOverride,
postcodeLookupOverride: postcodeLookupOverride,
customFields: customFields
};
window.idpcStart();
});
';
</script>
<?php } else {
echo $secureRenderer->renderTag('script', [], '
document.addEventListener("DOMContentLoaded", function() {
var apiKey = "' . $helper->getConfig('api_key') . '";
var postcodeLookup = ' . $helper->getConfig('postcodeLookup') . ';
var autocomplete = ' . $helper->getConfig('addressAutocomplete') . ';
var removeOrganisation = ' . $helper->getConfig('removeOrganisation') . ';
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: postcodeLookup,
autocomplete: autocomplete,
populateCounty: populateCounty,
removeOrganisation: removeOrganisation,
hoistCountry: hoistCountry,
autocompleteOverride: autocompleteOverride,
postcodeLookupOverride: postcodeLookupOverride,
customFields: customFields
};
window.idpcStart();
});
', false);
}
?>
<?= $secureRenderer->renderTag('script', [], $script, false); ?>
Loading