responsive.bootstrap4.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*! Bootstrap 4 integration for DataTables' Responsive
  2. * ©2016 SpryMedia Ltd - datatables.net/license
  3. */
  4. (function( factory ){
  5. if ( typeof define === 'function' && define.amd ) {
  6. // AMD
  7. define( ['jquery', 'datatables.net-bs4', 'datatables.net-responsive'], function ( $ ) {
  8. return factory( $, window, document );
  9. } );
  10. }
  11. else if ( typeof exports === 'object' ) {
  12. // CommonJS
  13. module.exports = function (root, $) {
  14. if ( ! root ) {
  15. root = window;
  16. }
  17. if ( ! $ || ! $.fn.dataTable ) {
  18. $ = require('datatables.net-bs4')(root, $).$;
  19. }
  20. if ( ! $.fn.dataTable.Responsive ) {
  21. require('datatables.net-responsive')(root, $);
  22. }
  23. return factory( $, root, root.document );
  24. };
  25. }
  26. else {
  27. // Browser
  28. factory( jQuery, window, document );
  29. }
  30. }(function( $, window, document, undefined ) {
  31. 'use strict';
  32. var DataTable = $.fn.dataTable;
  33. var _display = DataTable.Responsive.display;
  34. var _original = _display.modal;
  35. var _modal = $(
  36. '<div class="modal fade dtr-bs-modal" role="dialog">'+
  37. '<div class="modal-dialog" role="document">'+
  38. '<div class="modal-content">'+
  39. '<div class="modal-header">'+
  40. '<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+
  41. '</div>'+
  42. '<div class="modal-body"/>'+
  43. '</div>'+
  44. '</div>'+
  45. '</div>'
  46. );
  47. _display.modal = function ( options ) {
  48. return function ( row, update, render ) {
  49. if ( ! $.fn.modal ) {
  50. _original( row, update, render );
  51. }
  52. else {
  53. if ( ! update ) {
  54. if ( options && options.header ) {
  55. var header = _modal.find('div.modal-header');
  56. var button = header.find('button').detach();
  57. header
  58. .empty()
  59. .append( '<h4 class="modal-title">'+options.header( row )+'</h4>' )
  60. .append( button );
  61. }
  62. _modal.find( 'div.modal-body' )
  63. .empty()
  64. .append( render() );
  65. _modal
  66. .appendTo( 'body' )
  67. .modal();
  68. }
  69. }
  70. };
  71. };
  72. return DataTable.Responsive;
  73. }));