|
1 | | -/*! DataTables Bootstrap 3 integration |
2 | | - * ©2011-2014 SpryMedia Ltd - datatables.net/license |
3 | | - */ |
4 | 1 |
|
5 | 2 | /** |
6 | 3 | * DataTables integration for Bootstrap 3. This requires Bootstrap 3 and |
7 | 4 | * 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 | 5 | */ |
13 | | -(function(window, document, undefined){ |
14 | | - |
15 | | - var factory = function( $, DataTable ) { |
16 | | - "use strict"; |
17 | | - |
18 | | - |
19 | | - /* Set the defaults for DataTables initialisation */ |
20 | | - $.extend( true, DataTable.defaults, { |
21 | | - dom: |
22 | | - "<'row'<'col-sm-6'l><'col-sm-6'f>>" + |
23 | | - "<'row'<'col-sm-12'tr>>" + |
24 | | - "<'row'<'col-sm-6'i><'col-sm-6'p>>", |
25 | | - renderer: 'bootstrap' |
26 | | - } ); |
27 | | - |
28 | | - |
29 | | - /* Default class modification */ |
30 | | - $.extend( DataTable.ext.classes, { |
31 | | - sWrapper: "dataTables_wrapper form-inline dt-bootstrap", |
32 | | - sFilterInput: "form-control input-sm", |
33 | | - sLengthSelect: "form-control input-sm" |
34 | | - } ); |
35 | | - |
36 | | - |
37 | | - /* Bootstrap paging button renderer */ |
38 | | - DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, buttons, page, pages ) { |
39 | | - var api = new DataTable.Api( settings ); |
40 | | - var classes = settings.oClasses; |
41 | | - var lang = settings.oLanguage.oPaginate; |
42 | | - var btnDisplay, btnClass; |
43 | | - |
44 | | - var attach = function( container, buttons ) { |
45 | | - var i, ien, node, button; |
46 | | - var clickHandler = function ( e ) { |
47 | | - e.preventDefault(); |
48 | | - if ( !$(e.currentTarget).hasClass('disabled') ) { |
49 | | - api.page( e.data.action ).draw( false ); |
50 | | - } |
51 | | - }; |
52 | | - |
53 | | - for ( i=0, ien=buttons.length ; i<ien ; i++ ) { |
54 | | - button = buttons[i]; |
55 | | - |
56 | | - if ( $.isArray( button ) ) { |
57 | | - attach( container, button ); |
58 | | - } |
59 | | - else { |
60 | | - btnDisplay = ''; |
61 | | - btnClass = ''; |
62 | | - |
63 | | - switch ( button ) { |
64 | | - case 'ellipsis': |
65 | | - btnDisplay = '…'; |
66 | | - btnClass = 'disabled'; |
67 | | - break; |
68 | | - |
69 | | - case 'first': |
70 | | - btnDisplay = lang.sFirst; |
71 | | - btnClass = button + (page > 0 ? |
72 | | - '' : ' disabled'); |
73 | | - break; |
74 | | - |
75 | | - case 'previous': |
76 | | - btnDisplay = lang.sPrevious; |
77 | | - btnClass = button + (page > 0 ? |
78 | | - '' : ' disabled'); |
79 | | - break; |
80 | | - |
81 | | - case 'next': |
82 | | - btnDisplay = lang.sNext; |
83 | | - btnClass = button + (page < pages-1 ? |
84 | | - '' : ' disabled'); |
85 | | - break; |
86 | | - |
87 | | - case 'last': |
88 | | - btnDisplay = lang.sLast; |
89 | | - btnClass = button + (page < pages-1 ? |
90 | | - '' : ' disabled'); |
91 | | - break; |
92 | | - |
93 | | - default: |
94 | | - btnDisplay = button + 1; |
95 | | - btnClass = page === button ? |
96 | | - 'active' : ''; |
97 | | - break; |
98 | | - } |
99 | | - |
100 | | - if ( btnDisplay ) { |
101 | | - node = $('<li>', { |
102 | | - 'class': classes.sPageButton+' '+btnClass, |
103 | | - 'aria-controls': settings.sTableId, |
104 | | - 'tabindex': settings.iTabIndex, |
105 | | - 'id': idx === 0 && typeof button === 'string' ? |
106 | | - settings.sTableId +'_'+ button : |
107 | | - null |
108 | | - } ) |
109 | | - .append( $('<a>', { |
110 | | - 'href': '#' |
111 | | - } ) |
112 | | - .html( btnDisplay ) |
113 | | - ) |
114 | | - .appendTo( container ); |
115 | | - |
116 | | - settings.oApi._fnBindAction( |
117 | | - node, {action: button}, clickHandler |
118 | | - ); |
119 | | - } |
120 | | - } |
121 | | - } |
122 | | - }; |
123 | | - |
124 | | - attach( |
125 | | - $(host).empty().html('<ul class="pagination"/>').children('ul'), |
126 | | - buttons |
127 | | - ); |
128 | | - }; |
129 | | - |
130 | | - |
131 | | - /* |
132 | | - * TableTools Bootstrap compatibility |
133 | | - * Required TableTools 2.1+ |
134 | | - */ |
135 | | - if ( DataTable.TableTools ) { |
136 | | - // Set the classes that TableTools uses to something suitable for Bootstrap |
137 | | - $.extend( true, DataTable.TableTools.classes, { |
138 | | - "container": "DTTT btn-group", |
139 | | - "buttons": { |
140 | | - "normal": "btn btn-default", |
141 | | - "disabled": "disabled" |
142 | | - }, |
143 | | - "collection": { |
144 | | - "container": "DTTT_dropdown dropdown-menu", |
145 | | - "buttons": { |
146 | | - "normal": "", |
147 | | - "disabled": "disabled" |
148 | | - } |
149 | | - }, |
150 | | - "print": { |
151 | | - "info": "DTTT_print_info" |
152 | | - }, |
153 | | - "select": { |
154 | | - "row": "active" |
155 | | - } |
156 | | - } ); |
157 | | - |
158 | | - // Have the collection use a bootstrap compatible drop down |
159 | | - $.extend( true, DataTable.TableTools.DEFAULTS.oTags, { |
160 | | - "collection": { |
161 | | - "container": "ul", |
162 | | - "button": "li", |
163 | | - "liner": "a" |
164 | | - } |
165 | | - } ); |
166 | | - } |
167 | | - |
168 | | - }; // /factory |
169 | | - |
170 | | - |
| 6 | +(function (factory) { |
171 | 7 | if ( typeof define === 'function' && define.amd ) { |
172 | 8 | // Define as an AMD module if possible |
173 | 9 | define( ['jquery', 'datatables'], factory ); |
|
180 | 16 | // Otherwise simply initialise as normal, stopping multiple evaluation |
181 | 17 | factory( jQuery, jQuery.fn.dataTable ); |
182 | 18 | } |
| 19 | +}(function ($, DataTable) { |
| 20 | + "use strict"; |
| 21 | + |
| 22 | + |
| 23 | + /* Set the defaults for DataTables initialisation */ |
| 24 | + $.extend( true, DataTable.defaults, { |
| 25 | + dom: |
| 26 | + "<'row'<'col-sm-6'l><'col-sm-6'f>>" + |
| 27 | + "<'row'<'col-sm-12'tr>>" + |
| 28 | + "<'row'<'col-sm-6'i><'col-sm-6'p>>", |
| 29 | + renderer: 'bootstrap' |
| 30 | + } ); |
| 31 | + |
| 32 | + |
| 33 | + /* Default class modification */ |
| 34 | + $.extend( DataTable.ext.classes, { |
| 35 | + sWrapper: "dataTables_wrapper form-inline dt-bootstrap", |
| 36 | + sFilterInput: "form-control input-sm", |
| 37 | + sLengthSelect: "form-control input-sm" |
| 38 | + } ); |
| 39 | + |
| 40 | + |
| 41 | + /* Bootstrap paging button renderer */ |
| 42 | + DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, buttons, page, pages ) { |
| 43 | + var api = new DataTable.Api( settings ); |
| 44 | + var classes = settings.oClasses; |
| 45 | + var lang = settings.oLanguage.oPaginate; |
| 46 | + var btnDisplay, btnClass; |
| 47 | + |
| 48 | + var attach = function( container, buttons ) { |
| 49 | + var i, ien, node, button; |
| 50 | + var clickHandler = function ( e ) { |
| 51 | + e.preventDefault(); |
| 52 | + if ( !$(e.currentTarget).hasClass('disabled') ) { |
| 53 | + api.page( e.data.action ).draw( false ); |
| 54 | + } |
| 55 | + }; |
| 56 | + |
| 57 | + for ( i=0, ien=buttons.length ; i<ien ; i++ ) { |
| 58 | + button = buttons[i]; |
| 59 | + |
| 60 | + if ( $.isArray( button ) ) { |
| 61 | + attach( container, button ); |
| 62 | + } |
| 63 | + else { |
| 64 | + btnDisplay = ''; |
| 65 | + btnClass = ''; |
| 66 | + |
| 67 | + switch ( button ) { |
| 68 | + case 'ellipsis': |
| 69 | + btnDisplay = '…'; |
| 70 | + btnClass = 'disabled'; |
| 71 | + break; |
| 72 | + |
| 73 | + case 'first': |
| 74 | + btnDisplay = lang.sFirst; |
| 75 | + btnClass = button + (page > 0 ? |
| 76 | + '' : ' disabled'); |
| 77 | + break; |
| 78 | + |
| 79 | + case 'previous': |
| 80 | + btnDisplay = lang.sPrevious; |
| 81 | + btnClass = button + (page > 0 ? |
| 82 | + '' : ' disabled'); |
| 83 | + break; |
| 84 | + |
| 85 | + case 'next': |
| 86 | + btnDisplay = lang.sNext; |
| 87 | + btnClass = button + (page < pages-1 ? |
| 88 | + '' : ' disabled'); |
| 89 | + break; |
| 90 | + |
| 91 | + case 'last': |
| 92 | + btnDisplay = lang.sLast; |
| 93 | + btnClass = button + (page < pages-1 ? |
| 94 | + '' : ' disabled'); |
| 95 | + break; |
| 96 | + |
| 97 | + default: |
| 98 | + btnDisplay = button + 1; |
| 99 | + btnClass = page === button ? |
| 100 | + 'active' : ''; |
| 101 | + break; |
| 102 | + } |
183 | 103 |
|
| 104 | + if ( btnDisplay ) { |
| 105 | + node = $('<li>', { |
| 106 | + 'class': classes.sPageButton+' '+btnClass, |
| 107 | + 'aria-controls': settings.sTableId, |
| 108 | + 'tabindex': settings.iTabIndex, |
| 109 | + 'id': idx === 0 && typeof button === 'string' ? |
| 110 | + settings.sTableId +'_'+ button : |
| 111 | + null |
| 112 | + } ) |
| 113 | + .append( $('<a>', { |
| 114 | + 'href': '#' |
| 115 | + } ) |
| 116 | + .html( btnDisplay ) |
| 117 | + ) |
| 118 | + .appendTo( container ); |
| 119 | + |
| 120 | + settings.oApi._fnBindAction( |
| 121 | + node, {action: button}, clickHandler |
| 122 | + ); |
| 123 | + } |
| 124 | + } |
| 125 | + } |
| 126 | + }; |
| 127 | + |
| 128 | + attach( |
| 129 | + $(host).empty().html('<ul class="pagination"/>').children('ul'), |
| 130 | + buttons |
| 131 | + ); |
| 132 | + }; |
| 133 | + |
| 134 | + |
| 135 | + /* |
| 136 | + * TableTools Bootstrap compatibility |
| 137 | + * Required TableTools 2.1+ |
| 138 | + */ |
| 139 | + if ( DataTable.TableTools ) { |
| 140 | + // Set the classes that TableTools uses to something suitable for Bootstrap |
| 141 | + $.extend( true, DataTable.TableTools.classes, { |
| 142 | + "container": "DTTT btn-group", |
| 143 | + "buttons": { |
| 144 | + "normal": "btn btn-default", |
| 145 | + "disabled": "disabled" |
| 146 | + }, |
| 147 | + "collection": { |
| 148 | + "container": "DTTT_dropdown dropdown-menu", |
| 149 | + "buttons": { |
| 150 | + "normal": "", |
| 151 | + "disabled": "disabled" |
| 152 | + } |
| 153 | + }, |
| 154 | + "print": { |
| 155 | + "info": "DTTT_print_info" |
| 156 | + }, |
| 157 | + "select": { |
| 158 | + "row": "active" |
| 159 | + } |
| 160 | + } ); |
184 | 161 |
|
185 | | -})(window, document); |
| 162 | + // Have the collection use a bootstrap compatible drop down |
| 163 | + $.extend( true, DataTable.TableTools.DEFAULTS.oTags, { |
| 164 | + "collection": { |
| 165 | + "container": "ul", |
| 166 | + "button": "li", |
| 167 | + "liner": "a" |
| 168 | + } |
| 169 | + } ); |
| 170 | + } |
| 171 | +})); |
0 commit comments