@@ -19,6 +19,65 @@ <h5 class="p-muted-heading">Last updated</h5>
1919 < hr >
2020{% endif %}
2121
22+ {%- if aliases -%}
23+ {%- set show_more = "Show more" -%}
24+ {%- set show_less = "Show less" -%}
25+
26+ {#-
27+ # The list starts displaying maximum 3 elements with the rest hidden.
28+ # With the script provided and the link element rendered the user can toggle
29+ # displaying and hiding all the aliases.
30+ -#}
31+ < h5 class ="p-muted-heading "> Aliases</ h5 >
32+ < ul class ="p-list js-expandable-list ">
33+ {%- set aliases_len = aliases|length -%}
34+ {%- set default_visible_aliases = 3 -%}
35+ {%- for alias in aliases -%}
36+ {%- set invisible_class = "" -%}
37+ {%- if loop.index > default_visible_aliases -%}
38+ {%- set invisible_class = "js-hidable u-hide" -%}
39+ {%- endif -%}
40+ < li class ="p-list__item {{ invisible_class }} ">
41+ {{ alias[0]|safe }} › {{ alias[1]|safe }}
42+ </ li >
43+ {%- endfor -%}
44+ {%- if aliases_len > default_visible_aliases -%}
45+ < li class ="p-list__item ">
46+ < a class ="js-toggle-full-list " href ="# " title ="Display more/less aliases ">
47+ {{ show_more }}
48+ </ a >
49+ </ li >
50+ {%- endif -%}
51+ </ ul >
52+ < hr >
53+
54+ < script >
55+ // Handle aliases "show more" button
56+ const list = document . querySelector ( ".js-expandable-list" ) ;
57+ const showMoreButton = document . querySelector ( ".js-toggle-full-list" ) ;
58+ let hasAllElementsDisplayed = false ;
59+
60+ const updateAliasesListUI = ( displayAllElements , elements ) => {
61+ // change button
62+ showMoreButton . innerHTML = displayAllElements ? "{{ show_less }}" : "{{ show_more }}" ;
63+ // toggle hide classes
64+ for ( const element of elements ) {
65+ element . classList . toggle ( 'u-hide' , ! displayAllElements ) ;
66+ }
67+ }
68+
69+ if ( list && showMoreButton ) {
70+ const listElements = list . querySelectorAll ( ".js-hidable" ) ;
71+ showMoreButton . addEventListener ( "click" , ( e ) => {
72+ e . preventDefault ( ) ;
73+ // switch toggle
74+ hasAllElementsDisplayed = ! hasAllElementsDisplayed ;
75+ updateAliasesListUI ( hasAllElementsDisplayed , listElements ) ;
76+ } ) ;
77+ }
78+ </ script >
79+ {%- endif -%}
80+
2281{% if links %}
2382 {% if links["website"] %}
2483 < h5 class ="p-muted-heading "> Websites</ h5 >
0 commit comments