- Issue created by @dalin
- Status changed to Needs review
2 days ago 10:52pm 31 March 2025 - First commit to issue fork.
- 🇷🇸Serbia pivica
There are multiple problems here.
1. First problem is with selector:
$('#drupal-off-canvas-wrapper, #drupal-off-canvas').dialog('close');
That comma means that this will return two jquery elements, one for #drupal-off-canvas-wrapper and the second for #drupal-off-canvas and then dialog('close') will be called for both elements. However, #drupal-off-canvas-wrapper does not have dialog object attached to it, it is a wrapper for #drupal-off-canvas which does have dialog object. Calling dialog() on #drupal-off-canvas-wrapper will produce error from issue description:
Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'
This selector change is first proposed in MR !13 in comment #3448524-30: Automated Drupal 11 compatibility fixes → , re-mentioned in #3448524-33: Automated Drupal 11 compatibility fixes → and then introduced in commit 1866c00f. This is done as explained in previous comments in order to keep D9.5 support. However, proposed change should be done to keep D9 CSS compatibility as explained per change record https://www.drupal.org/node/3305664 → - this is just related to CSS selector that needs to be changed but not JS selectors. I guess somebody misunderstood this change record and though that we also need to change JS selector, which is not true. The selector for dialog element is the same, and it is `#drupal-off-canvas`.
Now, MR in previous comment #1 is proposing to switch to
$('#drupal-off-canvas-wrapper .ui-dialog-titlebar-close').click();
which is fine, but it is perfectly OK and a bit faster to just revert to previous code that was working before which is
$('#drupal-off-canvas').dialog('close');
2. Second problem is a data attribute that is never defined:
$('.toolbar-icon-moderation-sidebar').on('click', function (e, data) { if ($('.moderation-sidebar-container').length && (!data || !data.reload)) {
According to documentation data attribute is used to pass additional data to event.data property when event is triggered. However, `data` variable is never defined in the first place, and it looks to me, it should be removed. Maybe this was used in the past, and then got refactored but this code was not removed?
Note that this data attribute does not produce any bug, but is not doing anything usefull here and can be removed.
3. Finally, when viewing a node and with opened moderation sidebar if you click again on top right `a.toolbar-icon-moderation-sidebar` link first event that will be triggered is ajax event for /moderation-sidebar/node/nid/latest callback which will trigger loading of the sidebar again. Then event from moderation_sidebar.js will be triggered for closing this sidebar. This will result in first closing the moderation sidebar but then opening it again when ajax callback is finished - meaning sidebar will just reopen which is not expected behavior.
There are multiple ways to solve this and put moderation_sidebar event to be triggered first, before ajax event handler. Seems to me that using addEventListener() useCapture parameter is the easiest way to do it.
New commit in MR is addressing all three mentioned issues.