一般的问题是在 PrimeFaces 中缺少任何文档大小适配代码来进行对话。更糟糕的是设置对话框为位置:固定,这使得它们不可滚动。所以我离开了位置:当对话框适合窗口时固定,否则我设置了位置:绝对并调整文档大小,以便适合对话框(启用滚动):
function handleResizeDialog(dialog) {
var el = $(dialog.jqId);
var doc = $('body');
var win = $(window);
var elPos = '';
var bodyHeight = '';
var bodyWidth = '';
// position:fixed is maybe cool, but it makes the dialog not scrollable on browser level, even if document is big enough
if (el.height() > win.height()) {
bodyHeight = el.height() + 'px';
elPos = 'absolute';
}
if (el.width() > win.width()) {
bodyWidth = el.width() + 'px';
elPos = 'absolute';
}
el.css('position', elPos);
doc.css('width', bodyWidth);
doc.css('height', bodyHeight);
var pos = el.offset();
if (pos.top + el.height() > doc.height())
pos.top = doc.height() - el.height();
if (pos.left + el.width() > doc.width())
pos.left = doc.width() - el.width();
var offsetX = 0;
var offsetY = 0;
if (elPos != 'absolute') {
offsetX = $(window).scrollLeft();
offsetY = $(window).scrollTop();
}
// scroll fix for position fixed
if (pos.left < offsetX)
pos.left = offsetX;
if (pos.top < offsetY)
pos.top = offsetY;
el.offset(pos);
}