@@ -76,6 +76,65 @@ <h5 class="p-muted-heading">Source code</h5>
7676 < hr >
7777 {% endif %}
7878
79+ {%- if aliases -%}
80+ {%- set show_more = "Show more" -%}
81+ {%- set show_less = "Show less" -%}
82+
83+ {#-
84+ # The list starts displaying maximum 3 elements with the rest hidden.
85+ # With the script provided and the link element rendered the user can toggle
86+ # displaying and hiding all the aliases.
87+ -#}
88+ < h5 class ="p-muted-heading "> Command › Alias</ h5 >
89+ < ul class ="p-list js-expandable-list ">
90+ {%- set aliases_len = aliases|length -%}
91+ {%- set default_visible_aliases = 3 -%}
92+ {%- for alias in aliases -%}
93+ {%- set invisible_class = "" -%}
94+ {%- if loop.index > default_visible_aliases -%}
95+ {%- set invisible_class = "js-hidable u-hide" -%}
96+ {%- endif -%}
97+ < li class ="p-list__item {{ invisible_class }} ">
98+ {{ alias[0]|safe }} › {{ alias[1]|safe }}
99+ </ li >
100+ {%- endfor -%}
101+ {%- if aliases_len > default_visible_aliases -%}
102+ < li class ="p-list__item ">
103+ < a class ="js-toggle-full-list " href ="# " title ="Display more/less aliases ">
104+ {{ show_more }}
105+ </ a >
106+ </ li >
107+ {%- endif -%}
108+ </ ul >
109+ < hr >
110+
111+ < script >
112+ // Handle aliases "show more" button
113+ const list = document . querySelector ( ".js-expandable-list" ) ;
114+ const showMoreButton = document . querySelector ( ".js-toggle-full-list" ) ;
115+ let hasAllElementsDisplayed = false ;
116+
117+ const updateAliasesListUI = ( displayAllElements , elements ) => {
118+ // change button
119+ showMoreButton . innerHTML = displayAllElements ? "{{ show_less }}" : "{{ show_more }}" ;
120+ // toggle hide classes
121+ for ( const element of elements ) {
122+ element . classList . toggle ( 'u-hide' , ! displayAllElements ) ;
123+ }
124+ }
125+
126+ if ( list && showMoreButton ) {
127+ const listElements = list . querySelectorAll ( ".js-hidable" ) ;
128+ showMoreButton . addEventListener ( "click" , ( e ) => {
129+ e . preventDefault ( ) ;
130+ // switch toggle
131+ hasAllElementsDisplayed = ! hasAllElementsDisplayed ;
132+ updateAliasesListUI ( hasAllElementsDisplayed , listElements ) ;
133+ } ) ;
134+ }
135+ </ script >
136+ {%- endif -%}
137+
79138 {% if links["issues"] %}
80139 < h5 class ="p-muted-heading "> Report a bug</ h5 >
81140 < ul class ="p-list ">
0 commit comments