From 21388133f52b67e45a10f5ecae0c615b3c9eee71 Mon Sep 17 00:00:00 2001 From: dtbuild Date: Fri, 11 Oct 2024 15:10:18 +0000 Subject: [PATCH] fe105bc93f50921112e4f66a698b3312395c9a6a Fix: If a popover is `fixed` position, then attach it to the body, rather than next to the host button Sync to source repo @fe105bc93f50921112e4f66a698b3312395c9a6a --- datatables.json | 2 +- js/dataTables.buttons.js | 5 +++-- js/dataTables.buttons.min.js | 2 +- js/dataTables.buttons.min.mjs | 2 +- js/dataTables.buttons.mjs | 5 +++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/datatables.json b/datatables.json index 6669276..33f6722 100644 --- a/datatables.json +++ b/datatables.json @@ -25,5 +25,5 @@ ], "src-repo": "http://github.com/DataTables/Buttons", "last-tag": "3.1.2", - "last-sync": "8ab9e3841286f90654d29150a6f28c7b286f5eb1" + "last-sync": "fe105bc93f50921112e4f66a698b3312395c9a6a" } \ No newline at end of file diff --git a/js/dataTables.buttons.js b/js/dataTables.buttons.js index 92c6728..3ae7dcc 100644 --- a/js/dataTables.buttons.js +++ b/js/dataTables.buttons.js @@ -1387,7 +1387,8 @@ $.extend(Buttons.prototype, { var containerSelector = options.tag + '.' + options.containerClassName.replace(/ /g, '.'); - var hostNode = hostButton.node(); + var hostButtonNode = hostButton.node(); + var hostNode = options.collectionLayout.includes('fixed') ? $('body') : hostButton.node(); var close = function () { closed = true; @@ -1483,7 +1484,7 @@ $.extend(Buttons.prototype, { .attr('role', 'menu') .appendTo(display); - hostNode.attr('aria-expanded', 'true'); + hostButtonNode.attr('aria-expanded', 'true'); if (hostNode.parents('body')[0] !== document.body) { hostNode = document.body.lastChild; diff --git a/js/dataTables.buttons.min.js b/js/dataTables.buttons.min.js index e57c76c..e0a680e 100644 --- a/js/dataTables.buttons.min.js +++ b/js/dataTables.buttons.min.js @@ -1,4 +1,4 @@ /*! Buttons for DataTables 3.2.0-dev * © SpryMedia Ltd - datatables.net/license */ -!function(e){var o,i;"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(t){return e(t,window,document)}):"object"==typeof exports?(o=require("jquery"),i=function(t,n){n.fn.dataTable||require("datatables.net")(t,n)},"undefined"==typeof window?module.exports=function(t,n){return t=t||window,n=n||o(t),i(t,n),e(n,t,t.document)}:(i(window,o),module.exports=e(o,window,window.document))):e(jQuery,window,document)}(function(x,m,v){"use strict";var e=x.fn.dataTable,o=0,C=0,_=e.ext.buttons,i=null;function y(t,n,e){x.fn.animate?t.stop().fadeIn(n,e):(t.css("display","block"),e&&e.call(t))}function w(t,n,e){x.fn.animate?t.stop().fadeOut(n,e):(t.css("display","none"),e&&e.call(t))}function A(n,t){if(!e.versionCheck("2"))throw"Warning: Buttons requires DataTables 2 or newer";if(!(this instanceof A))return function(t){return new A(t,n).container()};!0===(t=void 0===t?{}:t)&&(t={}),Array.isArray(t)&&(t={buttons:t}),this.c=x.extend(!0,{},A.defaults,t),t.buttons&&(this.c.buttons=t.buttons),this.s={dt:new e.Api(n),buttons:[],listenKeys:"",namespace:"dtb"+o++},this.dom={container:x("<"+this.c.dom.container.tag+"/>").addClass(this.c.dom.container.className)},this._constructor()}x.extend(A.prototype,{action:function(t,n){t=this._nodeToButton(t);return void 0===n?t.conf.action:(t.conf.action=n,this)},active:function(t,n){var t=this._nodeToButton(t),e=this.c.dom.button.active,o=x(t.node);return t.inCollection&&this.c.dom.collection.button&&void 0!==this.c.dom.collection.button.active&&(e=this.c.dom.collection.button.active),void 0===n?o.hasClass(e):(o.toggleClass(e,void 0===n||n),this)},add:function(t,n,e){var o=this.s.buttons;if("string"==typeof n){for(var i=n.split("-"),s=this.s,r=0,a=i.length-1;r"),h.conf._collection=h.collection,this._expandButton(h.buttons,h.conf.buttons,h.conf.split,!a,a,s,h.conf)),h.conf.split){h.collection=x("<"+c.container.tag+"/>"),h.conf._collection=h.collection;for(var b=0;b").addClass("dt-button-spacer "+n.style+" "+p.spacer.className).html(i(n.text)),{conf:n,node:d,inserter:d,buttons:[],inCollection:t,isSplit:e,collection:null,textNode:d};if(n.available&&!n.available(f,n)&&!n.html)return!1;n.html?c=x(n.html):(r=function(t,n,e,o,i){o.action.call(n.button(e),t,n,e,o,i),x(n.table().node()).triggerHandler("buttons-action.dt",[n.button(e),n,e,o])},a=function(t,n,e,o){o.async?(u.processing(e[0],!0),setTimeout(function(){r(t,n,e,o,function(){u.processing(e[0],!1)})},o.async)):r(t,n,e,o,function(){})},d=n.tag||p.tag,l=void 0===n.clickBlurs||n.clickBlurs,c=x("<"+d+"/>").addClass(p.className).attr("tabindex",this.s.dt.settings()[0].iTabIndex).attr("aria-controls",this.s.dt.table().node().id).on("click.dtb",function(t){t.preventDefault(),!c.hasClass(p.disabled)&&n.action&&a(t,f,c,n),l&&c.trigger("blur")}).on("keypress.dtb",function(t){13===t.keyCode&&(t.preventDefault(),!c.hasClass(p.disabled))&&n.action&&a(t,f,c,n)}),"a"===d.toLowerCase()&&c.attr("href","#"),"button"===d.toLowerCase()&&c.attr("type","button"),s=p.liner.tag?(d=x("<"+p.liner.tag+"/>").html(i(n.text)).addClass(p.liner.className),"a"===p.liner.tag.toLowerCase()&&d.attr("href","#"),c.append(d),d):(c.html(i(n.text)),c),!1===n.enabled&&c.addClass(p.disabled),n.className&&c.addClass(n.className),n.titleAttr&&c.attr("title",i(n.titleAttr)),n.attr&&c.attr(n.attr),n.namespace||(n.namespace=".dt-button-"+C++),void 0!==n.config&&n.config.split&&(n.split=n.config.split));var h,b,g,m,v,y,d=this.c.dom.buttonContainer,d=d&&d.tag?x("<"+d.tag+"/>").addClass(d.className).append(c):c;return this._addKey(n),this.c.buttonCreated&&(d=this.c.buttonCreated(n,d)),e&&(b=(h=t?x.extend(!0,this.c.dom.split,this.c.dom.collection.split):this.c.dom.split).wrapper,g=x("<"+b.tag+"/>").addClass(b.className).append(c),m=x.extend(n,{autoClose:!0,align:h.dropdown.align,attr:{"aria-haspopup":"dialog","aria-expanded":!1},className:h.dropdown.className,closeButton:!1,splitAlignClass:h.dropdown.splitAlignClass,text:h.dropdown.text}),this._addKey(m),v=function(t,n,e,o){_.split.action.call(n.button(g),t,n,e,o),x(n.table().node()).triggerHandler("buttons-action.dt",[n.button(e),n,e,o]),e.attr("aria-expanded",!0)},y=x('').html(this.c.dom.button.dropHtml).addClass(this.c.dom.button.dropClass).on("click.dtb",function(t){t.preventDefault(),t.stopPropagation(),y.hasClass(p.disabled)||v(t,f,y,m),l&&y.trigger("blur")}).on("keypress.dtb",function(t){13===t.keyCode&&(t.preventDefault(),y.hasClass(p.disabled)||v(t,f,y,m))}),0===n.split.length&&y.addClass("dtb-hide-drop"),g.append(y).attr(m.attr)),{conf:n,node:(e?g:c).get(0),inserter:e?g:d,buttons:[],inCollection:t,isSplit:e,inSplit:o,collection:null,textNode:s}},_checkSplitEnable:function(t){t=t||this.s.buttons;for(var n=0;n").addClass(h.containerClassName).addClass(h.collectionLayout).addClass(h.splitAlignClass).addClass(n).css("display","none").attr({"aria-modal":!0,role:"dialog"}),o=x(o).addClass(h.contentClassName).attr("role","menu").appendTo(e),g.attr("aria-expanded","true"),g.parents("body")[0]!==v.body&&(g=v.body.lastChild),h.popoverTitle?e.prepend('
'+h.popoverTitle+"
"):h.collectionTitle&&e.prepend('
'+h.collectionTitle+"
"),h.closeButton&&e.prepend('
×
').addClass("dtb-collection-closeable"),y(e.insertAfter(g),h.fade),f=x(t.table().container()),n=e.css("position"),"container"!==h.span&&"dt-container"!==h.align||(g=g.parent(),e.css("width",f.width())),"absolute"===n?(t=x(g[0].offsetParent),f=g.position(),n=g.offset(),a=t.offset(),s=t.position(),r=m.getComputedStyle(t[0]),a.height=t.outerHeight(),a.width=t.width()+parseFloat(r.paddingLeft),a.right=a.left+a.width,a.bottom=a.top+a.height,a=f.top+g.outerHeight(),l=f.left,e.css({top:a,left:l}),r=m.getComputedStyle(e[0]),(c=e.offset()).height=e.outerHeight(),c.width=e.outerWidth(),c.right=c.left+c.width,c.bottom=c.top+c.height,c.marginTop=parseFloat(r.marginTop),c.marginBottom=parseFloat(r.marginBottom),h.dropup&&(a=f.top-c.height-c.marginTop-c.marginBottom),"button-right"!==h.align&&!e.hasClass(h.rightAlignClassName)||(l=f.left-c.width+g.outerWidth()),"dt-container"!==h.align&&"container"!==h.align||lx(m).width()&&(l=x(m).width()-c.width-s.left),n.left+l<0&&(l=-n.left),s.top+a+c.height>x(m).height()+x(m).scrollTop()&&(a=f.top-c.height-c.marginTop-c.marginBottom),t.offset().top+a").addClass(n).css("display","none").insertAfter(o),e):w(x("div."+n),e,function(){x(this).removeClass(n).remove()})},A.instanceSelector=function(t,s){var r,a,l;return null==t?x.map(s,function(t){return t.inst}):(r=[],a=x.map(s,function(t){return t.name}),(l=function(t){var n;if(Array.isArray(t))for(var e=0,o=t.length;e)|(