Skip to content

Commit

Permalink
Merge pull request #28 from adriaanzon/main
Browse files Browse the repository at this point in the history
Don't render script tag when JavaScript check is disabled
  • Loading branch information
lukeraymonddowning authored Mar 17, 2021
2 parents 9eee0fc + f1fab10 commit 5e9465d
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/Views/Honey.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ public function __construct(InputNameSelector $inputNameSelector)
public function render()
{
return <<<'blade'
@once
<script>
window.addEventListener('load', () => {
setTimeout(() => {
document.querySelectorAll('input[data-purpose="{{ $inputNameSelector->getJavascriptInputName() }}"]')
.forEach(input => {
if (input.value.length > 0) {
return;
}
input.value = "{{ $javascriptValue() }}";
input.dispatchEvent(new Event('change'));
});
}, {{ $javascriptTimeout() }})
});
</script>
@endonce
@if (in_array(\Lukeraymonddowning\Honey\Checks\JavascriptInputFilledCheck::class, config('honey.checks')))
@once
<script>
window.addEventListener('load', () => {
setTimeout(() => {
document.querySelectorAll('input[data-purpose="{{ $inputNameSelector->getJavascriptInputName() }}"]')
.forEach(input => {
if (input.value.length > 0) {
return;
}
input.value = "{{ $javascriptValue() }}";
input.dispatchEvent(new Event('change'));
});
}, {{ $javascriptTimeout() }})
});
</script>
@endonce
@endif
<div style="display: @isset($attributes['debug']) block @else none @endisset;">
<input wire:model.lazy.defer="honeyInputs.{{ $inputNameSelector->getPresentButEmptyInputName() }}" name="{{ $inputNameSelector->getPresentButEmptyInputName() }}" value="">
<input wire:model.lazy.defer="honeyInputs.{{ $inputNameSelector->getTimeOfPageLoadInputName() }}" name="{{ $inputNameSelector->getTimeOfPageLoadInputName() }}" value="{{ $timeOfPageLoadValue() }}">
Expand All @@ -63,4 +65,4 @@ public function javascriptTimeout()
{
return config('honey.minimum_time_passed') * 1000;
}
}
}

0 comments on commit 5e9465d

Please sign in to comment.