Skip to content

Commit 1130963

Browse files
authored
Make LaravelDataTables javascript namespace configurable. (#145)
* made LaravelDataTables const to variable * add namespace variable to datatables-html config file * add default value to config functions
1 parent 6affef4 commit 1130963

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

src/resources/config/config.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?php
22

33
return [
4+
/*
5+
* DataTables JavaScript global namespace.
6+
*/
7+
8+
'namespace' => 'LaravelDataTables',
9+
410
/*
511
* Default table attributes when generating the table.
612
*/

src/resources/views/editor.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
$(function(){
2-
window.LaravelDataTables = window.LaravelDataTables || {};
2+
window.{{ config('datatables-html.namespace', 'LaravelDataTables') }} = window.{{ config('datatables-html.namespace', 'LaravelDataTables') }} || {};
33
$.ajaxSetup({headers: {'X-CSRF-TOKEN': '{{csrf_token()}}'}});
44
@foreach($editors as $editor)
5-
var {{$editor->instance}} = window.LaravelDataTables["%1$s-{{$editor->instance}}"] = new $.fn.dataTable.Editor({!! $editor->toJson() !!});
5+
var {{$editor->instance}} = window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}["%1$s-{{$editor->instance}}"] = new $.fn.dataTable.Editor({!! $editor->toJson() !!});
66
{!! $editor->scripts !!}
77
@foreach ((array) $editor->events as $event)
88
{{$editor->instance}}.on('{!! $event['event'] !!}', {!! $event['script'] !!});
99
@endforeach
1010
@endforeach
11-
window.LaravelDataTables["%1$s"] = $("#%1$s").DataTable(%2$s);
11+
window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}["%1$s"] = $("#%1$s").DataTable(%2$s);
1212
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
window.dtx = window.dtx || {};
22
window.dtx["%1$s"] = function(opts) {
3-
window.LaravelDataTables = window.LaravelDataTables || {};
3+
window.{{ config('datatables-html.namespace', 'LaravelDataTables') }} = window.{{ config('datatables-html.namespace', 'LaravelDataTables') }} || {};
44
@if(isset($editors))
55
@foreach($editors as $editor)
6-
var {{$editor->instance}} = window.LaravelDataTables["%1$s-{{$editor->instance}}"] = new $.fn.dataTable.Editor({!! $editor->toJson() !!});
6+
var {{$editor->instance}} = window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}["%1$s-{{$editor->instance}}"] = new $.fn.dataTable.Editor({!! $editor->toJson() !!});
77
{!! $editor->scripts !!}
88
@foreach ((array) $editor->events as $event)
99
{{$editor->instance}}.on('{!! $event['event'] !!}', {!! $event['script'] !!});
1010
@endforeach
1111
@endforeach
1212
@endif
13-
return window.LaravelDataTables["%1$s"] = $("#%1$s").DataTable($.extend(%2$s, opts));
13+
return window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}["%1$s"] = $("#%1$s").DataTable($.extend(%2$s, opts));
1414
}

src/resources/views/options.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
window.LaravelDataTables = window.LaravelDataTables || {};
2-
window.LaravelDataTables.options = %2$s
3-
window.LaravelDataTables.editors = [];
1+
window.{{ config('datatables-html.namespace', 'LaravelDataTables') }} = window.{{ config('datatables-html.namespace', 'LaravelDataTables') }} || {};
2+
window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}.options = %2$s
3+
window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}.editors = [];
44
@foreach($editors as $editor)
5-
window.LaravelDataTables.editors["{{$editor->instance}}"] = {!! $editor->toJson() !!}
5+
window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}.editors["{{$editor->instance}}"] = {!! $editor->toJson() !!}
66
@endforeach

src/resources/views/script.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
$(function(){window.LaravelDataTables=window.LaravelDataTables||{};window.LaravelDataTables["%1$s"]=$("#%1$s").DataTable(%2$s);});
1+
$(function(){window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}=window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}||{};window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}["%1$s"]=$("#%1$s").DataTable(%2$s);});

0 commit comments

Comments
 (0)