From 0b0fac11a17de5e1e1edb241f0f49a1894be0d93 Mon Sep 17 00:00:00 2001
From: Nikita Hovratov <nikita.h@live.de>
Date: Sun, 2 May 2021 02:38:44 +0200
Subject: [PATCH] [BUGFIX] Fix csh popover position

This fixes the popover position after clicking on a csh link.

Side note:
The popover loads in two steps: First it shows a "loading ..." text and
when the content is fetched the popover must be updated. Before it was
achieved by hiding and then immediately showing the popover again. This
doesn't quite work with bootstrap v5 anymore. The popover is stuck in
the middle of the process before the positioning applies.

New method: Use the "setContent" method of the bootstrap popover
instance. This method is not documented, but it can be used.
Nevertheless we should keep an eye on that, as it's not public API.

Resolves: #93984
Resolves: #93152
Releases: master
Change-Id: If96028bd70bead243af1937cd2f87afed3b61c5f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/68962
Tested-by: core-ci <typo3@b13.com>
Tested-by: Riccardo De Contardi <erredeco@gmail.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Susanne Moog <look@susi.dev>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
---
 .../backend/Resources/Public/TypeScript/ContextHelp.ts     | 7 +------
 .../backend/Resources/Public/TypeScript/Popover.ts         | 1 +
 .../backend/Resources/Public/JavaScript/ContextHelp.js     | 2 +-
 .../sysext/backend/Resources/Public/JavaScript/Popover.js  | 2 +-
 4 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/ContextHelp.ts b/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/ContextHelp.ts
index ce8efb6bc698..fd10961e7e87 100644
--- a/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/ContextHelp.ts
+++ b/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/ContextHelp.ts
@@ -163,12 +163,7 @@ class ContextHelp {
           content: content,
         };
         Popover.setOptions($trigger, options);
-        $trigger
-          .attr('data-loaded', 'true')
-          .one('hidden.bs.popover', (): void => {
-            Popover.show($trigger);
-          });
-        Popover.hide($trigger);
+        $trigger.attr('data-loaded', 'true');
       });
     }
   }
diff --git a/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/Popover.ts b/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/Popover.ts
index 970f97775a49..c57df8073398 100644
--- a/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/Popover.ts
+++ b/Build/Sources/TypeScript/backend/Resources/Public/TypeScript/Popover.ts
@@ -88,6 +88,7 @@ class Popover {
   public setOption($element: JQuery, key: string, value: string): void {
     if (key === 'content') {
       $element.attr('data-bs-content', value);
+      $element.data('typo3.bs.popover').setContent(value);
     } else {
       $element.each((i, el) => {
         const popover = $(el).data('typo3.bs.popover');
diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/ContextHelp.js b/typo3/sysext/backend/Resources/Public/JavaScript/ContextHelp.js
index f98786dfd5f9..7c4abcaef8fa 100644
--- a/typo3/sysext/backend/Resources/Public/JavaScript/ContextHelp.js
+++ b/typo3/sysext/backend/Resources/Public/JavaScript/ContextHelp.js
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};define(["require","exports","jquery","TYPO3/CMS/Core/Ajax/AjaxRequest","./Popover","bootstrap"],(function(t,e,a,o,l){"use strict";a=__importDefault(a);class s{constructor(){this.ajaxUrl=TYPO3.settings.ajaxUrls.context_help,this.trigger="click",this.placement="auto",this.selector=".help-link",this.initialize()}static resolveBackend(){return void 0!==window.opener&&null!==window.opener?window.opener.top:top}initialize(){const t=s.resolveBackend();void 0!==t.TYPO3.settings.ContextHelp&&(this.helpModuleUrl=t.TYPO3.settings.ContextHelp.moduleUrl),void 0===TYPO3.ShortcutMenu&&void 0===t.TYPO3.ShortcutMenu&&a.default(".icon-actions-system-shortcut-new").closest(".btn").hide();let e="&nbsp;";void 0!==t.TYPO3.lang&&(e=t.TYPO3.lang.csh_tooltip_loading);const o=a.default(this.selector);o.attr("data-loaded","false").attr("data-bs-html","true").attr("data-bs-original-title",e).attr("data-bs-placement",this.placement).attr("data-bs-trigger",this.trigger),l.popover(o),a.default(document).on("show.bs.popover",this.selector,t=>{const e=a.default(t.currentTarget),o=e.data("description");if(void 0!==o&&""!==o){const t={title:e.data("title")||"",content:o};l.setOptions(e,t)}else"false"===e.attr("data-loaded")&&e.data("table")&&this.loadHelp(e);e.closest(".t3js-module-docheader").length&&l.setOption(e,"placement","bottom")}).on("click",".help-has-link",t=>{a.default(".popover").each((e,o)=>{const l=a.default(o);l.has(t.target).length&&this.showHelpPopup(a.default('[aria-describedby="'+l.attr("id")+'"]'))})}).on("click","body",t=>{a.default(this.selector).each((e,o)=>{const s=a.default(o);s.is(t.target)||0!==s.has(t.target).length||0!==a.default(".popover").has(t.target).length||l.hide(s)})})}showHelpPopup(t){try{const e=window.open(this.helpModuleUrl+"&table="+t.data("table")+"&field="+t.data("field")+"&action=detail","ContextHelpWindow","height=400,width=600,status=0,menubar=0,scrollbars=1");return e.focus(),l.hide(t),e}catch(t){}}loadHelp(t){const e=t.data("table"),a=t.data("field");e&&new o(this.ajaxUrl).withQueryArguments({params:{action:"getContextHelp",table:e,field:a}}).get().then(async e=>{const a=await e.resolve(),o={title:a.title||"",content:a.content||"<p></p>"};l.setOptions(t,o),t.attr("data-loaded","true").one("hidden.bs.popover",()=>{l.show(t)}),l.hide(t)})}}return new s}));
\ No newline at end of file
+var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};define(["require","exports","jquery","TYPO3/CMS/Core/Ajax/AjaxRequest","./Popover","bootstrap"],(function(t,e,a,o,l){"use strict";a=__importDefault(a);class s{constructor(){this.ajaxUrl=TYPO3.settings.ajaxUrls.context_help,this.trigger="click",this.placement="auto",this.selector=".help-link",this.initialize()}static resolveBackend(){return void 0!==window.opener&&null!==window.opener?window.opener.top:top}initialize(){const t=s.resolveBackend();void 0!==t.TYPO3.settings.ContextHelp&&(this.helpModuleUrl=t.TYPO3.settings.ContextHelp.moduleUrl),void 0===TYPO3.ShortcutMenu&&void 0===t.TYPO3.ShortcutMenu&&a.default(".icon-actions-system-shortcut-new").closest(".btn").hide();let e="&nbsp;";void 0!==t.TYPO3.lang&&(e=t.TYPO3.lang.csh_tooltip_loading);const o=a.default(this.selector);o.attr("data-loaded","false").attr("data-bs-html","true").attr("data-bs-original-title",e).attr("data-bs-placement",this.placement).attr("data-bs-trigger",this.trigger),l.popover(o),a.default(document).on("show.bs.popover",this.selector,t=>{const e=a.default(t.currentTarget),o=e.data("description");if(void 0!==o&&""!==o){const t={title:e.data("title")||"",content:o};l.setOptions(e,t)}else"false"===e.attr("data-loaded")&&e.data("table")&&this.loadHelp(e);e.closest(".t3js-module-docheader").length&&l.setOption(e,"placement","bottom")}).on("click",".help-has-link",t=>{a.default(".popover").each((e,o)=>{const l=a.default(o);l.has(t.target).length&&this.showHelpPopup(a.default('[aria-describedby="'+l.attr("id")+'"]'))})}).on("click","body",t=>{a.default(this.selector).each((e,o)=>{const s=a.default(o);s.is(t.target)||0!==s.has(t.target).length||0!==a.default(".popover").has(t.target).length||l.hide(s)})})}showHelpPopup(t){try{const e=window.open(this.helpModuleUrl+"&table="+t.data("table")+"&field="+t.data("field")+"&action=detail","ContextHelpWindow","height=400,width=600,status=0,menubar=0,scrollbars=1");return e.focus(),l.hide(t),e}catch(t){}}loadHelp(t){const e=t.data("table"),a=t.data("field");e&&new o(this.ajaxUrl).withQueryArguments({params:{action:"getContextHelp",table:e,field:a}}).get().then(async e=>{const a=await e.resolve(),o={title:a.title||"",content:a.content||"<p></p>"};l.setOptions(t,o),t.attr("data-loaded","true")})}}return new s}));
\ No newline at end of file
diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/Popover.js b/typo3/sysext/backend/Resources/Public/JavaScript/Popover.js
index 58d63144823b..e364faf9c9d6 100644
--- a/typo3/sysext/backend/Resources/Public/JavaScript/Popover.js
+++ b/typo3/sysext/backend/Resources/Public/JavaScript/Popover.js
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};define(["require","exports","jquery","bootstrap"],(function(t,e,o,a){"use strict";o=__importDefault(o);return new class{constructor(){this.DEFAULT_SELECTOR='[data-bs-toggle="popover"]',this.initialize()}initialize(t){t=t||this.DEFAULT_SELECTOR,o.default(t).each((t,e)=>{const s=new a.Popover(e);o.default(e).data("typo3.bs.popover",s)})}popover(t){t.each((t,e)=>{const s=new a.Popover(e);o.default(e).data("typo3.bs.popover",s)})}setOptions(t,e){const a=(e=e||{}).title||t.data("title")||"",s=e.content||t.data("bs-content")||"";t.attr("data-bs-original-title",a).attr("data-bs-content",s).attr("data-bs-placement","auto"),o.default.each(e,(e,o)=>{this.setOption(t,e,o)})}setOption(t,e,a){"content"===e?t.attr("data-bs-content",a):t.each((t,s)=>{const n=o.default(s).data("typo3.bs.popover");n&&(n.config[e]=a)})}show(t){t.each((t,e)=>{const a=o.default(e).data("typo3.bs.popover");a&&a.show()})}hide(t){t.each((t,e)=>{const a=o.default(e).data("typo3.bs.popover");a&&a.hide()})}destroy(t){t.each((t,e)=>{const a=o.default(e).data("typo3.bs.popover");a&&a.dispose()})}toggle(t){t.each((t,e)=>{const a=o.default(e).data("typo3.bs.popover");a&&a.toggle()})}}}));
\ No newline at end of file
+var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};define(["require","exports","jquery","bootstrap"],(function(t,e,o,a){"use strict";o=__importDefault(o);return new class{constructor(){this.DEFAULT_SELECTOR='[data-bs-toggle="popover"]',this.initialize()}initialize(t){t=t||this.DEFAULT_SELECTOR,o.default(t).each((t,e)=>{const s=new a.Popover(e);o.default(e).data("typo3.bs.popover",s)})}popover(t){t.each((t,e)=>{const s=new a.Popover(e);o.default(e).data("typo3.bs.popover",s)})}setOptions(t,e){const a=(e=e||{}).title||t.data("title")||"",s=e.content||t.data("bs-content")||"";t.attr("data-bs-original-title",a).attr("data-bs-content",s).attr("data-bs-placement","auto"),o.default.each(e,(e,o)=>{this.setOption(t,e,o)})}setOption(t,e,a){"content"===e?(t.attr("data-bs-content",a),t.data("typo3.bs.popover").setContent(a)):t.each((t,s)=>{const p=o.default(s).data("typo3.bs.popover");p&&(p.config[e]=a)})}show(t){t.each((t,e)=>{const a=o.default(e).data("typo3.bs.popover");a&&a.show()})}hide(t){t.each((t,e)=>{const a=o.default(e).data("typo3.bs.popover");a&&a.hide()})}destroy(t){t.each((t,e)=>{const a=o.default(e).data("typo3.bs.popover");a&&a.dispose()})}toggle(t){t.each((t,e)=>{const a=o.default(e).data("typo3.bs.popover");a&&a.toggle()})}}}));
\ No newline at end of file
-- 
GitLab