11/*! DataTables Bootstrap 3 integration
2- * ©2011-2014 SpryMedia Ltd - datatables.net/license
2+ * ©2011-2015 SpryMedia Ltd - datatables.net/license
33 */
44
55/**
1010 * controls using Bootstrap. See http://datatables.net/manual/styling/bootstrap
1111 * for further information.
1212 */
13- ( function ( window , document , undefined ) {
13+ ( function ( factory ) {
14+ if ( typeof define === 'function' && define . amd ) {
15+ // AMD
16+ define ( [ 'jquery' , 'datatables.net' ] , function ( $ ) {
17+ return factory ( $ , window , document ) ;
18+ } ) ;
19+ }
20+ else if ( typeof exports === 'object' ) {
21+ // CommonJS
22+ module . exports = function ( root , $ ) {
23+ if ( ! root ) {
24+ root = window ;
25+ }
26+
27+ if ( ! $ || ! $ . fn . dataTable ) {
28+ // Require DataTables, which attaches to jQuery, including
29+ // jQuery if needed and have a $ property so we can access the
30+ // jQuery object that is used
31+ $ = require ( 'datatables.net' ) ( root , $ ) . $ ;
32+ }
1433
15- var factory = function ( $ , DataTable ) {
16- "use strict" ;
34+ return factory ( $ , root , root . document ) ;
35+ } ;
36+ }
37+ else {
38+ // Browser
39+ factory ( jQuery , window , document ) ;
40+ }
41+ } ( function ( $ , window , document , undefined ) {
42+ 'use strict' ;
43+ var DataTable = $ . fn . dataTable ;
1744
1845
1946/* Set the defaults for DataTables initialisation */
@@ -30,7 +57,8 @@ $.extend( true, DataTable.defaults, {
3057$ . extend ( DataTable . ext . classes , {
3158 sWrapper : "dataTables_wrapper form-inline dt-bootstrap" ,
3259 sFilterInput : "form-control input-sm" ,
33- sLengthSelect : "form-control input-sm"
60+ sLengthSelect : "form-control input-sm" ,
61+ sProcessing : "dataTables_processing panel panel-default"
3462} ) ;
3563
3664
@@ -39,14 +67,15 @@ DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, bu
3967 var api = new DataTable . Api ( settings ) ;
4068 var classes = settings . oClasses ;
4169 var lang = settings . oLanguage . oPaginate ;
42- var btnDisplay , btnClass ;
70+ var aria = settings . oLanguage . oAria . paginate || { } ;
71+ var btnDisplay , btnClass , counter = 0 ;
4372
4473 var attach = function ( container , buttons ) {
4574 var i , ien , node , button ;
4675 var clickHandler = function ( e ) {
4776 e . preventDefault ( ) ;
48- if ( ! $ ( e . currentTarget ) . hasClass ( 'disabled' ) ) {
49- api . page ( e . data . action ) . draw ( false ) ;
77+ if ( ! $ ( e . currentTarget ) . hasClass ( 'disabled' ) && api . page ( ) != e . data . action ) {
78+ api . page ( e . data . action ) . draw ( 'page' ) ;
5079 }
5180 } ;
5281
@@ -62,7 +91,7 @@ DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, bu
6291
6392 switch ( button ) {
6493 case 'ellipsis' :
65- btnDisplay = '&hellip ;' ;
94+ btnDisplay = '… ;' ;
6695 btnClass = 'disabled' ;
6796 break ;
6897
@@ -100,14 +129,16 @@ DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, bu
100129 if ( btnDisplay ) {
101130 node = $ ( '<li>' , {
102131 'class' : classes . sPageButton + ' ' + btnClass ,
103- 'aria-controls' : settings . sTableId ,
104- 'tabindex' : settings . iTabIndex ,
105132 'id' : idx === 0 && typeof button === 'string' ?
106133 settings . sTableId + '_' + button :
107134 null
108135 } )
109136 . append ( $ ( '<a>' , {
110- 'href' : '#'
137+ 'href' : '#' ,
138+ 'aria-controls' : settings . sTableId ,
139+ 'aria-label' : aria [ button ] ,
140+ 'data-dt-idx' : counter ,
141+ 'tabindex' : settings . iTabIndex
111142 } )
112143 . html ( btnDisplay )
113144 )
@@ -116,15 +147,34 @@ DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, bu
116147 settings . oApi . _fnBindAction (
117148 node , { action : button } , clickHandler
118149 ) ;
150+
151+ counter ++ ;
119152 }
120153 }
121154 }
122155 } ;
123156
157+ // IE9 throws an 'unknown error' if document.activeElement is used
158+ // inside an iframe or frame.
159+ var activeEl ;
160+
161+ try {
162+ // Because this approach is destroying and recreating the paging
163+ // elements, focus is lost on the select button which is bad for
164+ // accessibility. So we want to restore focus once the draw has
165+ // completed
166+ activeEl = $ ( host ) . find ( document . activeElement ) . data ( 'dt-idx' ) ;
167+ }
168+ catch ( e ) { }
169+
124170 attach (
125171 $ ( host ) . empty ( ) . html ( '<ul class="pagination"/>' ) . children ( 'ul' ) ,
126172 buttons
127173 ) ;
174+
175+ if ( activeEl ) {
176+ $ ( host ) . find ( '[data-dt-idx=' + activeEl + ']' ) . focus ( ) ;
177+ }
128178} ;
129179
130180
@@ -165,21 +215,6 @@ if ( DataTable.TableTools ) {
165215 } ) ;
166216}
167217
168- } ; // /factory
169-
170-
171- // Define as an AMD module if possible
172- if ( typeof define === 'function' && define . amd ) {
173- define ( [ 'jquery' , 'datatables' ] , factory ) ;
174- }
175- else if ( typeof exports === 'object' ) {
176- // Node/CommonJS
177- factory ( require ( 'jquery' ) , require ( 'datatables' ) ) ;
178- }
179- else if ( jQuery ) {
180- // Otherwise simply initialise as normal, stopping multiple evaluation
181- factory ( jQuery , jQuery . fn . dataTable ) ;
182- }
183-
184218
185- } ) ( window , document ) ;
219+ return DataTable ;
220+ } ) ) ;
0 commit comments