mirror of
https://github.com/DataTables/DataTables.git
synced 2024-12-02 14:24:11 +01:00
c0cb3db92f
New: CommonJS will load jQuery if it wasn't passed in Fix: Bootstrap, Foundation and jQuery UI integration Javascript files use module.exports correctly Dev: Change the file include "function" name to not conflict with `require` - AMD / RequireJS - The Require documentation strongly discorages using a named module, but I've used this in the past as the plug-ins need a name to depend upon themselves. This is still `datatables` but if the developer is using Require and it resolves automatically to a different name (which it may depending upon their configuration) they can use a map option to map their name to `datatables`. See https://github.com/moment/moment/issues/1095 - CommonJS - Based on the disscussion in https://github.com/DataTables/Plugins/issues/199 it seems that some developers like to pass a certain version of jQuery in. This modification allows them to do so while retaining backwards compatiblity. - Integration files - The UMD wrapper for these files have been restructured to be easier to follow. Also, based on the discussion in the Plugins issue noted above you can now pass in a jQuery instance or not and likewise a DataTables object or not. - To avoid direct conflict with `require()` the build scripts have been updated to use a "function" called `_buildInclude`. Ultimatily this should really be updated to use grunt or similar.
145 lines
3.4 KiB
JavaScript
145 lines
3.4 KiB
JavaScript
/*! DataTables Foundation integration
|
|
* ©2011-2015 SpryMedia Ltd - datatables.net/license
|
|
*/
|
|
|
|
/**
|
|
* DataTables integration for Foundation. This requires Foundation 5 and
|
|
* DataTables 1.10 or newer.
|
|
*
|
|
* This file sets the defaults and adds options to DataTables to style its
|
|
* controls using Foundation. See http://datatables.net/manual/styling/foundation
|
|
* for further information.
|
|
*/
|
|
(function( factory ){
|
|
if ( typeof define === 'function' && define.amd ) {
|
|
// AMD
|
|
define( ['jquery', 'datatables'], factory );
|
|
}
|
|
else if ( typeof exports === 'object' ) {
|
|
// Node / CommonJS
|
|
module.exports = function ($, dt) {
|
|
if ( ! $ ) { $ = require('jquery'); }
|
|
factory( $, dt || $.fn.dataTable || require('datatables') );
|
|
};
|
|
}
|
|
else if ( jQuery ) {
|
|
// Browser standard
|
|
factory( jQuery, jQuery.fn.dataTable );
|
|
}
|
|
}(function( $, DataTable ) {
|
|
'use strict';
|
|
|
|
|
|
$.extend( DataTable.ext.classes, {
|
|
sWrapper: "dataTables_wrapper dt-foundation",
|
|
sProcessing: "dataTables_processing panel"
|
|
} );
|
|
|
|
|
|
/* Set the defaults for DataTables initialisation */
|
|
$.extend( true, DataTable.defaults, {
|
|
dom:
|
|
"<'row'<'small-6 columns'l><'small-6 columns'f>r>"+
|
|
"t"+
|
|
"<'row'<'small-6 columns'i><'small-6 columns'p>>",
|
|
renderer: 'foundation'
|
|
} );
|
|
|
|
|
|
/* Page button renderer */
|
|
DataTable.ext.renderer.pageButton.foundation = function ( settings, host, idx, buttons, page, pages ) {
|
|
var api = new DataTable.Api( settings );
|
|
var classes = settings.oClasses;
|
|
var lang = settings.oLanguage.oPaginate;
|
|
var btnDisplay, btnClass;
|
|
|
|
var attach = function( container, buttons ) {
|
|
var i, ien, node, button;
|
|
var clickHandler = function ( e ) {
|
|
e.preventDefault();
|
|
if ( !$(e.currentTarget).hasClass('unavailable') && api.page() != e.data.action ) {
|
|
api.page( e.data.action ).draw( 'page' );
|
|
}
|
|
};
|
|
|
|
for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
|
|
button = buttons[i];
|
|
|
|
if ( $.isArray( button ) ) {
|
|
attach( container, button );
|
|
}
|
|
else {
|
|
btnDisplay = '';
|
|
btnClass = '';
|
|
|
|
switch ( button ) {
|
|
case 'ellipsis':
|
|
btnDisplay = '…';
|
|
btnClass = 'unavailable';
|
|
break;
|
|
|
|
case 'first':
|
|
btnDisplay = lang.sFirst;
|
|
btnClass = button + (page > 0 ?
|
|
'' : ' unavailable');
|
|
break;
|
|
|
|
case 'previous':
|
|
btnDisplay = lang.sPrevious;
|
|
btnClass = button + (page > 0 ?
|
|
'' : ' unavailable');
|
|
break;
|
|
|
|
case 'next':
|
|
btnDisplay = lang.sNext;
|
|
btnClass = button + (page < pages-1 ?
|
|
'' : ' unavailable');
|
|
break;
|
|
|
|
case 'last':
|
|
btnDisplay = lang.sLast;
|
|
btnClass = button + (page < pages-1 ?
|
|
'' : ' unavailable');
|
|
break;
|
|
|
|
default:
|
|
btnDisplay = button + 1;
|
|
btnClass = page === button ?
|
|
'current' : '';
|
|
break;
|
|
}
|
|
|
|
if ( btnDisplay ) {
|
|
node = $('<li>', {
|
|
'class': classes.sPageButton+' '+btnClass,
|
|
'aria-controls': settings.sTableId,
|
|
'tabindex': settings.iTabIndex,
|
|
'id': idx === 0 && typeof button === 'string' ?
|
|
settings.sTableId +'_'+ button :
|
|
null
|
|
} )
|
|
.append( $('<a>', {
|
|
'href': '#'
|
|
} )
|
|
.html( btnDisplay )
|
|
)
|
|
.appendTo( container );
|
|
|
|
settings.oApi._fnBindAction(
|
|
node, {action: button}, clickHandler
|
|
);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
attach(
|
|
$(host).empty().html('<ul class="pagination"/>').children('ul'),
|
|
buttons
|
|
);
|
|
};
|
|
|
|
|
|
return DataTable;
|
|
}));
|