Skip to content

Commit

Permalink
Don't render script tag when JavaScript check is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriaan Zonnenberg authored Jan 14, 2021
1 parent 9eee0fc commit f1fab10
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 f1fab10

Please sign in to comment.