Skip to content

Commit

Permalink
Added @lagoonScripts and @lagoonStyles directives
Browse files Browse the repository at this point in the history
Those will replace the inline scripts and hopefully generate cleaner code
  • Loading branch information
daredloco committed Aug 7, 2023
1 parent cf7eb97 commit 6c322c9
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 108 deletions.
15 changes: 1 addition & 14 deletions resources/views/livewire/area-chart.blade.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
<div>
@once
@push('styles')
<style>
svg > g > g.google-visualization-tooltip { pointer-events: none }
</style>
@endpush
@push('headerScripts')
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart'], 'language': '{{ $localization }}'});
</script>
@endpush
@endonce

{{-- Add @lagoonScripts('en') --}}
<script type="text/javascript">
google.charts.setOnLoadCallback(drawChart{{ $chartId }});
Expand Down
15 changes: 1 addition & 14 deletions resources/views/livewire/bar-chart.blade.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
<div>
@once
@push('styles')
<style>
svg > g > g.google-visualization-tooltip { pointer-events: none }
</style>
@endpush
@push('headerScripts')
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart'], 'language': '{{ $localization }}'});
</script>
@endpush
@endonce

{{-- Add @lagoonScripts('en') --}}
<script type="text/javascript">
google.charts.setOnLoadCallback(drawChart{{ $chartId }});
Expand Down
15 changes: 1 addition & 14 deletions resources/views/livewire/candlestick-chart.blade.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
<div>
@once
@push('styles')
<style>
svg > g > g.google-visualization-tooltip { pointer-events: none }
</style>
@endpush
@push('headerScripts')
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart'], 'language': '{{ $localization }}'});
</script>
@endpush
@endonce

{{-- Add @lagoonScripts('en') --}}
<script type="text/javascript">
google.charts.setOnLoadCallback(drawChart{{ $chartId }});
Expand Down
15 changes: 1 addition & 14 deletions resources/views/livewire/column-chart.blade.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
<div>
@once
@push('styles')
<style>
svg > g > g.google-visualization-tooltip { pointer-events: none }
</style>
@endpush
@push('headerScripts')
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart'], 'language': '{{ $localization }}'});
</script>
@endpush
@endonce

{{-- Add @lagoonScripts('en') --}}
<script type="text/javascript">
google.charts.setOnLoadCallback(drawChart{{ $chartId }});
Expand Down
1 change: 1 addition & 0 deletions resources/views/livewire/gantt-chart.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div>
{{-- Add @lagoonScripts('en', 'gantt') --}}
@once
@push('styles')
<style>
Expand Down
14 changes: 1 addition & 13 deletions resources/views/livewire/line-chart.blade.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<div>
@once
@push('styles')
<style>
svg > g > g.google-visualization-tooltip { pointer-events: none }
</style>
@endpush
@push('headerScripts')
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart'], 'language': '{{ $localization }}'});
</script>
@endpush
@endonce
{{-- Add @lagoonScripts('en') --}}

<script type="text/javascript">
google.charts.setOnLoadCallback(drawChart{{ $chartId }});
Expand Down
14 changes: 1 addition & 13 deletions resources/views/livewire/pie-chart.blade.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<div>
@once
@push('styles')
<style>
svg > g > g.google-visualization-tooltip { pointer-events: none }
</style>
@endpush
@push('headerScripts')
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart'], 'language': '{{ $localization }}'});
</script>
@endpush
@endonce
{{-- Add @lagoonScripts('en') --}}

<script type="text/javascript">
google.charts.setOnLoadCallback(drawChart{{ $chartId }});
Expand Down
14 changes: 1 addition & 13 deletions resources/views/livewire/timeline.blade.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<div>
@once
@push('styles')
<style>
svg > g > g.google-visualization-tooltip { pointer-events: none }
</style>
@endpush
@push('headerScripts')
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['timeline'], 'language': '{{ $localization }}'});
</script>
@endpush
@endonce
{{-- Add @lagoonScripts('en', 'timeline') --}}

<script type="text/javascript">
google.charts.setOnLoadCallback(drawChart{{ $chartId }});
Expand Down
14 changes: 1 addition & 13 deletions resources/views/livewire/waterfall-chart.blade.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<div>
@once
@push('styles')
<style>
svg > g > g.google-visualization-tooltip { pointer-events: none }
</style>
@endpush
@push('headerScripts')
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart'], 'language': '{{ $localization }}'});
</script>
@endpush
@endonce
{{-- Add @lagoonScripts('en') --}}

<script type="text/javascript">
google.charts.setOnLoadCallback(drawChart{{ $chartId }});
Expand Down
14 changes: 14 additions & 0 deletions src/LagoonServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Helvetitec\LagoonCharts\Http\Livewire\GanttChart;
use Helvetitec\LagoonCharts\Http\Livewire\Timeline;
use Helvetitec\LagoonCharts\Http\Livewire\WaterfallChart;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;

Expand All @@ -34,6 +35,19 @@ public function boot()
Livewire::component('lagoon-waterfall-chart', WaterfallChart::class);
Livewire::component('lagoon-timeline', Timeline::class);

Blade::directive('lagoonScripts', function ($localization, $package = 'corechart') {
return '<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load(\'current\', {\'packages\':[\''.$package.'\'], \'language\': \''.$localization.'\'});
</script>';
});

Blade::directive('lagoonStyles', function ($localization) {
return '<style>
svg > g > g.google-visualization-tooltip { pointer-events: none }
</style>';
});

if ($this->app->runningInConsole())
{
$this->publishes([
Expand Down

0 comments on commit 6c322c9

Please sign in to comment.