Merge branch 'master' of github.com:DataTables/Plugins

pull/556/merge
Allan Jardine 2 years ago
commit 9f00721169

@ -0,0 +1 @@
Are you happy for it to be included and distributed under the MIT license? ✔️/❌

@ -97,13 +97,9 @@
$.fn.dataTable.render.moment = function ( from, to, locale ) { $.fn.dataTable.render.moment = function ( from, to, locale ) {
// Argument shifting // Argument shifting
if ( arguments.length === 1 ) { if ( arguments.length === 1 ) {
locale = 'en';
to = from; to = from;
from = 'YYYY-MM-DD'; from = 'YYYY-MM-DD';
} }
else if ( arguments.length === 2 ) {
locale = 'en';
}
return function ( d, type, row ) { return function ( d, type, row ) {
if (! d) { if (! d) {

@ -49,7 +49,7 @@
jQuery.fn.dataTable.render.ellipsis = function ( cutoff, wordbreak, escapeHtml ) { jQuery.fn.dataTable.render.ellipsis = function ( cutoff, wordbreak, escapeHtml ) {
var esc = function ( t ) { var esc = function ( t ) {
return t return ('' + t)
.replace( /&/g, '&' ) .replace( /&/g, '&' )
.replace( /</g, '&lt;' ) .replace( /</g, '&lt;' )
.replace( />/g, '&gt;' ) .replace( />/g, '&gt;' )
@ -63,12 +63,18 @@ jQuery.fn.dataTable.render.ellipsis = function ( cutoff, wordbreak, escapeHtml )
} }
if ( typeof d !== 'number' && typeof d !== 'string' ) { if ( typeof d !== 'number' && typeof d !== 'string' ) {
if ( escapeHtml ) {
return esc( d );
}
return d; return d;
} }
d = d.toString(); // cast numbers d = d.toString(); // cast numbers
if ( d.length <= cutoff ) { if ( d.length <= cutoff ) {
if ( escapeHtml ) {
return esc( d );
}
return d; return d;
} }

@ -76,15 +76,37 @@ var PageResize = function ( dt, pageResizeManualDelta )
container: $(table.container()), container: $(table.container()),
table: $(table.node()), table: $(table.node()),
delta: pageResizeManualDelta delta: pageResizeManualDelta
}; };
this.sizes = {
offsetTop: this._getOffsetTop(),
tableHeight: this._getTableHeight(),
containerHeight: this._getContainerHeight(),
headerHeight: this._getHeaderHeight(),
footerHeight: this._getFooterHeight()
};
var host = this.s.host; var host = this.s.host;
if ( host.css('position') === 'static' ) { if ( host.css('position') === 'static' ) {
host.css( 'position', 'relative' ); host.css( 'position', 'relative' );
} }
var onDestroy = function () {
dt.off('.pageResize', onDestroy);
this.s.obj && this.s.obj.remove();
}.bind(this);
dt.on('destroy.pageResize', onDestroy);
this._attach(); this._attach();
this._size();
// Delay the initial sizing until the table is fully initialized
// such that the pagination element is also added and can be taken
// into account.
var initEvent = 'init.pageResize';
dt.on(initEvent, function () {
dt.off(initEvent);
this._size();
}.bind(this));
}; };
@ -94,25 +116,30 @@ PageResize.prototype = {
var settings = this.s; var settings = this.s;
var dt = settings.dt; var dt = settings.dt;
var t = dt.table(); var t = dt.table();
var offsetTop = $( settings.table ).offset().top;
var rows = $( 'tr', settings.body ); var rows = $( 'tr', settings.body );
var rowHeight = rows.eq( rows.length > 1 ? 1 : 0 ).height(); // Attempt to use the second row if poss, for top and bottom border var rowHeight = rows.eq( rows.length > 1 ? 1 : 0 ).height(); // Attempt to use the second row if poss, for top and bottom border
var availableHeight = settings.host.height(); var availableHeight = settings.host.height();
var scrolling = t.header().parentNode !== t.body().parentNode; var scrolling = t.header().parentNode !== t.body().parentNode;
var delta = settings.delta; var delta = settings.delta;
var offsetTop = this.sizes.offsetTop = this._getOffsetTop();
var tableHeight = this.sizes.tableHeight = this._getTableHeight();
var containerHeight = this.sizes.containerHeight = this._getContainerHeight();
var headerHeight = this.sizes.headerHeight = this._getHeaderHeight();
var footerHeight = this.sizes.footerHeight = this._getFooterHeight();
// Subtract the height of the header, footer and the elements // Subtract the height of the header, footer and the elements
// surrounding the table // surrounding the table
if ( ! scrolling ) { if ( ! scrolling ) {
if ( t.header() ) { if ( t.header() ) {
availableHeight -= settings.header.height(); availableHeight -= headerHeight;
} }
if ( t.footer() ) { if ( t.footer() ) {
availableHeight -= settings.footer.height(); availableHeight -= footerHeight;
} }
} }
availableHeight -= offsetTop; availableHeight -= offsetTop;
availableHeight -= settings.container.height() - ( offsetTop + settings.table.height() ); availableHeight -= containerHeight - ( offsetTop + tableHeight );
if ( !isNaN( parseFloat( delta ) ) && isFinite( delta ) ) { if ( !isNaN( parseFloat( delta ) ) && isFinite( delta ) ) {
availableHeight -= delta; availableHeight -= delta;
@ -149,21 +176,42 @@ PageResize.prototype = {
var body = this.contentDocument.body; var body = this.contentDocument.body;
var height = body.offsetHeight; var height = body.offsetHeight;
this.contentDocument.defaultView.onresize = function () { this.contentDocument.defaultView.onresize = function () {
var newHeight = body.clientHeight || body.offsetHeight;
var newHeight = body.clientHeight || body.offsetHeight;
if ( newHeight !== height ) { if (newHeight !== height) {
height = newHeight; height = newHeight;
that._size();
return;
}
// Width changes might lead to layout changes, which might require
// resizing the table
if (that.sizes.offsetTop !== that._getOffsetTop()
|| that.sizes.containerHeight !== that._getContainerHeight()
|| that.sizes.tableHeight !== that._getTableHeight()
|| that.sizes.headerHeight !== that._getHeaderHeight()
|| that.sizes.footerHeight !== that._getFooterHeight()) {
that._size();
return;
}
that._size();
}
}; };
}; };
obj obj
.appendTo( this.s.host ) .appendTo( this.s.host )
.attr( 'data', 'about:blank' ); .attr( 'data', 'about:blank' );
}
this.s.obj = obj;
},
_getOffsetTop: function () { return $(this.s.table).offset().top; },
_getTableHeight: function () { return this.s.table.height(); },
_getContainerHeight: function () { return this.s.container.height(); },
_getHeaderHeight: function () { return this.s.dt.table().header() ? this.s.header.height() : 0; },
_getFooterHeight: function () { return this.s.dt.table().footer() ? this.s.footer.height() : 0; }
}; };

@ -79,12 +79,28 @@ var ScrollResize = function ( dt )
host.css( 'position', 'relative' ); host.css( 'position', 'relative' );
} }
dt.on( 'draw', function () { dt.on( 'draw.scrollResize', function () {
that._size(); that._size();
} ); } );
dt.on('destroy.scrollResize', function () {
dt.off('.scrollResize');
this.s.obj && this.s.obj.remove();
}.bind(this));
this._attach(); this._attach();
this._size(); this._size();
// Redraw the header if the scrollbar was visible before feature
// initialization, but no longer after initialization. Otherwise,
// the header width would differ from the body width, because the
// scrollbar is no longer present.
var settings = dt.settings()[0];
var divBodyEl = settings.nScrollBody;
var scrollBarVis = divBodyEl.scrollHeight > divBodyEl.clientHeight;
if (settings.scrollBarVis && !scrollBarVis) {
dt.columns.adjust();
}
}; };
@ -154,7 +170,9 @@ ScrollResize.prototype = {
obj obj
.appendTo( this.s.host ) .appendTo( this.s.host )
.attr( 'data', 'about:blank' ); .attr( 'data', 'about:blank' );
}
this.s.obj = obj;
}
}; };

@ -1,6 +1,6 @@
{ {
"name": "datatables.net-plugins", "name": "datatables.net-plugins",
"version": "1.11.4", "version": "1.11.5",
"description": "Various small plug-ins for DataTables including feature, ordering, search and internationalisation plug-ins.", "description": "Various small plug-ins for DataTables including feature, ordering, search and internationalisation plug-ins.",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"

@ -29,13 +29,11 @@
}(function ($, luxon) { }(function ($, luxon) {
function strip (d) { function strip (d) {
if ( typeof d === 'string' ) { // Strip HTML tags and newline characters if possible
// Strip HTML tags and newline characters if possible d = d.replace(/(<.*?>)|(\r?\n|\r)/g, '');
d = d.replace(/(<.*?>)|(\r?\n|\r)/g, '');
// Strip out surrounding white space // Strip out surrounding white space
d = d.trim(); d = d.trim();
}
return d; return d;
} }
@ -45,25 +43,37 @@ $.fn.dataTable.luxon = function ( format, locale, reverseEmpties ) {
// Add type detection // Add type detection
types.detect.unshift( function ( d ) { types.detect.unshift( function ( d ) {
d = strip(d); // Null values are acceptable
if ( d === null ) {
// Null and empty values are acceptable
if ( d === '' || d === null ) {
return 'luxon-'+format; return 'luxon-'+format;
} }
if ( typeof d === 'string' ) {
d = strip(d);
return luxon.DateTime.fromFormat( d, format).isValid ? // Empty values are acceptable
'luxon-'+format : if ( d === '' ) {
null; return 'luxon-'+format;
}
return luxon.DateTime.fromFormat( d, format).isValid ?
'luxon-'+format :
null;
} else {
return null;
}
} ); } );
// Add sorting method - use an integer for the sorting // Add sorting method - use an integer for the sorting
types.order[ 'luxon-'+format+'-pre' ] = function ( d ) { types.order[ 'luxon-'+format+'-pre' ] = function ( d ) {
d = strip(d); if ( typeof d === 'string' ) {
d = strip(d);
return !luxon.DateTime.fromFormat(d, format).isValid ?
(reverseEmpties ? -Infinity : Infinity) : return !luxon.DateTime.fromFormat(d, format).isValid ?
parseInt( luxon.DateTime.fromFormat( d, format).ts, 10 ); (reverseEmpties ? -Infinity : Infinity) :
parseInt( luxon.DateTime.fromFormat( d, format).ts, 10 );
} else {
return null;
}
}; };
}; };

Loading…
Cancel
Save