fixed static file collection for third party components: now relying on symlinks
[myslice.git] / third-party / datatables-1.9.4 / js / dataTables.bootstrap.js
1 /* Set the defaults for DataTables initialisation */
2 $.extend( true, $.fn.dataTable.defaults, {
3         "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
4         "sPaginationType": "bootstrap",
5         "oLanguage": {
6                 "sLengthMenu": "_MENU_ records per page"
7         }
8 } );
9
10
11 /* Default class modification */
12 $.extend( $.fn.dataTableExt.oStdClasses, {
13         "sWrapper": "dataTables_wrapper form-inline"
14 } );
15
16
17 /* API method to get paging information */
18 $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
19 {
20         return {
21                 "iStart":         oSettings._iDisplayStart,
22                 "iEnd":           oSettings.fnDisplayEnd(),
23                 "iLength":        oSettings._iDisplayLength,
24                 "iTotal":         oSettings.fnRecordsTotal(),
25                 "iFilteredTotal": oSettings.fnRecordsDisplay(),
26                 "iPage":          oSettings._iDisplayLength === -1 ?
27                         0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
28                 "iTotalPages":    oSettings._iDisplayLength === -1 ?
29                         0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
30         };
31 };
32
33
34 /* Bootstrap style pagination control */
35 $.extend( $.fn.dataTableExt.oPagination, {
36         "bootstrap": {
37                 "fnInit": function( oSettings, nPaging, fnDraw ) {
38                         var oLang = oSettings.oLanguage.oPaginate;
39                         var fnClickHandler = function ( e ) {
40                                 e.preventDefault();
41                                 if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
42                                         fnDraw( oSettings );
43                                 }
44                         };
45
46                         $(nPaging).addClass('pagination').append(
47                                 '<ul>'+
48                                         '<li class="prev disabled"><a href="#">&larr; '+oLang.sPrevious+'</a></li>'+
49                                         '<li class="next disabled"><a href="#">'+oLang.sNext+' &rarr; </a></li>'+
50                                 '</ul>'
51                         );
52                         var els = $('a', nPaging);
53                         $(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
54                         $(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
55                 },
56
57                 "fnUpdate": function ( oSettings, fnDraw ) {
58                         var iListLength = 5;
59                         var oPaging = oSettings.oInstance.fnPagingInfo();
60                         var an = oSettings.aanFeatures.p;
61                         var i, ien, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2);
62
63                         if ( oPaging.iTotalPages < iListLength) {
64                                 iStart = 1;
65                                 iEnd = oPaging.iTotalPages;
66                         }
67                         else if ( oPaging.iPage <= iHalf ) {
68                                 iStart = 1;
69                                 iEnd = iListLength;
70                         } else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
71                                 iStart = oPaging.iTotalPages - iListLength + 1;
72                                 iEnd = oPaging.iTotalPages;
73                         } else {
74                                 iStart = oPaging.iPage - iHalf + 1;
75                                 iEnd = iStart + iListLength - 1;
76                         }
77
78                         for ( i=0, ien=an.length ; i<ien ; i++ ) {
79                                 // Remove the middle elements
80                                 $('li:gt(0)', an[i]).filter(':not(:last)').remove();
81
82                                 // Add the new list items and their event handlers
83                                 for ( j=iStart ; j<=iEnd ; j++ ) {
84                                         sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
85                                         $('<li '+sClass+'><a href="#">'+j+'</a></li>')
86                                                 .insertBefore( $('li:last', an[i])[0] )
87                                                 .bind('click', function (e) {
88                                                         e.preventDefault();
89                                                         oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
90                                                         fnDraw( oSettings );
91                                                 } );
92                                 }
93
94                                 // Add / remove disabled classes from the static elements
95                                 if ( oPaging.iPage === 0 ) {
96                                         $('li:first', an[i]).addClass('disabled');
97                                 } else {
98                                         $('li:first', an[i]).removeClass('disabled');
99                                 }
100
101                                 if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
102                                         $('li:last', an[i]).addClass('disabled');
103                                 } else {
104                                         $('li:last', an[i]).removeClass('disabled');
105                                 }
106                         }
107                 }
108         }
109 } );
110
111
112 /*
113  * TableTools Bootstrap compatibility
114  * Required TableTools 2.1+
115  */
116 if ( $.fn.DataTable.TableTools ) {
117         // Set the classes that TableTools uses to something suitable for Bootstrap
118         $.extend( true, $.fn.DataTable.TableTools.classes, {
119                 "container": "DTTT btn-group",
120                 "buttons": {
121                         "normal": "btn",
122                         "disabled": "disabled"
123                 },
124                 "collection": {
125                         "container": "DTTT_dropdown dropdown-menu",
126                         "buttons": {
127                                 "normal": "",
128                                 "disabled": "disabled"
129                         }
130                 },
131                 "print": {
132                         "info": "DTTT_print_info modal"
133                 },
134                 "select": {
135                         "row": "active"
136                 }
137         } );
138
139         // Have the collection use a bootstrap compatible dropdown
140         $.extend( true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {
141                 "collection": {
142                         "container": "ul",
143                         "button": "li",
144                         "liner": "a"
145                 }
146         } );
147 }
148