From ea4ff23eee31b80cf2268737cfa145fe14f9ec0e Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 19 Aug 2022 15:15:21 +0300 Subject: [PATCH] ref --- client/src/ui.js | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/client/src/ui.js b/client/src/ui.js index cd6e97572d..c85a75732f 100644 --- a/client/src/ui.js +++ b/client/src/ui.js @@ -776,33 +776,40 @@ function (/** marked~ */marked, /** DOMPurify~ */ DOMPurify) { return new Dialog(options); }, + + /** + * @typedef {Object} Espo.Ui~PopoverOptions + * @property {'bottom'|'top'} placement A placement. + * @property {string} [container='body'] A container selector. + * @property {string} [content] An HTML content. + * @property {string} [text] A text. + * @property {'manual'|'click'|'hover'|'focus'} [trigger='manual'] A trigger type. + * @property {boolean} [noToggleInit=false] Skip init toggle on click. + */ + /** * Init a popover. * * @param {JQuery} $el An element. - * @param {{ - * placement: 'bottom'|'top', - * container: string, - * content: string, - * trigger: 'manual'|'click'|'hover'|'focus', - * noToggleInit: boolean, - * }} o Options. + * @param {Espo.Ui~PopoverOptions} o Options. * @param {module:view} [view] A view. */ popover: function ($el, o, view) { + let $body = $('body') + + let content = o.content || Handlebars.Utils.escapeExpression(o.text || ''); + $el.popover({ placement: o.placement || 'bottom', container: o.container || 'body', html: true, - content: o.content || o.text, + content: content, trigger: o.trigger || 'manual', }).on('shown.bs.popover', () => { if (!view) { return; } - let $body = $('body') - $body.off('click.popover-' + view.cid); $body.on('click.popover-' + view.cid, e => { @@ -818,8 +825,7 @@ function (/** marked~ */marked, /** DOMPurify~ */ DOMPurify) { return; } - $('body').off('click.popover-' + view.cid); - + $body.off('click.popover-' + view.cid); $el.popover('hide'); }); }); @@ -833,12 +839,12 @@ function (/** marked~ */marked, /** DOMPurify~ */ DOMPurify) { if (view) { view.on('remove', () => { $el.popover('destroy'); - $('body').off('click.popover-' + view.cid); + $body.off('click.popover-' + view.cid); }); view.on('render', () => { $el.popover('destroy'); - $('body').off('click.popover-' + view.cid); + $body.off('click.popover-' + view.cid); }); } },