LaravelTest
184 строки · 4.6 Кб
1/*! DataTables Bootstrap 4 integration
2* ©2011-2017 SpryMedia Ltd - datatables.net/license
3*/
4
5/**
6* DataTables integration for Bootstrap 4. This requires Bootstrap 4 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 ){14if ( typeof define === 'function' && define.amd ) {15// AMD16define( ['jquery', 'datatables.net'], function ( $ ) {17return factory( $, window, document );18} );19}20else if ( typeof exports === 'object' ) {21// CommonJS22module.exports = function (root, $) {23if ( ! root ) {24root = window;25}26
27if ( ! $ || ! $.fn.dataTable ) {28// Require DataTables, which attaches to jQuery, including29// jQuery if needed and have a $ property so we can access the30// jQuery object that is used31$ = require('datatables.net')(root, $).$;32}33
34return factory( $, root, root.document );35};36}37else {38// Browser39factory( jQuery, window, document );40}41}(function( $, window, document, undefined ) {42'use strict';43var DataTable = $.fn.dataTable;44
45
46/* Set the defaults for DataTables initialisation */
47$.extend( true, DataTable.defaults, {48dom:49"<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>>" +50"<'row'<'col-sm-12'tr>>" +51"<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",52renderer: 'bootstrap'53} );54
55
56/* Default class modification */
57$.extend( DataTable.ext.classes, {58sWrapper: "dataTables_wrapper dt-bootstrap4",59sFilterInput: "form-control form-control-sm",60sLengthSelect: "custom-select custom-select-sm form-control form-control-sm",61sProcessing: "dataTables_processing card",62sPageButton: "paginate_button page-item"63} );64
65
66/* Bootstrap paging button renderer */
67DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, buttons, page, pages ) {68var api = new DataTable.Api( settings );69var classes = settings.oClasses;70var lang = settings.oLanguage.oPaginate;71var aria = settings.oLanguage.oAria.paginate || {};72var btnDisplay, btnClass, counter=0;73
74var attach = function( container, buttons ) {75var i, ien, node, button;76var clickHandler = function ( e ) {77e.preventDefault();78if ( !$(e.currentTarget).hasClass('disabled') && api.page() != e.data.action ) {79api.page( e.data.action ).draw( 'page' );80}81};82
83for ( i=0, ien=buttons.length ; i<ien ; i++ ) {84button = buttons[i];85
86if ( Array.isArray( button ) ) {87attach( container, button );88}89else {90btnDisplay = '';91btnClass = '';92
93switch ( button ) {94case 'ellipsis':95btnDisplay = '…';96btnClass = 'disabled';97break;98
99case 'first':100btnDisplay = lang.sFirst;101btnClass = button + (page > 0 ?102'' : ' disabled');103break;104
105case 'previous':106btnDisplay = lang.sPrevious;107btnClass = button + (page > 0 ?108'' : ' disabled');109break;110
111case 'next':112btnDisplay = lang.sNext;113btnClass = button + (page < pages-1 ?114'' : ' disabled');115break;116
117case 'last':118btnDisplay = lang.sLast;119btnClass = button + (page < pages-1 ?120'' : ' disabled');121break;122
123default:124btnDisplay = button + 1;125btnClass = page === button ?126'active' : '';127break;128}129
130if ( btnDisplay ) {131node = $('<li>', {132'class': classes.sPageButton+' '+btnClass,133'id': idx === 0 && typeof button === 'string' ?134settings.sTableId +'_'+ button :135null136} )137.append( $('<a>', {138'href': '#',139'aria-controls': settings.sTableId,140'aria-label': aria[ button ],141'data-dt-idx': counter,142'tabindex': settings.iTabIndex,143'class': 'page-link'144} )145.html( btnDisplay )146)147.appendTo( container );148
149settings.oApi._fnBindAction(150node, {action: button}, clickHandler151);152
153counter++;154}155}156}157};158
159// IE9 throws an 'unknown error' if document.activeElement is used160// inside an iframe or frame.161var activeEl;162
163try {164// Because this approach is destroying and recreating the paging165// elements, focus is lost on the select button which is bad for166// accessibility. So we want to restore focus once the draw has167// completed168activeEl = $(host).find(document.activeElement).data('dt-idx');169}170catch (e) {}171
172attach(173$(host).empty().html('<ul class="pagination"/>').children('ul'),174buttons
175);176
177if ( activeEl !== undefined ) {178$(host).find( '[data-dt-idx='+activeEl+']' ).trigger('focus');179}180};181
182
183return DataTable;184}));185