Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/dataTables.bootstrap.js
1292 views
1
/* Set the defaults for DataTables initialisation */
2
jQuery.extend( true, jQuery.fn.dataTable.defaults, {
3
"sDom": "<'row'<'col-xs-6 col-left'l><'col-xs-6 col-right'f>r>t<'row'<'col-xs-6 col-left'i><'col-xs-6 col-right'p>>",
4
"sPaginationType": "bootstrap",
5
"oLanguage": {
6
"sLengthMenu": "_MENU_ records per page"
7
}
8
} );
9
10
11
12
13
/* Default class modification */
14
jQuery.extend( jQuery.fn.dataTableExt.oStdClasses, {
15
"sWrapper": "dataTables_wrapper form-inline",
16
"sFilterInput": "form-control input-sm",
17
"sLengthSelect": "form-control input-sm"
18
} );
19
20
21
/* API method to get paging information */
22
jQuery.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
23
{
24
return {
25
"iStart": oSettings._iDisplayStart,
26
"iEnd": oSettings.fnDisplayEnd(),
27
"iLength": oSettings._iDisplayLength,
28
"iTotal": oSettings.fnRecordsTotal(),
29
"iFilteredTotal": oSettings.fnRecordsDisplay(),
30
"iPage": oSettings._iDisplayLength === -1 ?
31
0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
32
"iTotalPages": oSettings._iDisplayLength === -1 ?
33
0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
34
};
35
};
36
37
38
/* Bootstrap style pagination control */
39
jQuery.extend( jQuery.fn.dataTableExt.oPagination, {
40
"bootstrap": {
41
"fnInit": function( oSettings, nPaging, fnDraw ) {
42
var oLang = oSettings.oLanguage.oPaginate;
43
var fnClickHandler = function ( e ) {
44
e.preventDefault();
45
if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
46
fnDraw( oSettings );
47
}
48
};
49
50
jQuery(nPaging).append(
51
'<ul class="pagination pagination-sm">'+
52
'<li class="prev disabled"><a href="#"><i class="entypo-left-open"></i></a></li>'+
53
'<li class="next disabled"><a href="#"><i class="entypo-right-open"></i></a></li>'+
54
'</ul>'
55
);
56
var els = jQuery('a', nPaging);
57
jQuery(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
58
jQuery(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
59
},
60
61
"fnUpdate": function ( oSettings, fnDraw ) {
62
var iListLength = 5;
63
var oPaging = oSettings.oInstance.fnPagingInfo();
64
var an = oSettings.aanFeatures.p;
65
var i, ien, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2);
66
67
if ( oPaging.iTotalPages < iListLength) {
68
iStart = 1;
69
iEnd = oPaging.iTotalPages;
70
}
71
else if ( oPaging.iPage <= iHalf ) {
72
iStart = 1;
73
iEnd = iListLength;
74
} else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
75
iStart = oPaging.iTotalPages - iListLength + 1;
76
iEnd = oPaging.iTotalPages;
77
} else {
78
iStart = oPaging.iPage - iHalf + 1;
79
iEnd = iStart + iListLength - 1;
80
}
81
82
for ( i=0, ien=an.length ; i<ien ; i++ ) {
83
// Remove the middle elements
84
jQuery('li:gt(0)', an[i]).filter(':not(:last)').remove();
85
86
// Add the new list items and their event handlers
87
for ( j=iStart ; j<=iEnd ; j++ ) {
88
sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
89
jQuery('<li '+sClass+'><a href="#">'+j+'</a></li>')
90
.insertBefore( jQuery('li:last', an[i])[0] )
91
.bind('click', function (e) {
92
e.preventDefault();
93
oSettings._iDisplayStart = (parseInt(jQuery('a', this).text(),10)-1) * oPaging.iLength;
94
fnDraw( oSettings );
95
} );
96
}
97
98
// Add / remove disabled classes from the static elements
99
if ( oPaging.iPage === 0 ) {
100
jQuery('li:first', an[i]).addClass('disabled');
101
} else {
102
jQuery('li:first', an[i]).removeClass('disabled');
103
}
104
105
if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
106
jQuery('li:last', an[i]).addClass('disabled');
107
} else {
108
jQuery('li:last', an[i]).removeClass('disabled');
109
}
110
}
111
}
112
}
113
} );
114
115
116
/*
117
* TableTools Bootstrap compatibility
118
* Required TableTools 2.1+
119
*/
120
if ( jQuery.fn.DataTable.TableTools ) {
121
// Set the classes that TableTools uses to something suitable for Bootstrap
122
jQuery.extend( true, jQuery.fn.DataTable.TableTools.classes, {
123
"container": "DTTT btn-group",
124
"buttons": {
125
"normal": "btn btn-white",
126
"disabled": "disabled"
127
},
128
"collection": {
129
"container": "DTTT_dropdown dropdown-menu",
130
"buttons": {
131
"normal": "",
132
"disabled": "disabled"
133
}
134
},
135
"print": {
136
"info": "DTTT_print_info modal"
137
},
138
"select": {
139
"row": "active"
140
}
141
} );
142
143
// Have the collection use a bootstrap compatible dropdown
144
jQuery.extend( true, jQuery.fn.DataTable.TableTools.DEFAULTS.oTags, {
145
"collection": {
146
"container": "ul",
147
"button": "li",
148
"liner": "a"
149
}
150
} );
151
}
152
153
154