dataTables_overrides.js - warvox - VoIP based wardialing tool, forked from rapid7/warvox.
HTML git clone git://jay.scot/warvox
DIR Log
DIR Files
DIR Refs
DIR README
---
dataTables_overrides.js (3905B)
---
1 $.extend( $.fn.dataTableExt.oStdClasses, {
2 "sWrapper": "dataTables_wrapper form-inline"
3 } );
4
5
6 /* API method to get paging information */
7 $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
8 {
9 return {
10 "iStart": oSettings._iDisplayStart,
11 "iEnd": oSettings.fnDisplayEnd(),
12 "iLength": oSettings._iDisplayLength,
13 "iTotal": oSettings.fnRecordsTotal(),
14 "iFilteredTotal": oSettings.fnRecordsDisplay(),
15 "iPage": Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
16 "iTotalPages": Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
17 };
18 };
19
20 /* Bootstrap style pagination control */
21 $.extend( $.fn.dataTableExt.oPagination, {
22
23 "bootstrap": {
24 "fnInit": function( oSettings, nPaging, fnDraw ) {
25 var oLang = oSettings.oLanguage.oPaginate;
26 var fnClickHandler = function ( e ) {
27 e.preventDefault();
28 if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
29 fnDraw( oSettings );
30 }
31 };
32
33 $(nPaging).addClass('pagination').append(
34 '<ul class="pagination pagination">'+
35 '<li class="prev disabled"><a href="#">← '+oLang.sPrevious+'</a></li>'+
36 '<li class="next disabled"><a href="#">'+oLang.sNext+' → </a></li>'+
37 '</ul>'
38 );
39 var els = $('a', nPaging);
40 $(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
41 $(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
42 },
43
44 "fnUpdate": function ( oSettings, fnDraw ) {
45 var iListLength = 5;
46 var oPaging = oSettings.oInstance.fnPagingInfo();
47 var an = oSettings.aanFeatures.p;
48 var i, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2);
49
50 if ( oPaging.iTotalPages < iListLength) {
51 iStart = 1;
52 iEnd = oPaging.iTotalPages;
53 }
54 else if ( oPaging.iPage <= iHalf ) {
55 iStart = 1;
56 iEnd = iListLength;
57 } else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
58 iStart = oPaging.iTotalPages - iListLength + 1;
59 iEnd = oPaging.iTotalPages;
60 } else {
61 iStart = oPaging.iPage - iHalf + 1;
62 iEnd = iStart + iListLength - 1;
63 }
64
65 for ( i=0, iLen=an.length ; i<iLen ; i++ ) {
66 // Remove the middle elements
67 $('li:gt(0)', an[i]).filter(':not(:last)').remove();
68
69 // Add the new list items and their event handlers
70 for ( j=iStart ; j<=iEnd ; j++ ) {
71 sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
72 $('<li '+sClass+'><a href="#">'+j+'</a></li>')
73 .insertBefore( $('li:last', an[i])[0] )
74 .bind('click', function (e) {
75 e.preventDefault();
76 oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
77 fnDraw( oSettings );
78 } );
79 }
80
81 // Add / remove disabled classes from the static elements
82 if ( oPaging.iPage === 0 ) {
83 $('li:first', an[i]).addClass('disabled');
84 } else {
85 $('li:first', an[i]).removeClass('disabled');
86 }
87
88 if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
89 $('li:last', an[i]).addClass('disabled');
90 } else {
91 $('li:last', an[i]).removeClass('disabled');
92 }
93 }
94 }
95 }
96 } );
97
98
99 /*
100 * TableTools Bootstrap compatibility
101 * Required TableTools 2.1+
102 */
103 if ( $.fn.DataTable.TableTools ) {
104 // Set the classes that TableTools uses to something suitable for Bootstrap
105 $.extend( true, $.fn.DataTable.TableTools.classes, {
106 "container": "DTTT btn-group",
107 "buttons": {
108 "normal": "btn",
109 "disabled": "disabled"
110 },
111 "collection": {
112 "container": "DTTT_dropdown dropdown-menu",
113 "buttons": {
114 "normal": "",
115 "disabled": "disabled"
116 }
117 },
118 "print": {
119 "info": "DTTT_print_info modal"
120 },
121 "select": {
122 "row": "active"
123 }
124 } );
125
126 // Have the collection use a bootstrap compatible dropdown
127 $.extend( true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {
128 "collection": {
129 "container": "ul",
130 "button": "li",
131 "liner": "a"
132 }
133 } );
134 }