-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from magmodules/release/2.1.8
Release/2.1.8
- Loading branch information
Showing
5 changed files
with
120 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,74 @@ | ||
<?php | ||
|
||
use Magento\Framework\View\Element\Template; | ||
use Magento\Framework\View\Helper\SecureHtmlRenderer; | ||
use Magmodules\Sooqr\ViewModel\Search; | ||
use Magento\Framework\Escaper; | ||
|
||
/** | ||
* @var \Magento\Framework\View\Element\Template $block | ||
* @var \Magmodules\Sooqr\ViewModel\Search $viewModel | ||
* @var Template $block | ||
* @var Search $viewModel | ||
* @var SecureHtmlRenderer $secureRenderer | ||
* @var Escaper $escaper | ||
*/ | ||
$viewModel = $block->getData('view_model'); | ||
|
||
if (!$viewModel->isSearchEnabled()) { | ||
return; | ||
} | ||
|
||
if ($viewModel->getLoaderType() == 'custom'): | ||
$scriptString = ' | ||
(function() { | ||
var ws = document.createElement(\'script\'); ws.type = \'text/javascript\'; ws.async = true; | ||
ws.src = (\'https:\' === document.location.protocol ? \'https://\' : \'http://\') | ||
+ \'' . $escaper->escapeUrl($viewModel->getSooqrScriptUri()) . '\'; | ||
var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ws, s); | ||
})();'; | ||
else: | ||
$scriptString = ' | ||
var _wssq = _wssq || []; | ||
_wssq.push([\'_load\', {\'suggest\': ' . /* @noEscape */ $viewModel->getSooqrOptions() . '}]); | ||
_wssq.push([\'suggest._setPosition\', \'screen-middle\']); | ||
_wssq.push([\'suggest._setLocale\', \'' . $escaper->escapeHtml($viewModel->getSooqrLanguage()) .'\']);'; | ||
|
||
if ($viewModel->isTrackingEnabled()): | ||
$scriptString .= ' | ||
(function() { | ||
var ws = document.createElement(\'script\'); ws.type = \'text/javascript\'; ws.async = true; | ||
ws.src = (\'https:\' == document.location.protocol ? \'https://\' : \'http://\') | ||
+ \'' . $escaper->escapeUrl($viewModel->getSooqrInsightsUri()) . '\'; | ||
var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ws, s); | ||
})();'; | ||
endif; | ||
|
||
$scriptString .= ' | ||
(function () { | ||
var ws = document.createElement(\'script\'); | ||
ws.type = \'text/javascript\'; | ||
ws.async = true; | ||
ws.src = (\'https:\' === document.location.protocol ? \'https://\' : \'http://\') | ||
+ \'' . $escaper->escapeUrl($viewModel->getSooqrScriptUri()) . '\'; | ||
var s = document.getElementsByTagName(\'script\')[0]; | ||
s.parentNode.insertBefore(ws, s); | ||
})();'; | ||
endif; | ||
|
||
// @phpstan-ignore-next-line | ||
if (isset($secureRenderer)) { | ||
// phpcs:ignore | ||
echo /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false); | ||
} else { | ||
echo /* @noEscape */ '<script>' . $scriptString . '</script>'; | ||
} | ||
?> | ||
<?php if ($viewModel->isSearchEnabled()): ?> | ||
<?php if ($viewModel->getLoaderType() == 'custom'): ?> | ||
<script> | ||
(function() { | ||
var ws = document.createElement('script'); ws.type = 'text/javascript'; ws.async = true; | ||
ws.src = ('https:' === document.location.protocol ? 'https://' : 'http://') | ||
+ '<?= $block->escapeUrl($viewModel->getSooqrScriptUri()) ?>'; | ||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ws, s); | ||
})(); | ||
</script> | ||
<?php else: ?> | ||
<script> | ||
var _wssq = _wssq || []; | ||
_wssq.push(['_load', {'suggest': <?= /* @noEscape */ $viewModel->getSooqrOptions() ?>}]); | ||
_wssq.push(['suggest._setPosition', 'screen-middle']); | ||
_wssq.push(['suggest._setLocale', '<?= $block->escapeHtml($viewModel->getSooqrLanguage()) ?>']); | ||
<?php if ($viewModel->isTrackingEnabled()): ?> | ||
(function() { | ||
var ws = document.createElement('script'); ws.type = 'text/javascript'; ws.async = true; | ||
ws.src = ('https:' == document.location.protocol ? 'https://' : 'http://') | ||
+ '<?= $block->escapeUrl($viewModel->getSooqrInsightsUri()) ?>'; | ||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ws, s); | ||
})(); | ||
<?php endif; ?> | ||
(function () { | ||
var ws = document.createElement('script'); | ||
ws.type = 'text/javascript'; | ||
ws.async = true; | ||
ws.src = ('https:' === document.location.protocol ? 'https://' : 'http://') | ||
+ '<?= $block->escapeUrl($viewModel->getSooqrScriptUri()) ?>'; | ||
var s = document.getElementsByTagName('script')[0]; | ||
s.parentNode.insertBefore(ws, s); | ||
})(); | ||
</script> | ||
<?php endif; ?> | ||
<?php if ($viewModel->isAjaxAddToCartEnabled()): ?> | ||
<script type="text/x-magento-init"> | ||
{ | ||
"*": { | ||
"Magmodules_Sooqr/js/add-to-cart": {} | ||
} | ||
|
||
<?php if ($viewModel->isAjaxAddToCartEnabled()): ?> | ||
<script type="text/x-magento-init"> | ||
{ | ||
"*": { | ||
"Magmodules_Sooqr/js/add-to-cart": {} | ||
} | ||
</script> | ||
<?php endif; ?> | ||
<?php endif; ?> | ||
} | ||
</script> | ||
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters