Changes for page Menu Macro

Last modified by Drunk Monkey on 2024-10-07 11:49

From version 11.1
edited by Drunk Monkey
on 2024-10-07 11:49
Change comment: Install extension [org.xwiki.platform:xwiki-platform-menu-ui/16.8.0]
To version 7.1
edited by Drunk Monkey
on 2023-04-26 20:38
Change comment: Install extension [org.xwiki.platform:xwiki-platform-menu-ui/15.3]

Summary

Details

XWiki.JavaScriptExtension[0]
Code
... ... @@ -58,30 +58,12 @@
58 58   xDropdown.toggleClass('open');
59 59   setDropdownButtonTitle(dropDownButton);
60 60   });
61 - let dropDownContent = $(this).contents();
62 - // We put all the content of the entry in the header,
63 - // except for the last one which is the content of the dropdown. This dropdown stays where it is.
64 - for (let index = 0; index < dropDownContent.length - 1 ; index++) {
65 - let item = dropDownContent[index];
66 - dropDownHeader.append(item);
67 - }
68 - dropDownHeader.append(dropDownButton);
69 - $(this).prepend(dropDownHeader);
70 - $(dropDownHeader).next().addClass('xDropdown-menu');
61 + dropDownHeader.append($(this).contents()[0]);
62 + dropDownHeader.append(dropDownButton);
63 + $(this).prepend(dropDownHeader);
64 + $(dropDownHeader).next().addClass('xDropdown-menu');
71 71   });
72 72  
73 - $('.xDropdown-menu').each(function() {
74 - this.addEventListener('keyup', function(event) {
75 - if (event.key === 'Escape') {
76 - // We change the state of the parent xDropdown
77 - this.parentNode.classList.remove('open');
78 - // We set the focus on the toggle button of the section we just collapsed
79 - this.parentNode.querySelector(':scope > .xDropdown-header > .xDropdown-header-toggle').focus();
80 - }
81 - event.stopPropagation();
82 - });
83 - });
84 -
85 85   $('.menu-horizontal .xDropdown').each(function() {
86 86   // In case of horizontal menus, make it so that a class is added on hover, instead of using the :hover pseudo-class
87 87   this.addEventListener("mouseover", function() {
XWiki.StyleSheetExtension[1]
Code
... ... @@ -159,19 +159,19 @@
159 159   margin-top: 0;
160 160   border-top-right-radius: 0;
161 161   border-top-left-radius: 0;
162 - overflow-wrap: break-word;
163 - hyphens: auto;
164 164   li {
165 165   /* Text inside menu */
166 166   color: @dropdown-link-color;
167 - padding: 3px 20px;
168 168   /* Links inside menu */
169 169   a {
170 170   display: block;
168 + padding: 3px 20px;
171 171   clear: both;
172 172   font-weight: normal;
173 173   line-height: @line-height-base;
174 174   color: @dropdown-link-color;
173 + overflow: hidden;
174 + text-overflow: ellipsis; // Displaying ... if the text is too long
175 175   &:hover, &:focus-within {
176 176   /* &:extend(.dropdown-menu>li>a:hover); */
177 177   text-decoration: none;
... ... @@ -200,16 +200,15 @@
200 200   }
201 201   }
202 202   /* When in dropdown we also have a link, reset the duplicated padding */
203 - & > .xDropdown-header > span > a {
203 + & > span > a {
204 204   padding: 0;
205 205   display: inherit;
206 206   }
207 - /* Reposition the toggle when in a dropdown of fixed size
208 - to avoid eating away at the bit of space we have for the text. */
209 - & > .xDropdown-header > .xDropdown-header-toggle {
207 + /* Place the arrow on the right */
208 + &:after {
210 210   position: absolute;
211 - right: 0;
212 - top: 0;
210 + margin-top: @line-height-computed / 2;
211 + right: 8px;
213 213   }
214 214   }
215 215   /* Separator horizontal inside menu */
XWiki.WikiMacroClass[0]
Macro code
... ... @@ -1,7 +1,6 @@
1 1  {{velocity}}
2 2  #set ($id = $xcontext.macro.params.id)
3 3  #set ($type = $xcontext.macro.params.type)
4 -#set ($label = $xcontext.macro.params.label)
5 5  #set ($colorTheme = $xwiki.getUserPreference('colorTheme'))
6 6  #if ("$!colorTheme" != '')
7 7   ## Make sure we use an absolute reference (see XWIKI-9672)
... ... @@ -9,24 +9,16 @@
9 9  #end
10 10  #set ($discard = $xwiki.ssx.use("$xcontext.macro.doc.prefixedFullName", {'colorTheme': $colorTheme}))
11 11  #set ($discard = $xwiki.jsx.use("$xcontext.macro.doc.prefixedFullName"))
12 -## Make sure the label is non-empty as otherwise the aria-label doesn't work.
13 -#if ("$!label" != '')
14 - #set ($label = $wikimacro.context.getXDOM().getIdGenerator().generateUniqueId('Menu',''))
15 -#end
16 16  #if($type.contains('horizontal'))
17 17   ## Make sure the id is non-empty for horizontal menus as otherwise the toggle doesn't work.
18 - #if ("$!id" == '')
13 + #if ($stringtool.isBlank("$!id"))
19 19   #set ($id = $wikimacro.context.getXDOM().getIdGenerator().generateUniqueId("M", "GeneratedMenuId"))
20 20   #end
21 - (% role='navigation' class='menu-horizontal-toggle'
22 - aria-label="${services.rendering.escape($label, 'xwiki/2.1')}" %)(((
16 + (% role="navigation" class="menu-horizontal-toggle" %)(((
23 23   (% class="navbar-header" %)(((
24 24   {{html}}
25 - <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#$!{escapetool.xml($id)}"
26 - aria-expanded="false" aria-controls="$!{escapetool.xml($id)}">
27 - <span class="sr-only">
28 - $escapetool.xml($services.localization.render('menu.ui.horizontal.toggler.description'))
29 - </span>
19 + <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#$!{escapetool.xml($id)}" aria-expanded="false">
20 + <span class="sr-only"></span>
30 30   <span class="icon-bar"></span>
31 31   <span class="icon-bar"></span>
32 32   <span class="icon-bar"></span>
... ... @@ -33,13 +33,12 @@
33 33   </button>
34 34   {{/html}}
35 35   )))
36 - (% id="$!{services.rendering.escape($id, 'xwiki/2.1')}" class="menu menu-${services.rendering.escape($!type, 'xwiki/2.1')} collapse navbar-collapse" role="navigation" %)(((
27 + (% id="$!{services.rendering.escape($id, 'xwiki/2.1')}" class="menu menu-${services.rendering.escape($!type, 'xwiki/2.1')} collapse navbar-collapse" role="menubar" %)(((
37 37   {{wikimacrocontent/}}
38 38   )))
39 39   )))
40 40  #else
41 - (% role="navigation" #if ("$!id" != '') id="${services.rendering.escape($id, 'xwiki/2.1')}"#end class="menu menu-${services.rendering.escape($!type, 'xwiki/2.1')}"
42 - aria-label="${services.rendering.escape($label, 'xwiki/2.1')}" %)(((
32 + (% #if ("$!id" != '') id="${services.rendering.escape($id, 'xwiki/2.1')}"#end class="menu menu-${services.rendering.escape($!type, 'xwiki/2.1')}" role="menu" %)(((
43 43   {{wikimacrocontent/}}
44 44   )))
45 45  #end
XWiki.WikiMacroParameterClass[3]
Parameter name
... ... @@ -1,1 +1,0 @@
1 -label
Parameter description
... ... @@ -1,1 +1,0 @@
1 -Optional menu label used to describe the content of the menu.
Parameter mandatory
... ... @@ -1,1 +1,0 @@
1 -No