From 00e8e08be04296eff63a99d4a1ad8539421439bc Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Mon, 28 Feb 2022 15:18:37 +0000 Subject: [PATCH 01/12] Release 1.11.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index feeb7ea..678fab6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "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.", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" From 8c583e9800501b3ca7742fda096470260250cb82 Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Tue, 26 Jul 2022 10:47:45 +0200 Subject: [PATCH 02/12] Fix datetime-luxon.js luxon.fromFormat argument text must really be text so if the d variable is not do not call luxon.fromFormat as then we will get the dreaded TypeError: input.match is not a function. When the variable is not text it will not match anyway so return null in that case. --- sorting/datetime-luxon.js | 48 +++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/sorting/datetime-luxon.js b/sorting/datetime-luxon.js index f743816..2cfee7c 100644 --- a/sorting/datetime-luxon.js +++ b/sorting/datetime-luxon.js @@ -29,13 +29,11 @@ }(function ($, luxon) { function strip (d) { - if ( typeof d === 'string' ) { - // Strip HTML tags and newline characters if possible - d = d.replace(/(<.*?>)|(\r?\n|\r)/g, ''); + // Strip HTML tags and newline characters if possible + d = d.replace(/(<.*?>)|(\r?\n|\r)/g, ''); - // Strip out surrounding white space - d = d.trim(); - } + // Strip out surrounding white space + d = d.trim(); return d; } @@ -45,25 +43,37 @@ $.fn.dataTable.luxon = function ( format, locale, reverseEmpties ) { // Add type detection types.detect.unshift( function ( d ) { - d = strip(d); - - // Null and empty values are acceptable - if ( d === '' || d === null ) { + // Null values are acceptable + if ( d === null ) { return 'luxon-'+format; - } + } + if ( typeof d === 'string' ) { + d = strip(d); - return luxon.DateTime.fromFormat( d, format).isValid ? - 'luxon-'+format : - null; + // Empty values are acceptable + if ( d === '' ) { + 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 types.order[ 'luxon-'+format+'-pre' ] = function ( d ) { - d = strip(d); - - return !luxon.DateTime.fromFormat(d, format).isValid ? - (reverseEmpties ? -Infinity : Infinity) : - parseInt( luxon.DateTime.fromFormat( d, format).ts, 10 ); + if ( typeof d === 'string' ) { + d = strip(d); + + return !luxon.DateTime.fromFormat(d, format).isValid ? + (reverseEmpties ? -Infinity : Infinity) : + parseInt( luxon.DateTime.fromFormat( d, format).ts, 10 ); + } else { + return null; + } }; }; From 856964b396c8bde253c551aa154b43d4593fc785 Mon Sep 17 00:00:00 2001 From: Joost Molenkamp Date: Fri, 29 Jul 2022 19:28:44 +0200 Subject: [PATCH 03/12] Remove resize helper object on table destruction --- features/pageResize/dataTables.pageResize.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/features/pageResize/dataTables.pageResize.js b/features/pageResize/dataTables.pageResize.js index 9ee8fe3..8bf24e6 100644 --- a/features/pageResize/dataTables.pageResize.js +++ b/features/pageResize/dataTables.pageResize.js @@ -83,6 +83,12 @@ var PageResize = function ( dt, pageResizeManualDelta ) 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._size(); }; @@ -162,8 +168,10 @@ PageResize.prototype = { obj .appendTo( this.s.host ) - .attr( 'data', 'about:blank' ); - } + .attr( 'data', 'about:blank' ); + + this.s.obj = obj; + } }; From 9016c33370f81d5ab85bc3f29c9cfdc72e3625dd Mon Sep 17 00:00:00 2001 From: Joost Molenkamp Date: Fri, 29 Jul 2022 20:17:42 +0200 Subject: [PATCH 04/12] Resize on layout changes due to width changes --- features/pageResize/dataTables.pageResize.js | 64 +++++++++++++++----- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/features/pageResize/dataTables.pageResize.js b/features/pageResize/dataTables.pageResize.js index 8bf24e6..522733c 100644 --- a/features/pageResize/dataTables.pageResize.js +++ b/features/pageResize/dataTables.pageResize.js @@ -76,7 +76,15 @@ var PageResize = function ( dt, pageResizeManualDelta ) container: $(table.container()), table: $(table.node()), delta: pageResizeManualDelta - }; + }; + + this.sizes = { + offsetTop: this._getOffsetTop(), + tableHeight: this._getTableHeight(), + containerHeight: this._getContainerHeight(), + headerHeight: this._getHeaderHeight(), + footerHeight: this._getFooterHeight() + }; var host = this.s.host; if ( host.css('position') === 'static' ) { @@ -100,25 +108,30 @@ PageResize.prototype = { var settings = this.s; var dt = settings.dt; var t = dt.table(); - var offsetTop = $( settings.table ).offset().top; 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 availableHeight = settings.host.height(); 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 // surrounding the table if ( ! scrolling ) { if ( t.header() ) { - availableHeight -= settings.header.height(); + availableHeight -= headerHeight; } if ( t.footer() ) { - availableHeight -= settings.footer.height(); + availableHeight -= footerHeight; } } availableHeight -= offsetTop; - availableHeight -= settings.container.height() - ( offsetTop + settings.table.height() ); + availableHeight -= containerHeight - ( offsetTop + tableHeight ); if ( !isNaN( parseFloat( delta ) ) && isFinite( delta ) ) { availableHeight -= delta; @@ -155,23 +168,42 @@ PageResize.prototype = { var body = this.contentDocument.body; var height = body.offsetHeight; - this.contentDocument.defaultView.onresize = function () { - var newHeight = body.clientHeight || body.offsetHeight; - - if ( newHeight !== height ) { - height = newHeight; + this.contentDocument.defaultView.onresize = function () { + + var newHeight = body.clientHeight || body.offsetHeight; + if (newHeight !== height) { + 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 .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; } - this.s.obj = obj; - } }; From b308a5b5baef411ccf3ca8b642e9ce22d0001233 Mon Sep 17 00:00:00 2001 From: Joost Molenkamp Date: Thu, 1 Sep 2022 20:40:39 +0200 Subject: [PATCH 05/12] ScrollResize: remove resize helper iframe on table destruction --- features/scrollResize/dataTables.scrollResize.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/features/scrollResize/dataTables.scrollResize.js b/features/scrollResize/dataTables.scrollResize.js index 2017dea..4a01d20 100644 --- a/features/scrollResize/dataTables.scrollResize.js +++ b/features/scrollResize/dataTables.scrollResize.js @@ -83,6 +83,12 @@ var ScrollResize = function ( dt ) that._size(); } ); + var onDestroy = function () { + dt.off('.pageResize', onDestroy); + this.s.obj && this.s.obj.remove(); + }.bind(this); + dt.on('destroy.pageResize', onDestroy); + this._attach(); this._size(); }; @@ -154,7 +160,9 @@ ScrollResize.prototype = { obj .appendTo( this.s.host ) .attr( 'data', 'about:blank' ); - } + + this.s.obj = obj; + } }; From d405f51abb439e8e6149b0285a654ba1567284f8 Mon Sep 17 00:00:00 2001 From: Joost Molenkamp Date: Tue, 6 Sep 2022 12:08:41 +0200 Subject: [PATCH 06/12] Use the set moment locale as a fallback instead of fixed 'en' --- dataRender/datetime.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dataRender/datetime.js b/dataRender/datetime.js index c866f97..0d97d8c 100644 --- a/dataRender/datetime.js +++ b/dataRender/datetime.js @@ -97,13 +97,9 @@ $.fn.dataTable.render.moment = function ( from, to, locale ) { // Argument shifting if ( arguments.length === 1 ) { - locale = 'en'; to = from; from = 'YYYY-MM-DD'; } - else if ( arguments.length === 2 ) { - locale = 'en'; - } return function ( d, type, row ) { if (! d) { From ca1e5396d99d59234fd219aaff85ff46d1f12cd7 Mon Sep 17 00:00:00 2001 From: Joost Molenkamp Date: Tue, 6 Sep 2022 21:42:50 +0200 Subject: [PATCH 07/12] ScrollResize: remove draw event handler on table destruction --- features/scrollResize/dataTables.scrollResize.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/features/scrollResize/dataTables.scrollResize.js b/features/scrollResize/dataTables.scrollResize.js index 4a01d20..7daeedd 100644 --- a/features/scrollResize/dataTables.scrollResize.js +++ b/features/scrollResize/dataTables.scrollResize.js @@ -79,15 +79,14 @@ var ScrollResize = function ( dt ) host.css( 'position', 'relative' ); } - dt.on( 'draw', function () { + dt.on( 'draw.scrollResize', function () { that._size(); } ); - var onDestroy = function () { - dt.off('.pageResize', onDestroy); + dt.on('destroy.scrollResize', function () { + dt.off('.scrollResize'); this.s.obj && this.s.obj.remove(); - }.bind(this); - dt.on('destroy.pageResize', onDestroy); + }.bind(this)); this._attach(); this._size(); From 90d135e8d681083e2903a60e8135daec88e98ac5 Mon Sep 17 00:00:00 2001 From: Joost Molenkamp Date: Fri, 9 Sep 2022 20:36:33 +0200 Subject: [PATCH 08/12] ScrollResize: redraw header on scrollbar hiding during feature initialization --- features/scrollResize/dataTables.scrollResize.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/features/scrollResize/dataTables.scrollResize.js b/features/scrollResize/dataTables.scrollResize.js index 7daeedd..6c6a1f4 100644 --- a/features/scrollResize/dataTables.scrollResize.js +++ b/features/scrollResize/dataTables.scrollResize.js @@ -90,6 +90,17 @@ var ScrollResize = function ( dt ) this._attach(); 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(); + } }; From a9f1ba1c0bbad50d9e16aa830f0b341f3a1b4888 Mon Sep 17 00:00:00 2001 From: Joost Molenkamp Date: Sun, 11 Sep 2022 21:15:23 +0200 Subject: [PATCH 09/12] PageResize: delay initial call to _size until table is fully initialized --- features/pageResize/dataTables.pageResize.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/features/pageResize/dataTables.pageResize.js b/features/pageResize/dataTables.pageResize.js index 522733c..161ce06 100644 --- a/features/pageResize/dataTables.pageResize.js +++ b/features/pageResize/dataTables.pageResize.js @@ -98,7 +98,15 @@ var PageResize = function ( dt, pageResizeManualDelta ) dt.on('destroy.pageResize', onDestroy); 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)); }; From 4d3a6850b9502166e74e9cedf32720a9e153b6ba Mon Sep 17 00:00:00 2001 From: yaakovfeldman Date: Mon, 12 Sep 2022 16:15:28 +0100 Subject: [PATCH 10/12] Escape input even when no shortening required --- dataRender/ellipsis.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dataRender/ellipsis.js b/dataRender/ellipsis.js index 186e9e5..b42ac5e 100644 --- a/dataRender/ellipsis.js +++ b/dataRender/ellipsis.js @@ -63,12 +63,18 @@ jQuery.fn.dataTable.render.ellipsis = function ( cutoff, wordbreak, escapeHtml ) } if ( typeof d !== 'number' && typeof d !== 'string' ) { + if ( escapeHtml ) { + return esc( d ); + } return d; } d = d.toString(); // cast numbers if ( d.length <= cutoff ) { + if ( escapeHtml ) { + return esc( d ); + } return d; } From 40e3b46cd05a145a74ef02e15d518e0af64c2874 Mon Sep 17 00:00:00 2001 From: yaakovfeldman Date: Mon, 12 Sep 2022 17:25:45 +0100 Subject: [PATCH 11/12] Ensure that data is string before escaping --- dataRender/ellipsis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataRender/ellipsis.js b/dataRender/ellipsis.js index b42ac5e..a89cf77 100644 --- a/dataRender/ellipsis.js +++ b/dataRender/ellipsis.js @@ -49,7 +49,7 @@ jQuery.fn.dataTable.render.ellipsis = function ( cutoff, wordbreak, escapeHtml ) { var esc = function ( t ) { - return t + return ('' + t) .replace( /&/g, '&' ) .replace( //g, '>' ) From 27bd88a867bf2d051b28ae8e38e53718a191e65e Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 13 Sep 2022 22:09:47 +0300 Subject: [PATCH 12/12] Create PULL_REQUEST_TEMPLATE.md ~~Dobby~~AllanJard is free (: --- .github/PULL_REQUEST_TEMPLATE.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..82f3afa --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1 @@ +Are you happy for it to be included and distributed under the MIT license? ✔️/❌