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