Açıklama Yok

dataTables.bootstrap5.js 5.1KB

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