1 /*! DataTables Foundation integration
2 * ©2011-2015 SpryMedia Ltd - datatables.net/license
6 * DataTables integration for Foundation. This requires Foundation 5 and
7 * DataTables 1.10 or newer.
9 * This file sets the defaults and adds options to DataTables to style its
10 * controls using Foundation. See http://datatables.net/manual/styling/foundation
11 * for further information.
14 if ( typeof define === 'function' && define.amd ) {
16 define( ['jquery', 'datatables.net'], function ( $ ) {
17 return factory( $, window, document );
20 else if ( typeof exports === 'object' ) {
22 module.exports = function (root, $) {
27 if ( ! $ || ! $.fn.dataTable ) {
28 $ = require('datatables.net')(root, $).$;
31 return factory( $, root, root.document );
36 factory( jQuery, window, document );
38 }(function( $, window, document, undefined ) {
40 var DataTable = $.fn.dataTable;
42 // Detect Foundation 5 / 6 as they have different element and class requirements
43 var meta = $('<meta class="foundation-mq"/>').appendTo('head');
44 DataTable.ext.foundationVersion = meta.css('font-family').match(/small|medium|large/) ? 6 : 5;
48 $.extend( DataTable.ext.classes, {
49 sWrapper: "dataTables_wrapper dt-foundation",
50 sProcessing: "dataTables_processing panel"
54 /* Set the defaults for DataTables initialisation */
55 $.extend( true, DataTable.defaults, {
57 "<'row'<'small-6 columns'l><'small-6 columns'f>r>"+
59 "<'row'<'small-6 columns'i><'small-6 columns'p>>",
60 renderer: 'foundation'
64 /* Page button renderer */
65 DataTable.ext.renderer.pageButton.foundation = function ( settings, host, idx, buttons, page, pages ) {
66 var api = new DataTable.Api( settings );
67 var classes = settings.oClasses;
68 var lang = settings.oLanguage.oPaginate;
69 var aria = settings.oLanguage.oAria.paginate || {};
70 var btnDisplay, btnClass;
72 var v5 = DataTable.ext.foundationVersion === 5;
74 var attach = function( container, buttons ) {
75 var i, ien, node, button;
76 var clickHandler = function ( e ) {
78 if ( !$(e.currentTarget).hasClass('unavailable') && api.page() != e.data.action ) {
79 api.page( e.data.action ).draw( 'page' );
83 for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
86 if ( $.isArray( button ) ) {
87 attach( container, button );
96 btnDisplay = '…';
97 btnClass = 'unavailable disabled';
102 btnDisplay = lang.sFirst;
103 btnClass = button + (page > 0 ?
104 '' : ' unavailable disabled');
105 tag = page > 0 ? 'a' : null;
109 btnDisplay = lang.sPrevious;
110 btnClass = button + (page > 0 ?
111 '' : ' unavailable disabled');
112 tag = page > 0 ? 'a' : null;
116 btnDisplay = lang.sNext;
117 btnClass = button + (page < pages-1 ?
118 '' : ' unavailable disabled');
119 tag = page < pages-1 ? 'a' : null;
123 btnDisplay = lang.sLast;
124 btnClass = button + (page < pages-1 ?
125 '' : ' unavailable disabled');
126 tag = page < pages-1 ? 'a' : null;
130 btnDisplay = button + 1;
131 btnClass = page === button ?
133 tag = page === button ?
144 'class': classes.sPageButton+' '+btnClass,
145 'aria-controls': settings.sTableId,
146 'aria-label': aria[ button ],
147 'tabindex': settings.iTabIndex,
148 'id': idx === 0 && typeof button === 'string' ?
149 settings.sTableId +'_'+ button :
153 $('<'+tag+'/>', {'href': '#'} ).html( btnDisplay ) :
156 .appendTo( container );
158 settings.oApi._fnBindAction(
159 node, {action: button}, clickHandler
167 $(host).empty().html('<ul class="pagination"/>').children('ul'),