1.
/*! DataTables Bootstrap 3 integration
2.
* ©2011-2015 SpryMedia Ltd - datatables.net/license
3.
*/
4.
5.
/**
6.
* DataTables integration for Bootstrap 3. This requires Bootstrap 3 and
7.
* DataTables 1.10 or newer.
8.
*
9.
* This file sets the defaults and adds options to DataTables to style its
10.
* controls using Bootstrap. See http://datatables.net/manual/styling/bootstrap
11.
* for further information.
12.
*/
13.
(function( factory ){
14.
if ( typeof define === 'function' && define.amd ) {
15.
// AMD
16.
define( ['jquery', 'datatables.net'], function ( $ ) {
17.
return factory( $, window, document );
18.
} );
19.
}
20.
else if ( typeof exports === 'object' ) {
21.
// CommonJS
22.
module.exports = function (root, $) {
23.
if ( ! root ) {
24.
root = window;
25.
}
26.
27.
if ( ! $ || ! $.fn.dataTable ) {
28.
// Require DataTables, which attaches to jQuery, including
29.
// jQuery if needed and have a $ property so we can access the
30.
// jQuery object that is used
31.
$ = require('datatables.net')(root, $).$;
32.
}
33.
34.
return factory( $, root, root.document );
35.
};
36.
}
37.
else {
38.
// Browser
39.
factory( jQuery, window, document );
40.
}
41.
}(function( $, window, document, undefined ) {
42.
'use strict';
43.
var DataTable = $.fn.dataTable;
44.
45.
46.
/* Set the defaults for DataTables initialisation */
47.
$.extend( true, DataTable.defaults, {
48.
dom:
49.
"<'ui stackable grid'"+
50.
"<'row'"+
51.
"<'eight wide column'l>"+
52.
"<'right aligned eight wide column'f>"+
53.
">"+
54.
"<'row dt-table'"+
55.
"<'sixteen wide column'tr>"+
56.
">"+
57.
"<'row'"+
58.
"<'seven wide column'i>"+
59.
"<'right aligned nine wide column'p>"+
60.
">"+
61.
">",
62.
renderer: 'semanticUI'
63.
} );
64.
65.
66.
/* Default class modification */
67.
$.extend( DataTable.ext.classes, {
68.
sWrapper: "dataTables_wrapper dt-semanticUI",
69.
sFilter: "dataTables_filter ui input",
70.
sProcessing: "dataTables_processing ui segment",
71.
sPageButton: "paginate_button item"
72.
} );
73.
74.
75.
/* Bootstrap paging button renderer */
76.
DataTable.ext.renderer.pageButton.semanticUI = function ( settings, host, idx, buttons, page, pages ) {
77.
var api = new DataTable.Api( settings );
78.
var classes = settings.oClasses;
79.
var lang = settings.oLanguage.oPaginate;
80.
var aria = settings.oLanguage.oAria.paginate || {};
81.
var btnDisplay, btnClass, counter=0;
82.
83.
var attach = function( container, buttons ) {
84.
var i, ien, node, button;
85.
var clickHandler = function ( e ) {
86.
e.preventDefault();
87.
if ( !$(e.currentTarget).hasClass('disabled') && api.page() != e.data.action ) {
88.
api.page( e.data.action ).draw( 'page' );
89.
}
90.
};
91.
92.
for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
93.
button = buttons[i];
94.
95.
if ( $.isArray( button ) ) {
96.
attach( container, button );
97.
}
98.
else {
99.
btnDisplay = '';
100.
btnClass = '';
101.
102.
switch ( button ) {
103.
case 'ellipsis':
104.
btnDisplay = '…';
105.
btnClass = 'disabled';
106.
break;
107.
108.
case 'first':
109.
btnDisplay = lang.sFirst;
110.
btnClass = button + (page > 0 ?
111.
'' : ' disabled');
112.
break;
113.
114.
case 'previous':
115.
btnDisplay = lang.sPrevious;
116.
btnClass = button + (page > 0 ?
117.
'' : ' disabled');
118.
break;
119.
120.
case 'next':
121.
btnDisplay = lang.sNext;
122.
btnClass = button + (page < pages-1 ?
123.
'' : ' disabled');
124.
break;
125.
126.
case 'last':
127.
btnDisplay = lang.sLast;
128.
btnClass = button + (page < pages-1 ?
129.
'' : ' disabled');
130.
break;
131.
132.
default:
133.
btnDisplay = button + 1;
134.
btnClass = page === button ?
135.
'active' : '';
136.
break;
137.
}
138.
139.
var tag = btnClass.indexOf( 'disabled' ) === -1 ?
140.
'a' :
141.
'div';
142.
143.
if ( btnDisplay ) {
144.
node = $('<'+tag+'>', {
145.
'class': classes.sPageButton+' '+btnClass,
146.
'id': idx === 0 && typeof button === 'string' ?
147.
settings.sTableId +'_'+ button :
148.
null,
149.
'href': '#',
150.
'aria-controls': settings.sTableId,
151.
'aria-label': aria[ button ],
152.
'data-dt-idx': counter,
153.
'tabindex': settings.iTabIndex
154.
} )
155.
.html( btnDisplay )
156.
.appendTo( container );
157.
158.
settings.oApi._fnBindAction(
159.
node, {action: button}, clickHandler
160.
);
161.
162.
counter++;
163.
}
164.
}
165.
}
166.
};
167.
168.
// IE9 throws an 'unknown error' if document.activeElement is used
169.
// inside an iframe or frame.
170.
var activeEl;
171.
172.
try {
173.
// Because this approach is destroying and recreating the paging
174.
// elements, focus is lost on the select button which is bad for
175.
// accessibility. So we want to restore focus once the draw has
176.
// completed
177.
activeEl = $(host).find(document.activeElement).data('dt-idx');
178.
}
179.
catch (e) {}
180.
181.
attach(
182.
$(host).empty().html('<div class="ui stackable pagination menu"/>').children(),
183.
buttons
184.
);
185.
186.
if ( activeEl !== undefined ) {
187.
$(host).find( '[data-dt-idx='+activeEl+']' ).trigger('focus');
188.
}
189.
};
190.
191.
192.
// Javascript enhancements on table initialisation
193.
$(document).on( 'init.dt', function (e, ctx) {
194.
if ( e.namespace !== 'dt' ) {
195.
return;
196.
}
197.
198.
var api = new $.fn.dataTable.Api( ctx );
199.
200.
// Length menu drop down
201.
if ( $.fn.dropdown ) {
202.
$( 'div.dataTables_length select', api.table().container() ).dropdown();
203.
}
204.
205.
// Filtering input
206.
$( 'div.dataTables_filter.ui.input', api.table().container() ).removeClass('input').addClass('form');
207.
$( 'div.dataTables_filter input', api.table().container() ).wrap( '<span class="ui input" />' );
208.
} );
209.
210.
211.
return DataTable;
212.
}));
213.