|
|
@ -1,266 +1,137 @@
|
|
|
|
/* Set the defaults for DataTables initialisation */
|
|
|
|
/*! DataTables Foundation integration
|
|
|
|
$.extend( true, $.fn.dataTable.defaults, {
|
|
|
|
* ©2011-2014 SpryMedia Ltd - datatables.net/license
|
|
|
|
"sDom":
|
|
|
|
*/
|
|
|
|
"<'row'<'small-6 columns'l><'small-6 columns'f>r>"+
|
|
|
|
|
|
|
|
"t"+
|
|
|
|
|
|
|
|
"<'row'<'small-6 columns'i><'small-6 columns'p>>",
|
|
|
|
|
|
|
|
"oLanguage": {
|
|
|
|
|
|
|
|
"sLengthMenu": "_MENU_ records per page"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// In 1.10 we use the pagination renderers to draw the Bootstrap paging,
|
|
|
|
|
|
|
|
// rather than custom plug-in
|
|
|
|
|
|
|
|
if ( $.fn.dataTable.Api ) {
|
|
|
|
|
|
|
|
$.fn.dataTable.defaults.renderer = 'foundation';
|
|
|
|
|
|
|
|
$.fn.dataTable.ext.renderer.pageButton.foundation = function ( settings, host, idx, buttons, page, pages ) {
|
|
|
|
|
|
|
|
var api = new $.fn.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.data.action !== 'ellipsis' ) {
|
|
|
|
|
|
|
|
api.page( e.data.action ).draw( false );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
|
|
|
|
|
|
|
|
button = buttons[i];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( $.isArray( button ) ) {
|
|
|
|
/**
|
|
|
|
attach( container, button );
|
|
|
|
* DataTables integration for Foundation. This requires Foundation 5 and
|
|
|
|
}
|
|
|
|
* DataTables 1.10 or newer.
|
|
|
|
else {
|
|
|
|
*
|
|
|
|
btnDisplay = '';
|
|
|
|
* This file sets the defaults and adds options to DataTables to style its
|
|
|
|
btnClass = '';
|
|
|
|
* controls using Foundation. See http://datatables.net/manual/styling/foundation
|
|
|
|
|
|
|
|
* for further information.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function(window, document, undefined){
|
|
|
|
|
|
|
|
|
|
|
|
switch ( button ) {
|
|
|
|
var factory = function( $, DataTable ) {
|
|
|
|
case 'ellipsis':
|
|
|
|
"use strict";
|
|
|
|
btnDisplay = '…';
|
|
|
|
|
|
|
|
btnClass = 'unavailable';
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'first':
|
|
|
|
|
|
|
|
btnDisplay = lang.sFirst;
|
|
|
|
|
|
|
|
btnClass = button + (page > 0 ?
|
|
|
|
|
|
|
|
'' : ' unavailable');
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'previous':
|
|
|
|
$.extend( DataTable.ext.classes, {
|
|
|
|
btnDisplay = lang.sPrevious;
|
|
|
|
sWrapper: "dataTables_wrapper dt-foundation"
|
|
|
|
btnClass = button + (page > 0 ?
|
|
|
|
} );
|
|
|
|
'' : ' unavailable');
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'next':
|
|
|
|
|
|
|
|
btnDisplay = lang.sNext;
|
|
|
|
|
|
|
|
btnClass = button + (page < pages-1 ?
|
|
|
|
|
|
|
|
'' : ' unavailable');
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'last':
|
|
|
|
/* Set the defaults for DataTables initialisation */
|
|
|
|
btnDisplay = lang.sLast;
|
|
|
|
$.extend( true, DataTable.defaults, {
|
|
|
|
btnClass = button + (page < pages-1 ?
|
|
|
|
dom:
|
|
|
|
'' : ' unavailable');
|
|
|
|
"<'row'<'small-6 columns'l><'small-6 columns'f>r>"+
|
|
|
|
break;
|
|
|
|
"t"+
|
|
|
|
|
|
|
|
"<'row'<'small-6 columns'i><'small-6 columns'p>>",
|
|
|
|
|
|
|
|
renderer: 'foundation'
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
btnDisplay = button + 1;
|
|
|
|
|
|
|
|
btnClass = page === button ?
|
|
|
|
|
|
|
|
'current' : '';
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( btnDisplay ) {
|
|
|
|
/* Page button renderer */
|
|
|
|
node = $('<li>', {
|
|
|
|
DataTable.ext.renderer.pageButton.foundation = function ( settings, host, idx, buttons, page, pages ) {
|
|
|
|
'class': classes.sPageButton+' '+btnClass,
|
|
|
|
var api = new DataTable.Api( settings );
|
|
|
|
'aria-controls': settings.sTableId,
|
|
|
|
var classes = settings.oClasses;
|
|
|
|
'tabindex': settings.iTabIndex,
|
|
|
|
var lang = settings.oLanguage.oPaginate;
|
|
|
|
'id': idx === 0 && typeof button === 'string' ?
|
|
|
|
var btnDisplay, btnClass;
|
|
|
|
settings.sTableId +'_'+ button :
|
|
|
|
|
|
|
|
null
|
|
|
|
|
|
|
|
} )
|
|
|
|
|
|
|
|
.append( $('<a>', {
|
|
|
|
|
|
|
|
'href': '#'
|
|
|
|
|
|
|
|
} )
|
|
|
|
|
|
|
|
.html( btnDisplay )
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.appendTo( container );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
settings.oApi._fnBindAction(
|
|
|
|
var attach = function( container, buttons ) {
|
|
|
|
node, {action: button}, clickHandler
|
|
|
|
var i, ien, node, button;
|
|
|
|
);
|
|
|
|
var clickHandler = function ( e ) {
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
if ( e.data.action !== 'ellipsis' ) {
|
|
|
|
|
|
|
|
api.page( e.data.action ).draw( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
attach(
|
|
|
|
for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
|
|
|
|
$(host).empty().html('<ul class="pagination"/>').children('ul'),
|
|
|
|
button = buttons[i];
|
|
|
|
buttons
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
// Integration for 1.9-
|
|
|
|
|
|
|
|
$.fn.dataTable.defaults.sPaginationType = 'foundation';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* API method to get paging information */
|
|
|
|
|
|
|
|
$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
"iStart": oSettings._iDisplayStart,
|
|
|
|
|
|
|
|
"iEnd": oSettings.fnDisplayEnd(),
|
|
|
|
|
|
|
|
"iLength": oSettings._iDisplayLength,
|
|
|
|
|
|
|
|
"iTotal": oSettings.fnRecordsTotal(),
|
|
|
|
|
|
|
|
"iFilteredTotal": oSettings.fnRecordsDisplay(),
|
|
|
|
|
|
|
|
"iPage": oSettings._iDisplayLength === -1 ?
|
|
|
|
|
|
|
|
0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
|
|
|
|
|
|
|
|
"iTotalPages": oSettings._iDisplayLength === -1 ?
|
|
|
|
|
|
|
|
0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Bootstrap style pagination control */
|
|
|
|
if ( $.isArray( button ) ) {
|
|
|
|
$.extend( $.fn.dataTableExt.oPagination, {
|
|
|
|
attach( container, button );
|
|
|
|
"foundation": {
|
|
|
|
}
|
|
|
|
"fnInit": function( oSettings, nPaging, fnDraw ) {
|
|
|
|
else {
|
|
|
|
var oLang = oSettings.oLanguage.oPaginate;
|
|
|
|
btnDisplay = '';
|
|
|
|
var fnClickHandler = function ( e ) {
|
|
|
|
btnClass = '';
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
|
|
|
|
switch ( button ) {
|
|
|
|
fnDraw( oSettings );
|
|
|
|
case 'ellipsis':
|
|
|
|
}
|
|
|
|
btnDisplay = '…';
|
|
|
|
};
|
|
|
|
btnClass = 'unavailable';
|
|
|
|
|
|
|
|
break;
|
|
|
|
$(nPaging).append(
|
|
|
|
|
|
|
|
'<ul class="pagination">'+
|
|
|
|
case 'first':
|
|
|
|
'<li class="prev arrow unavailable"><a href="">«</a></li>'+
|
|
|
|
btnDisplay = lang.sFirst;
|
|
|
|
'<li class="next arrow unavailable"><a href="">»</a></li>'+
|
|
|
|
btnClass = button + (page > 0 ?
|
|
|
|
'</ul>'
|
|
|
|
'' : ' unavailable');
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
var els = $('a', nPaging);
|
|
|
|
|
|
|
|
$(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
|
|
|
|
case 'previous':
|
|
|
|
$(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
|
|
|
|
btnDisplay = lang.sPrevious;
|
|
|
|
},
|
|
|
|
btnClass = button + (page > 0 ?
|
|
|
|
|
|
|
|
'' : ' unavailable');
|
|
|
|
"fnUpdate": function ( oSettings, fnDraw ) {
|
|
|
|
break;
|
|
|
|
var iListLength = 5;
|
|
|
|
|
|
|
|
var oPaging = oSettings.oInstance.fnPagingInfo();
|
|
|
|
case 'next':
|
|
|
|
var an = oSettings.aanFeatures.p;
|
|
|
|
btnDisplay = lang.sNext;
|
|
|
|
var pages = [];
|
|
|
|
btnClass = button + (page < pages-1 ?
|
|
|
|
var i, ien, klass, host;
|
|
|
|
'' : ' unavailable');
|
|
|
|
|
|
|
|
break;
|
|
|
|
// This could use some improving - however, see
|
|
|
|
|
|
|
|
// https://github.com/DataTables/DataTables/issues/163 - this will
|
|
|
|
case 'last':
|
|
|
|
// be changing in the near future, so not much point in doing too
|
|
|
|
btnDisplay = lang.sLast;
|
|
|
|
// much just now
|
|
|
|
btnClass = button + (page < pages-1 ?
|
|
|
|
if ( oPaging.iTotalPages <= 6 ) {
|
|
|
|
'' : ' unavailable');
|
|
|
|
for ( i=0 ; i<oPaging.iTotalPages ; i++ ) {
|
|
|
|
break;
|
|
|
|
pages.push( i );
|
|
|
|
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
btnDisplay = button + 1;
|
|
|
|
else {
|
|
|
|
btnClass = page === button ?
|
|
|
|
// Current page
|
|
|
|
'current' : '';
|
|
|
|
pages.push( oPaging.iPage );
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// After current page
|
|
|
|
|
|
|
|
var pagesAfter = oPaging.iPage + 2 >= oPaging.iTotalPages ?
|
|
|
|
|
|
|
|
oPaging.iTotalPages :
|
|
|
|
|
|
|
|
oPaging.iPage + 2;
|
|
|
|
|
|
|
|
for ( i=oPaging.iPage+1 ; i<pagesAfter ; i++ ) {
|
|
|
|
|
|
|
|
pages.push( i );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// After gap
|
|
|
|
|
|
|
|
if ( pagesAfter < oPaging.iTotalPages-2 ) {
|
|
|
|
|
|
|
|
pages.push( null );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// End
|
|
|
|
|
|
|
|
if ( $.inArray( oPaging.iTotalPages-2, pages ) === -1 && oPaging.iPage < oPaging.iTotalPages-2 ) {
|
|
|
|
|
|
|
|
pages.push( oPaging.iTotalPages-2 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $.inArray( oPaging.iTotalPages-1, pages ) === -1 ) {
|
|
|
|
|
|
|
|
pages.push( oPaging.iTotalPages-1 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pages before
|
|
|
|
|
|
|
|
var pagesBefore = oPaging.iPage - 2 > 0 ?
|
|
|
|
|
|
|
|
oPaging.iPage - 2 :
|
|
|
|
|
|
|
|
0;
|
|
|
|
|
|
|
|
for ( i=oPaging.iPage-1 ; i>pagesBefore ; i-- ) {
|
|
|
|
|
|
|
|
pages.unshift( i );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Before gap
|
|
|
|
|
|
|
|
if ( pagesBefore > 1 ) {
|
|
|
|
|
|
|
|
pages.unshift( null );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start
|
|
|
|
|
|
|
|
if ( $.inArray( 1, pages ) === -1 && oPaging.iTotalPages > 1 ) {
|
|
|
|
|
|
|
|
pages.unshift( 1 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $.inArray( 0, pages ) === -1 ) {
|
|
|
|
|
|
|
|
pages.unshift( 0 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for ( i=0, ien=an.length ; i<ien ; i++ ) {
|
|
|
|
if ( btnDisplay ) {
|
|
|
|
// Remove the middle elements
|
|
|
|
node = $('<li>', {
|
|
|
|
host = an[i];
|
|
|
|
'class': classes.sPageButton+' '+btnClass,
|
|
|
|
$('li:gt(0)', host).filter(':not(:last)').remove();
|
|
|
|
'aria-controls': settings.sTableId,
|
|
|
|
|
|
|
|
'tabindex': settings.iTabIndex,
|
|
|
|
// Add the new list items and their event handlers
|
|
|
|
'id': idx === 0 && typeof button === 'string' ?
|
|
|
|
$.each( pages, function( i, page ) {
|
|
|
|
settings.sTableId +'_'+ button :
|
|
|
|
klass = page === null ? 'unavailable' :
|
|
|
|
null
|
|
|
|
page === oPaging.iPage ? 'current' : '';
|
|
|
|
} )
|
|
|
|
$('<li class="'+klass+'"><a href="">'+(page===null? '…' : page+1)+'</a></li>')
|
|
|
|
.append( $('<a>', {
|
|
|
|
.insertBefore( $('li:last', host) )
|
|
|
|
'href': '#'
|
|
|
|
.bind('click', function (e) {
|
|
|
|
} )
|
|
|
|
e.preventDefault();
|
|
|
|
.html( btnDisplay )
|
|
|
|
var pageNum = parseInt($('a', this).text(),10);
|
|
|
|
)
|
|
|
|
if ( ! isNaN(pageNum)) {
|
|
|
|
.appendTo( container );
|
|
|
|
oSettings._iDisplayStart = (pageNum-1) * oPaging.iLength;
|
|
|
|
|
|
|
|
fnDraw( oSettings );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add / remove disabled classes from the static elements
|
|
|
|
|
|
|
|
if ( oPaging.iPage === 0 ) {
|
|
|
|
|
|
|
|
$('li:first', host).addClass('unavailable');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$('li:first', host).removeClass('unavailable');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
|
|
|
|
settings.oApi._fnBindAction(
|
|
|
|
$('li:last', host).addClass('unavailable');
|
|
|
|
node, {action: button}, clickHandler
|
|
|
|
} else {
|
|
|
|
);
|
|
|
|
$('li:last', host).removeClass('unavailable');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
attach(
|
|
|
|
|
|
|
|
$(host).empty().html('<ul class="pagination"/>').children('ul'),
|
|
|
|
|
|
|
|
buttons
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* TableTools Foundation compatibility
|
|
|
|
* TableTools Foundation compatibility
|
|
|
|
* Required TableTools 2.1+
|
|
|
|
* Required TableTools 2.1+
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
if ( $.fn.DataTable.TableTools ) {
|
|
|
|
if ( DataTable.TableTools ) {
|
|
|
|
// Set the classes that TableTools uses to something suitable for Foundation
|
|
|
|
// Set the classes that TableTools uses to something suitable for Foundation
|
|
|
|
$.extend( true, $.fn.DataTable.TableTools.classes, {
|
|
|
|
$.extend( true, DataTable.TableTools.classes, {
|
|
|
|
"container": "DTTT button-group",
|
|
|
|
"container": "DTTT button-group",
|
|
|
|
"buttons": {
|
|
|
|
"buttons": {
|
|
|
|
"normal": "button",
|
|
|
|
"normal": "button",
|
|
|
@ -279,7 +150,7 @@ if ( $.fn.DataTable.TableTools ) {
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
// Have the collection use a bootstrap compatible dropdown
|
|
|
|
// Have the collection use a bootstrap compatible dropdown
|
|
|
|
$.extend( true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {
|
|
|
|
$.extend( true, DataTable.TableTools.DEFAULTS.oTags, {
|
|
|
|
"collection": {
|
|
|
|
"collection": {
|
|
|
|
"container": "ul",
|
|
|
|
"container": "ul",
|
|
|
|
"button": "li",
|
|
|
|
"button": "li",
|
|
|
@ -288,3 +159,22 @@ if ( $.fn.DataTable.TableTools ) {
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; // /factory
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Define as an AMD module if possible
|
|
|
|
|
|
|
|
if ( typeof define === 'function' && define.amd ) {
|
|
|
|
|
|
|
|
define( ['jquery', 'datatables'], factory );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ( typeof exports === 'object' ) {
|
|
|
|
|
|
|
|
// Node/CommonJS
|
|
|
|
|
|
|
|
factory( require('jquery'), require('datatables') );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ( jQuery ) {
|
|
|
|
|
|
|
|
// Otherwise simply initialise as normal, stopping multiple evaluation
|
|
|
|
|
|
|
|
factory( jQuery, jQuery.fn.dataTable );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})(window, document);
|
|
|
|
|
|
|
|
|
|
|
|