bootstrap dialog update

这个提交包含在:
HB9HIL 2023-11-14 15:53:19 +01:00
父节点 a8057d0ab9
当前提交 313e5a13fd
共有 2 个文件被更改,包括 47 次插入7 次删除

查看文件

@ -38,9 +38,13 @@
* Extend Bootstrap Modal and override some functions.
* BootstrapDialogModal === Modified Modal.
* ================================================ */
var Modal = $.fn.modal.Constructor;
var Modal = bootstrap.Modal ? bootstrap.Modal : $.fn.modal.Constructor;
var BootstrapDialogModal = function (element, options) {
if (/4\.1\.\d+/.test($.fn.modal.Constructor.VERSION)) { //FIXME for BootstrapV4
if(bootstrap && bootstrap.Modal && /^5\.[^\D0]\./.test(bootstrap.Modal.VERSION)) {
return new Modal(element, options);
} else if(bootstrap && bootstrap.Modal && /^5\.0\.2/.test(bootstrap.Modal.VERSION)) {
return new Modal(element, options);
} else if (/4\.1\.\d+/.test($.fn.modal.Constructor.VERSION)) { //FIXME for BootstrapV4
return new Modal(element, options);
} else {
Modal.call(this, element, options);
@ -48,7 +52,13 @@
};
BootstrapDialogModal.getModalVersion = function () {
var version = null;
if (typeof $.fn.modal.Constructor.VERSION === 'undefined') {
if(bootstrap && bootstrap.Modal && /^5\.[^\D0]\./.test(bootstrap.Modal.VERSION)) {
version = 'v5.1';
//not compatible with 5.0.1, regex upper bounds would have been better
} else if(bootstrap && bootstrap.Modal && /^5\.0\.[23456789]/.test(bootstrap.Modal.VERSION)) {
version = 'v5.1';
}
else if (typeof $.fn.modal.Constructor.VERSION === 'undefined') {
version = 'v3.1';
} else if (/3\.2\.\d+/.test($.fn.modal.Constructor.VERSION)) {
version = 'v3.2';
@ -146,6 +156,7 @@
};
BootstrapDialogModal.METHODS_TO_OVERRIDE['v3.3.4'] = $.extend({}, BootstrapDialogModal.METHODS_TO_OVERRIDE['v3.3']);
BootstrapDialogModal.METHODS_TO_OVERRIDE['v4.1'] = $.extend({}, BootstrapDialogModal.METHODS_TO_OVERRIDE['v3.3']); //FIXME for BootstrapV4
BootstrapDialogModal.METHODS_TO_OVERRIDE['v5.1'] = $.extend({}, BootstrapDialogModal.METHODS_TO_OVERRIDE['v4.1']); //FIXME for BootstrapV5
BootstrapDialogModal.prototype = {
constructor: BootstrapDialogModal,
/**
@ -231,7 +242,7 @@
BootstrapDialog.BUTTON_SIZES[BootstrapDialog.SIZE_SMALL] = 'btn-small';
BootstrapDialog.BUTTON_SIZES[BootstrapDialog.SIZE_WIDE] = 'btn-block';
BootstrapDialog.BUTTON_SIZES[BootstrapDialog.SIZE_LARGE] = 'btn-lg';
BootstrapDialog.ICON_SPINNER = 'glyphicon glyphicon-asterisk';
BootstrapDialog.ICON_SPINNER = 'fas fa-spinner';
BootstrapDialog.BUTTONS_ORDER_CANCEL_OK = 'btns-order-cancel-ok';
BootstrapDialog.BUTTONS_ORDER_OK_CANCEL = 'btns-order-ok-cancel';
BootstrapDialog.Z_INDEX_BACKDROP = 1040;
@ -257,6 +268,7 @@
animate: true,
description: '',
tabindex: -1,
verticalCentered:false,
btnsOrder: BootstrapDialog.BUTTONS_ORDER_CANCEL_OK
};
@ -391,6 +403,20 @@
return this.getModal().get(0);
}
};
BootstrapDialog.METHODS_TO_OVERRIDE['v5.1'] = $.extend({}, BootstrapDialog.METHODS_TO_OVERRIDE['v4.1'], {
createCloseButton: function () {
var $container = $('<div></div>');
$container.addClass(this.getNamespace('close-button'));
var $icon = $('<button class="btn-close" aria-label="close"></button>');
// $icon.append(this.options.closeIcon);
$container.append($icon);
$container.on('click', { dialog: this }, function (event) {
event.data.dialog.close();
});
return $container;
},
});
BootstrapDialog.prototype = {
constructor: BootstrapDialog,
initOptions: function (options) {
@ -781,6 +807,14 @@
return this;
},
getVerticalCentered: function(){
return this.options.verticalCentered;
},
setVerticalCentered: function (verticalcentered) {
this.options.verticalCentered = verticalCentered;
return this;
},
setTabindex: function (tabindex) {
this.options.tabindex = tabindex;
@ -1126,7 +1160,7 @@
$(this).remove();
}
BootstrapDialog.moveFocus();
if ($('.modal').hasClass('in')) {
if ($('.modal').hasClass('in') || $('.modal').hasClass('show')) {
$('body').addClass('modal-open');
}
});
@ -1153,6 +1187,7 @@
makeModalDraggable: function () {
if (this.options.draggable) {
this.getModalHeader().addClass(this.getNamespace('draggable')).on('mousedown', { dialog: this }, function (event) {
event.preventDefault();
var dialog = event.data.dialog;
dialog.draggableData.isMouseDown = true;
var dialogOffset = dialog.getModalDialog().offset();
@ -1161,7 +1196,7 @@
left: event.clientX - dialogOffset.left
};
});
this.getModal().on('mouseup mouseleave', { dialog: this }, function (event) {
this.getModal().on('mouseup', { dialog: this }, function (event) {
event.data.dialog.draggableData.isMouseDown = false;
});
$('body').on('mousemove', { dialog: this }, function (event) {
@ -1173,6 +1208,8 @@
top: event.clientY - dialog.draggableData.mouseOffset.top,
left: event.clientX - dialog.draggableData.mouseOffset.left
});
}).on('mouseleave', { dialog: this }, function (event) {
event.data.dialog.draggableData.isMouseDown = false;
});
}
@ -1187,6 +1224,9 @@
this.getModal().attr('aria-describedby', this.getDescription());
}
//this.getModalFooter().append(this.createFooterContent());
if(this.getVerticalCentered()){
this.getModalDialog().addClass('modal-dialog-centered');
}
this.getModalHeader().append(this.createHeaderContent());
this.getModalBody().append(this.createBodyContent());
this.getModal().data('bs.modal', new BootstrapDialogModal(this.getModalForBootstrapDialogModal(), { //FIXME for BootstrapV4

文件差异因一行或多行过长而隐藏