NPM libs: Update embedded package to avoid their dependencies to be retrieved as they are already their

This commit is contained in:
Molkobain
2021-03-29 11:10:53 +02:00
parent a29dac2c60
commit c11fd4f0ab
42 changed files with 1601 additions and 63390 deletions

View File

@@ -1,15 +1,15 @@
/*! Responsive 2.1.0
* 2014-2016 SpryMedia Ltd - datatables.net/license
/*! Responsive 2.2.7
* 2014-2021 SpryMedia Ltd - datatables.net/license
*/
/**
* @summary Responsive
* @description Responsive tables plug-in for DataTables
* @version 2.1.0
* @version 2.2.7
* @file dataTables.responsive.js
* @author SpryMedia Ltd (www.sprymedia.co.uk)
* @contact www.sprymedia.co.uk/contact
* @copyright Copyright 2014-2016 SpryMedia Ltd.
* @copyright Copyright 2014-2021 SpryMedia Ltd.
*
* This source file is free software, available under the following license:
* MIT license - http://datatables.net/license/mit
@@ -97,8 +97,8 @@ var DataTable = $.fn.dataTable;
*/
var Responsive = function ( settings, opts ) {
// Sanity check that we are using DataTables 1.10 or newer
if ( ! DataTable.versionCheck || ! DataTable.versionCheck( '1.10.3' ) ) {
throw 'DataTables Responsive requires DataTables 1.10.3 or newer';
if ( ! DataTable.versionCheck || ! DataTable.versionCheck( '1.10.10' ) ) {
throw 'DataTables Responsive requires DataTables 1.10.10 or newer';
}
this.s = {
@@ -144,7 +144,7 @@ $.extend( Responsive.prototype, {
var that = this;
var dt = this.s.dt;
var dtPrivateSettings = dt.settings()[0];
var oldWindowWidth = $(window).width();
var oldWindowWidth = $(window).innerWidth();
dt.settings()[0]._responsive = this;
@@ -153,7 +153,7 @@ $.extend( Responsive.prototype, {
$(window).on( 'resize.dtr orientationchange.dtr', DataTable.util.throttle( function () {
// iOS has a bug whereby resize can fire when only scrolling
// See: http://stackoverflow.com/questions/8898412
var width = $(window).width();
var width = $(window).innerWidth();
if ( width !== oldWindowWidth ) {
that._resize();
@@ -166,7 +166,7 @@ $.extend( Responsive.prototype, {
// new data is added
dtPrivateSettings.oApi._fnCallbackReg( dtPrivateSettings, 'aoRowCreatedCallback', function (tr, data, idx) {
if ( $.inArray( false, that.s.current ) !== -1 ) {
$('td, th', tr).each( function ( i ) {
$('>td, >th', tr).each( function ( i ) {
var idx = dt.column.index( 'toData', i );
if ( that.s.current[idx] === false ) {
@@ -181,6 +181,7 @@ $.extend( Responsive.prototype, {
dt.off( '.dtr' );
$( dt.table().body() ).off( '.dtr' );
$(window).off( 'resize.dtr orientationchange.dtr' );
dt.cells('.dtr-control').nodes().to$().removeClass('dtr-control');
// Restore the columns that we've hidden
$.each( that.s.current, function ( i, val ) {
@@ -208,10 +209,21 @@ $.extend( Responsive.prototype, {
// DataTables will trigger this event on every column it shows and
// hides individually
dt.on( 'column-visibility.dtr', function (e, ctx, col, vis) {
that._classLogic();
that._resizeAuto();
that._resize();
dt.on( 'column-visibility.dtr', function () {
// Use a small debounce to allow multiple columns to be set together
if ( that._timer ) {
clearTimeout( that._timer );
}
that._timer = setTimeout( function () {
that._timer = null;
that._classLogic();
that._resizeAuto();
that._resize(true);
that._redrawChildren();
}, 100 );
} );
// Redraw the details box on each draw which will happen if the data
@@ -227,7 +239,7 @@ $.extend( Responsive.prototype, {
dt.on( 'column-reorder.dtr', function (e, settings, details) {
that._classLogic();
that._resizeAuto();
that._resize();
that._resize(true);
} );
// Change in column sizes means we need to calc
@@ -236,16 +248,44 @@ $.extend( Responsive.prototype, {
that._resize();
});
dt.on( 'init.dtr', function (e, settings, details) {
that._resizeAuto();
that._resize();
// On Ajax reload we want to reopen any child rows which are displayed
// by responsive
dt.on( 'preXhr.dtr', function () {
var rowIds = [];
dt.rows().every( function () {
if ( this.child.isShown() ) {
rowIds.push( this.id(true) );
}
} );
// If columns were hidden, then DataTables needs to adjust the
// column sizing
if ( $.inArray( false, that.s.current ) ) {
dt.columns.adjust();
}
} );
dt.one( 'draw.dtr', function () {
that._resizeAuto();
that._resize();
dt.rows( rowIds ).every( function () {
that._detailsDisplay( this, false );
} );
} );
});
dt
.on( 'draw.dtr', function () {
that._controlClass();
})
.on( 'init.dtr', function (e, settings, details) {
if ( e.namespace !== 'dt' ) {
return;
}
that._resizeAuto();
that._resize();
// If columns were hidden, then DataTables needs to adjust the
// column sizing
if ( $.inArray( false, that.s.current ) ) {
dt.columns.adjust();
}
} );
// First pass - draw the table for the current viewport size
this._resize();
@@ -294,7 +334,10 @@ $.extend( Responsive.prototype, {
// Class logic - determine which columns are in this breakpoint based
// on the classes. If no class control (i.e. `auto`) then `-` is used
// to indicate this to the rest of the function
var display = $.map( columns, function ( col ) {
var display = $.map( columns, function ( col, i ) {
if ( dt.column(i).visible() === false ) {
return 'not-visible';
}
return col.auto && col.minWidth === null ?
false :
col.auto === true ?
@@ -362,7 +405,7 @@ $.extend( Responsive.prototype, {
var showControl = false;
for ( i=0, ien=columns.length ; i<ien ; i++ ) {
if ( ! columns[i].control && ! columns[i].never && ! display[i] ) {
if ( ! columns[i].control && ! columns[i].never && display[i] === false ) {
showControl = true;
break;
}
@@ -372,6 +415,11 @@ $.extend( Responsive.prototype, {
if ( columns[i].control ) {
display[i] = showControl;
}
// Replace not visible string with false from the control column detection above
if ( display[i] === 'not-visible' ) {
display[i] = false;
}
}
// Finally we need to make sure that there is at least one column that
@@ -402,13 +450,12 @@ $.extend( Responsive.prototype, {
var column = this.column(i);
var className = column.header().className;
var priority = dt.settings()[0].aoColumns[i].responsivePriority;
var dataPriority = column.header().getAttribute('data-priority');
if ( priority === undefined ) {
var dataPriority = $(column.header()).data('priority');
priority = dataPriority !== undefined ?
dataPriority * 1 :
10000;
priority = dataPriority === undefined || dataPriority === null?
10000 :
dataPriority * 1;
}
return {
@@ -475,7 +522,7 @@ $.extend( Responsive.prototype, {
// Split the class name up so multiple rules can be applied if needed
for ( var k=0, ken=classNames.length ; k<ken ; k++ ) {
var className = $.trim( classNames[k] );
var className = classNames[k].trim();
if ( className === 'all' ) {
// Include in all
@@ -490,7 +537,7 @@ $.extend( Responsive.prototype, {
hasClass = true;
return;
}
else if ( className === 'control' ) {
else if ( className === 'control' || className === 'dtr-control' ) {
// Special column that is only visible, when one of the other
// columns is hidden. This is used for the details control
hasClass = true;
@@ -528,6 +575,36 @@ $.extend( Responsive.prototype, {
this.s.columns = columns;
},
/**
* Update the cells to show the correct control class / button
* @private
*/
_controlClass: function ()
{
if ( this.c.details.type === 'inline' ) {
var dt = this.s.dt;
var columnsVis = this.s.current;
var firstVisible = $.inArray(true, columnsVis);
// Remove from any cells which shouldn't have it
dt.cells(
null,
function(idx) {
return idx !== firstVisible;
},
{page: 'current'}
)
.nodes()
.to$()
.filter('.dtr-control')
.removeClass('dtr-control');
dt.cells(null, firstVisible, {page: 'current'})
.nodes()
.to$()
.addClass('dtr-control');
}
},
/**
* Show the details for the child row
@@ -569,7 +646,7 @@ $.extend( Responsive.prototype, {
// The inline type always uses the first child as the target
if ( details.type === 'inline' ) {
details.target = 'td:first-child, th:first-child';
details.target = 'td.dtr-control, th.dtr-control';
}
// Keyboard accessibility
@@ -588,51 +665,53 @@ $.extend( Responsive.prototype, {
var target = details.target;
var selector = typeof target === 'string' ? target : 'td, th';
// Click handler to show / hide the details rows when they are available
$( dt.table().body() )
.on( 'click.dtr mousedown.dtr mouseup.dtr', selector, function (e) {
// If the table is not collapsed (i.e. there is no hidden columns)
// then take no action
if ( ! $(dt.table().node()).hasClass('collapsed' ) ) {
return;
}
// Check that the row is actually a DataTable's controlled node
if ( ! dt.row( $(this).closest('tr') ).length ) {
return;
}
// For column index, we determine if we should act or not in the
// handler - otherwise it is already okay
if ( typeof target === 'number' ) {
var targetIdx = target < 0 ?
dt.columns().eq(0).length + target :
target;
if ( dt.cell( this ).index().column !== targetIdx ) {
if ( target !== undefined || target !== null ) {
// Click handler to show / hide the details rows when they are available
$( dt.table().body() )
.on( 'click.dtr mousedown.dtr mouseup.dtr', selector, function (e) {
// If the table is not collapsed (i.e. there is no hidden columns)
// then take no action
if ( ! $(dt.table().node()).hasClass('collapsed' ) ) {
return;
}
}
// $().closest() includes itself in its check
var row = dt.row( $(this).closest('tr') );
// Check that the row is actually a DataTable's controlled node
if ( $.inArray( $(this).closest('tr').get(0), dt.rows().nodes().toArray() ) === -1 ) {
return;
}
// Check event type to do an action
if ( e.type === 'click' ) {
// The renderer is given as a function so the caller can execute it
// only when they need (i.e. if hiding there is no point is running
// the renderer)
that._detailsDisplay( row, false );
}
else if ( e.type === 'mousedown' ) {
// For mouse users, prevent the focus ring from showing
$(this).css('outline', 'none');
}
else if ( e.type === 'mouseup' ) {
// And then re-allow at the end of the click
$(this).blur().css('outline', '');
}
} );
// For column index, we determine if we should act or not in the
// handler - otherwise it is already okay
if ( typeof target === 'number' ) {
var targetIdx = target < 0 ?
dt.columns().eq(0).length + target :
target;
if ( dt.cell( this ).index().column !== targetIdx ) {
return;
}
}
// $().closest() includes itself in its check
var row = dt.row( $(this).closest('tr') );
// Check event type to do an action
if ( e.type === 'click' ) {
// The renderer is given as a function so the caller can execute it
// only when they need (i.e. if hiding there is no point is running
// the renderer)
that._detailsDisplay( row, false );
}
else if ( e.type === 'mousedown' ) {
// For mouse users, prevent the focus ring from showing
$(this).css('outline', 'none');
}
else if ( e.type === 'mouseup' ) {
// And then re-allow at the end of the click
$(this).trigger('blur').css('outline', '');
}
} );
}
},
@@ -652,12 +731,17 @@ $.extend( Responsive.prototype, {
return;
}
var dtCol = dt.settings()[0].aoColumns[ i ];
return {
title: dt.settings()[0].aoColumns[ i ].sTitle,
className: dtCol.sClass,
columnIndex: i,
data: dt.cell( rowIdx, i ).render( that.c.orthogonal ),
hidden: dt.column( i ).visible() && !that.s.current[ i ],
columnIndex: i,
rowIndex: rowIdx
rowIndex: rowIdx,
title: dtCol.sTitle !== null ?
dtCol.sTitle :
$(dt.column(i).header()).text()
};
} );
},
@@ -706,13 +790,14 @@ $.extend( Responsive.prototype, {
* determining what breakpoint the window currently is in, getting the
* column visibilities to apply and then setting them.
*
* @param {boolean} forceRedraw Force a redraw
* @private
*/
_resize: function ()
_resize: function (forceRedraw)
{
var that = this;
var dt = this.s.dt;
var width = $(window).width();
var width = $(window).innerWidth();
var breakpoints = this.c.breakpoints;
var breakpoint = breakpoints[0].name;
var columns = this.s.columns;
@@ -735,8 +820,9 @@ $.extend( Responsive.prototype, {
// listeners know what the state is. Need to determine if there are
// any columns that are not visible but can be shown
var collapsedClass = false;
for ( i=0, ien=columns.length ; i<ien ; i++ ) {
if ( columnsVis[i] === false && ! columns[i].never && ! columns[i].control ) {
if ( columnsVis[i] === false && ! columns[i].never && ! columns[i].control && ! dt.column(i).visible() === false ) {
collapsedClass = true;
break;
}
@@ -745,9 +831,14 @@ $.extend( Responsive.prototype, {
$( dt.table().node() ).toggleClass( 'collapsed', collapsedClass );
var changed = false;
var visible = 0;
dt.columns().eq(0).each( function ( colIdx, i ) {
if ( columnsVis[i] !== oldVis[i] ) {
if ( columnsVis[i] === true ) {
visible++;
}
if ( forceRedraw || columnsVis[i] !== oldVis[i] ) {
changed = true;
that._setColumnVis( colIdx, columnsVis[i] );
}
@@ -758,7 +849,14 @@ $.extend( Responsive.prototype, {
// Inform listeners of the change
$(dt.table().node()).trigger( 'responsive-resize.dt', [dt, this.s.current] );
// If no records, update the "No records" display element
if ( dt.page.info().recordsDisplay === 0 ) {
$('td', dt.table().body()).eq(0).attr('colspan', visible);
}
}
that._controlClass();
},
@@ -786,6 +884,15 @@ $.extend( Responsive.prototype, {
return;
}
// Need to restore all children. They will be reinstated by a re-render
if ( ! $.isEmptyObject( _childNodeStore ) ) {
$.each( _childNodeStore, function ( key ) {
var idx = key.split('-');
_childNodesRestore( dt, idx[0]*1, idx[1]*1 );
} );
}
// Clone the table with the current data in it
var tableWidth = dt.table().node().offsetWidth;
var columnWidths = dt.columns;
@@ -793,6 +900,8 @@ $.extend( Responsive.prototype, {
var clonedHeader = $( dt.table().header().cloneNode( false ) ).appendTo( clonedTable );
var clonedBody = $( dt.table().body() ).clone( false, false ).empty().appendTo( clonedTable ); // use jQuery because of IE8
clonedTable.style.width = 'auto';
// Header
var headerCells = dt.columns()
.header()
@@ -801,7 +910,9 @@ $.extend( Responsive.prototype, {
} )
.to$()
.clone( false )
.css( 'display', 'table-cell' );
.css( 'display', 'table-cell' )
.css( 'width', 'auto' )
.css( 'min-width', 0 );
// Body rows - we don't need to take account of DataTables' column
// visibility since we implement our own here (hence the `display` set)
@@ -842,12 +953,17 @@ $.extend( Responsive.prototype, {
// multiple times. For example, cloning and inserting a checked radio
// clears the chcecked state of the original radio.
$( clonedTable ).find( '[name]' ).removeAttr( 'name' );
// A position absolute table would take the table out of the flow of
// our container element, bypassing the height and width (Scroller)
$( clonedTable ).css( 'position', 'relative' )
var inserted = $('<div/>')
.css( {
width: 1,
height: 1,
overflow: 'hidden'
overflow: 'hidden',
clear: 'both'
} )
.append( clonedTable );
@@ -862,6 +978,23 @@ $.extend( Responsive.prototype, {
inserted.remove();
},
/**
* Get the state of the current hidden columns - controlled by Responsive only
*/
_responsiveOnlyHidden: function ()
{
var dt = this.s.dt;
return $.map( this.s.current, function (v, i) {
// If the column is hidden by DataTables then it can't be hidden by
// Responsive!
if ( dt.column(i).visible() === false ) {
return true;
}
return v;
} );
},
/**
* Set a column's visibility.
*
@@ -882,6 +1015,13 @@ $.extend( Responsive.prototype, {
$( dt.column( col ).header() ).css( 'display', display );
$( dt.column( col ).footer() ).css( 'display', display );
dt.column( col ).nodes().to$().css( 'display', display );
// If the are child nodes stored, we might need to reinsert them
if ( ! $.isEmptyObject( _childNodeStore ) ) {
dt.cells( null, col ).indexes().each( function (idx) {
_childNodesRestore( dt, idx.row, idx.column );
} );
}
},
@@ -903,13 +1043,22 @@ $.extend( Responsive.prototype, {
cells.filter( '[data-dtr-keyboard]' ).removeData( '[data-dtr-keyboard]' );
var selector = typeof target === 'number' ?
':eq('+target+')' :
target;
if ( typeof target === 'number' ) {
dt.cells( null, target, { page: 'current' } ).nodes().to$()
.attr( 'tabIndex', ctx.iTabIndex )
.data( 'dtr-keyboard', 1 );
}
else {
// This is a bit of a hack - we need to limit the selected nodes to just
// those of this table
if ( target === 'td:first-child, th:first-child' ) {
target = '>td:first-child, >th:first-child';
}
$( selector, dt.rows( { page: 'current' } ).nodes() )
.attr( 'tabIndex', ctx.iTabIndex )
.data( 'dtr-keyboard', 1 );
$( target, dt.rows( { page: 'current' } ).nodes() )
.attr( 'tabIndex', ctx.iTabIndex )
.data( 'dtr-keyboard', 1 );
}
}
} );
@@ -1037,6 +1186,52 @@ Responsive.display = {
};
var _childNodeStore = {};
function _childNodes( dt, row, col ) {
var name = row+'-'+col;
if ( _childNodeStore[ name ] ) {
return _childNodeStore[ name ];
}
// https://jsperf.com/childnodes-array-slice-vs-loop
var nodes = [];
var children = dt.cell( row, col ).node().childNodes;
for ( var i=0, ien=children.length ; i<ien ; i++ ) {
nodes.push( children[i] );
}
_childNodeStore[ name ] = nodes;
return nodes;
}
function _childNodesRestore( dt, row, col ) {
var name = row+'-'+col;
if ( ! _childNodeStore[ name ] ) {
return;
}
var node = dt.cell( row, col ).node();
var store = _childNodeStore[ name ];
var parent = store[0].parentNode;
var parentChildren = parent.childNodes;
var a = [];
for ( var i=0, ien=parentChildren.length ; i<ien ; i++ ) {
a.push( parentChildren[i] );
}
for ( var j=0, jen=a.length ; j<jen ; j++ ) {
node.appendChild( a[j] );
}
_childNodeStore[ name ] = undefined;
}
/**
* Display methods - functions which define how the hidden data should be shown
* in the table.
@@ -1046,11 +1241,46 @@ Responsive.display = {
* @static
*/
Responsive.renderer = {
listHiddenNodes: function () {
return function ( api, rowIdx, columns ) {
var ul = $('<ul data-dtr-index="'+rowIdx+'" class="dtr-details"/>');
var found = false;
var data = $.each( columns, function ( i, col ) {
if ( col.hidden ) {
var klass = col.className ?
'class="'+ col.className +'"' :
'';
$(
'<li '+klass+' data-dtr-index="'+col.columnIndex+'" data-dt-row="'+col.rowIndex+'" data-dt-column="'+col.columnIndex+'">'+
'<span class="dtr-title">'+
col.title+
'</span> '+
'</li>'
)
.append( $('<span class="dtr-data"/>').append( _childNodes( api, col.rowIndex, col.columnIndex ) ) )// api.cell( col.rowIndex, col.columnIndex ).node().childNodes ) )
.appendTo( ul );
found = true;
}
} );
return found ?
ul :
false;
};
},
listHidden: function () {
return function ( api, rowIdx, columns ) {
var data = $.map( columns, function ( col ) {
var klass = col.className ?
'class="'+ col.className +'"' :
'';
return col.hidden ?
'<li data-dtr-index="'+col.columnIndex+'" data-dt-row="'+col.rowIndex+'" data-dt-column="'+col.columnIndex+'">'+
'<li '+klass+' data-dtr-index="'+col.columnIndex+'" data-dt-row="'+col.rowIndex+'" data-dt-column="'+col.columnIndex+'">'+
'<span class="dtr-title">'+
col.title+
'</span> '+
@@ -1062,7 +1292,7 @@ Responsive.renderer = {
} ).join('');
return data ?
$('<ul data-dtr-index="'+rowIdx+'"/>').append( data ) :
$('<ul data-dtr-index="'+rowIdx+'" class="dtr-details"/>').append( data ) :
false;
}
},
@@ -1074,13 +1304,17 @@ Responsive.renderer = {
return function ( api, rowIdx, columns ) {
var data = $.map( columns, function ( col ) {
return '<tr data-dt-row="'+col.rowIndex+'" data-dt-column="'+col.columnIndex+'">'+
var klass = col.className ?
'class="'+ col.className +'"' :
'';
return '<tr '+klass+' data-dt-row="'+col.rowIndex+'" data-dt-column="'+col.columnIndex+'">'+
'<td>'+col.title+':'+'</td> '+
'<td>'+col.data+'</td>'+
'</tr>';
} ).join('');
return $('<table class="'+options.tableClass+'" width="100%"/>').append( data );
return $('<table class="'+options.tableClass+' dtr-details" width="100%"/>').append( data );
}
}
};
@@ -1190,10 +1424,18 @@ Api.register( 'responsive.hasHidden()', function () {
var ctx = this.context[0];
return ctx._responsive ?
$.inArray( false, ctx._responsive.s.current ) !== -1 :
$.inArray( false, ctx._responsive._responsiveOnlyHidden() ) !== -1 :
false;
} );
Api.registerPlural( 'columns().responsiveHidden()', 'column().responsiveHidden()', function () {
return this.iterator( 'column', function ( settings, column ) {
return settings._responsive ?
settings._responsive._responsiveOnlyHidden()[ column ] :
false;
}, 1 );
} );
/**
* Version information
@@ -1201,7 +1443,7 @@ Api.register( 'responsive.hasHidden()', function () {
* @name Responsive.version
* @static
*/
Responsive.version = '2.1.0';
Responsive.version = '2.2.7';
$.fn.dataTable.Responsive = Responsive;