Skip to content

Commit

Permalink
Fix smart menu mustache linter warnings, solves moodle-an-hochschulen…
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Dec 20, 2023
1 parent e0c545e commit cf8837b
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 198 deletions.
2 changes: 1 addition & 1 deletion amd/build/fontawesome-popover.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/fontawesome-popover.min.js.map

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions amd/src/fontawesome-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ define(['jquery', 'theme_boost/popover', 'core/fragment'], function($, popover,

/**
* Filter the icons in the list with values which the user entered in the search input.
* Given input will contain the text in both aria-value and aria-label.
* Ex. "core:t\document" is aria-value and "fa-document" is aria-label.
* Given input will contain the text in both data-value and data-label.
* Ex. "core:t\document" is data-value and "fa-document" is data-label.
*
* @param {Element} target
*/
Expand All @@ -62,8 +62,8 @@ define(['jquery', 'theme_boost/popover', 'core/fragment'], function($, popover,
var li = ul.querySelectorAll('li');

for (var i = 0; i < li.length; i++) {
var value = li[i].getAttribute('aria-value');
var label = li[i].getAttribute('aria-label');
var value = li[i].getAttribute('data-value');
var label = li[i].getAttribute('data-label');
if (!value.toLowerCase().includes(filter) && !label.toLowerCase().includes(filter)) {
li[i].style.display = "none";
} else {
Expand Down Expand Up @@ -140,19 +140,20 @@ define(['jquery', 'theme_boost/popover', 'core/fragment'], function($, popover,
html: true,
placement: 'bottom',
customClass: 'fontawesome-picker',
trigger: 'click'
trigger: 'click',
sanitize: false
});

// Event observer when the popover is inserted in DOM, create event listner for each icon in icons list.
// Icon is clicked, set the icon aria-value as value for select box.
// Icon is clicked, set the icon data-value as value for select box.
// Set the icon label to value of autocomplete picker.
$(pickerInput).on('inserted.bs.popover', function() {
var ul = document.querySelector('.fontawesome-iconpicker-popover ul.fontawesome-icon-suggestions');
ul.querySelectorAll('li').forEach((li) => {
li.addEventListener('click', (e) => {
var target = e.target.closest('li');
var value = target.getAttribute('aria-value');
var label = target.getAttribute('aria-label');
var value = target.getAttribute('data-value');
var label = target.getAttribute('data-label');
pickerInput.value = label;
SELECTBOX.value = value || 0;
$(pickerInput).popover('hide');
Expand Down Expand Up @@ -188,12 +189,12 @@ define(['jquery', 'theme_boost/popover', 'core/fragment'], function($, popover,
// Add class to selected icon, helps to differentiate.
if (pickerInput.value != '') {
var iconSuggestion = document.querySelector('.fontawesome-iconpicker-popover ul.fontawesome-icon-suggestions');
if (iconSuggestion.querySelector('li[aria-label="' + pickerInput.value + '"]') !== null) {
if (iconSuggestion.querySelector('li[data-label="' + pickerInput.value + '"]') !== null) {
// Remove selected class.
iconSuggestion.querySelectorAll('li').forEach((li) =>
li.classList.remove('selected'));
// Assign selected class for new.
iconSuggestion.querySelector('li[aria-label="' + pickerInput.value + '"]').classList.add('selected');
iconSuggestion.querySelector('li[data-label="' + pickerInput.value + '"]').classList.add('selected');
}
}
});
Expand Down
33 changes: 30 additions & 3 deletions templates/core/moremenu.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,44 @@
<ul id="moremenu-{{moremenuid}}-{{navbarstyle}}" role="{{#istablist}}tablist{{/istablist}}{{^istablist}}menubar{{/istablist}}" class="nav more-nav {{navbarstyle}}">
{{#nodecollection}}
{{#children}}
{{> core/moremenu_children}}
{{#haschildren}}
<li class="dropdown nav-item {{#menuclasses}}{{.}} {{/menuclasses}} " role="none" data-forceintomoremenu="{{#forceintomoremenu}}true{{/forceintomoremenu}}{{^forceintomoremenu}}false{{/forceintomoremenu}}">
{{> core/moremenu_children}}
</li>
{{/haschildren}}
{{^haschildren}}
<li data-key="{{key}}" class="nav-item {{#menuclasses}}{{.}} {{/menuclasses}}" role="none" data-forceintomoremenu="{{#forceintomoremenu}}true{{/forceintomoremenu}}{{^forceintomoremenu}}false{{/forceintomoremenu}}">
{{> core/moremenu_children}}
</li>
{{/haschildren}}
{{/children}}
{{/nodecollection}}
{{#nodearray}}
{{!-- Menu with card style --}}
{{#card}}
{{> theme_boost_union/smartmenus-cardmenu-children}}
{{#haschildren}}
<li class="dropdown nav-item {{#card}} card-dropdown {{/card}} {{#menudata.classes}} {{.}} {{/menudata.classes}}" role="none" data-forceintomoremenu="{{#forceintomoremenu}}true{{/forceintomoremenu}}{{^forceintomoremenu}}false{{/forceintomoremenu}}">
{{> theme_boost_union/smartmenus-cardmenu-children}}
</li>
{{/haschildren}}
{{^haschildren}}
<li data-key="{{key}}" class="nav-item" role="none" data-forceintomoremenu="{{#forceintomoremenu}}true{{/forceintomoremenu}}{{^forceintomoremenu}}false{{/forceintomoremenu}}">
{{> theme_boost_union/smartmenus-cardmenu-children}}
</li>
{{/haschildren}}
{{/card}}

{{^card}}
{{> core/moremenu_children}}
{{#haschildren}}
<li class="dropdown nav-item {{#menuclasses}}{{.}} {{/menuclasses}} " role="none" data-forceintomoremenu="{{#forceintomoremenu}}true{{/forceintomoremenu}}{{^forceintomoremenu}}false{{/forceintomoremenu}}">
{{> core/moremenu_children}}
</li>
{{/haschildren}}
{{^haschildren}}
<li data-key="{{key}}" class="nav-item {{#menuclasses}}{{.}} {{/menuclasses}}" role="none" data-forceintomoremenu="{{#forceintomoremenu}}true{{/forceintomoremenu}}{{^forceintomoremenu}}false{{/forceintomoremenu}}">
{{> core/moremenu_children}}
</li>
{{/haschildren}}
{{/card}}
{{/nodearray}}
{{^drawer}}
Expand Down
Loading

0 comments on commit cf8837b

Please sign in to comment.