-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
responsive.bootstrap5.js
78 lines (68 loc) · 1.87 KB
/
responsive.bootstrap5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*! Bootstrap 5 integration for DataTables' Responsive
* © SpryMedia Ltd - datatables.net/license
*/
var _display = DataTable.Responsive.display;
var _original = _display.modal;
var _modal = $(
'<div class="modal fade dtr-bs-modal" role="dialog">'+
'<div class="modal-dialog" role="document">'+
'<div class="modal-content">'+
'<div class="modal-header">'+
'<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>'+
'</div>'+
'<div class="modal-body"/>'+
'</div>'+
'</div>'+
'</div>'
);
var modal;
// Note this could be undefined at the time of initialisation - the
// DataTable.Responsive.bootstrap function can be used to set a different
// bootstrap object
var _bs = window.bootstrap;
DataTable.Responsive.bootstrap = function (bs) {
_bs = bs;
}
_display.modal = function ( options ) {
if (! modal) {
modal = new _bs.Modal(_modal[0]);
}
return function ( row, update, render, closeCallback ) {
if ( ! $.fn.modal ) {
return _original( row, update, render, closeCallback );
}
else {
if ( ! update ) {
if ( options && options.header ) {
var header = _modal.find('div.modal-header');
var button = header.find('button').detach();
header
.empty()
.append( '<h4 class="modal-title">'+options.header( row )+'</h4>' )
.append( button );
}
_modal.find( 'div.modal-body' )
.empty()
.append( render() );
_modal
.data('dtr-row-idx', row.index())
.one('hidden.bs.modal', closeCallback)
.appendTo( 'body' )
.modal();
modal.show();
}
else {
if ( $.contains(document, _modal[0]) && row.index() === _modal.data('dtr-row-idx') ) {
_modal.find( 'div.modal-body' )
.empty()
.append( render() );
}
else {
// Modal not shown for this row - do nothing
return null;
}
}
return true;
}
};
};