Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menubar - Add "find menu item" search feature #16597

Merged
merged 1 commit into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions css/crm-menubar.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ body.crm-menubar-over-cms-menu #crm-menubar-toggle-position a i {
transform: rotate(180deg);
}

/* Drilldown menu item finder */
#civicrm-menu [data-name=MenubarDrillDown] > a {
padding-top: 2px;
padding-bottom: 2px;
}
#crm-menubar-drilldown {
padding: 4px;
background-color: #eee;
}
#crm-menubar-drilldown:focus {
background-color: white;
}
#crm-menubar-drilldown + .sub-arrow:before {
margin-top: 5px;
}

@media (min-width: $breakMin) {

/* Switch to desktop layout
Expand Down
5 changes: 5 additions & 0 deletions extension-compatibility.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"com.civibridge.quickmenu": {
"obsolete": "5.24",
"disable": true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colemanw Wasn't aware of "obsolete" capability. Kinda cool. Is this documented somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's fairly new. So far its being used for extensions whose features have been migrated into core (Api4, KAM, ExportUI, etc.). Adding an extension to this list will:

  1. Automatically disable/uninstall it during the upgrade.
  2. Not allow it to be reenabled; label it "obsolete" in the UI.
  3. Resolve any dependencies (so an extension that declares a dependency on Api4 will still work)

Let me see if I can find a spot for that in the dev docs pages...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"uninstall": true
},
"org.civicrm.exportui": {
"obsolete": "5.23",
"disable": true,
Expand Down
46 changes: 43 additions & 3 deletions js/crm.menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@
})
.on('show.smapi', function(e, menu) {
// Focus menu when opened with an accesskey
$(menu).siblings('a[accesskey]').focus();
if ($(menu).parent().data('name') === 'Home') {
$('#crm-menubar-drilldown').focus();
} else {
$(menu).siblings('a[accesskey]').focus();
}
})
.smartmenus(CRM.menubar.settings);
initialized = true;
CRM.menubar.initializeResponsive();
CRM.menubar.initializeSearch();
CRM.menubar.initializeDrill();
});
}
},
Expand Down Expand Up @@ -144,6 +149,9 @@
getItem: function(itemName) {
return traverse(CRM.menubar.data.menu, itemName, 'get');
},
findItems: function(searchTerm) {
return findRecursive(CRM.menubar.data.menu, searchTerm.toLowerCase().replace(/ /g, ''));
},
addItems: function(position, targetName, items) {
var list, container, $ul;
if (position === 'before' || position === 'after') {
Expand Down Expand Up @@ -376,6 +384,14 @@
return !$('ul.crm-quickSearch-results').is(':visible:not(.ui-state-disabled)');
});
},
initializeDrill: function() {
$('#civicrm-menu').on('keyup', '#crm-menubar-drilldown', function() {
var term = $(this).val(),
results = term ? CRM.menubar.findItems(term).slice(0, 20) : [];
$(this).parent().next('ul').html(getTpl('branch')({items: results, branchTpl: getTpl('branch'), drillTpl: _.noop}));
$('#civicrm-menu').smartmenus('refresh').smartmenus('itemActivate', $(this).closest('a'));
});
},
treeTpl:
'<nav id="civicrm-menu-nav">' +
'<input id="crm-menubar-state" type="checkbox" />' +
Expand Down Expand Up @@ -408,6 +424,11 @@
'<% }) %>' +
'</ul>' +
'</li>',
drillTpl:
'<li class="crm-menu-border-bottom" data-name="MenubarDrillDown">' +
'<a href="#"><input type="text" id="crm-menubar-drilldown" placeholder="' + _.escape(ts('Find menu item...')) + '"></a>' +
'<ul></ul>' +
'</li>',
branchTpl:
'<% _.forEach(items, function(item) { %>' +
'<li <%= attr("li", item) %>>' +
Expand All @@ -420,7 +441,10 @@
'<% } %>' +
'</a>' +
'<% if (item.child) { %>' +
'<ul><%= branchTpl({items: item.child, branchTpl: branchTpl}) %></ul>' +
'<ul>' +
'<% if (item.name === "Home") { %><%= drillTpl() %><% } %>' +
'<%= branchTpl({items: item.child, branchTpl: branchTpl}) %>' +
'</ul>' +
'<% } %>' +
'</li>' +
'<% }) %>'
Expand All @@ -429,9 +453,10 @@
function getTpl(name) {
if (!templates) {
templates = {
branch: _.template(CRM.menubar.branchTpl, {imports: {_: _, attr: attr}}),
drill: _.template(CRM.menubar.drillTpl, {}),
search: _.template(CRM.menubar.searchTpl, {imports: {_: _, ts: ts, CRM: CRM}})
};
templates.branch = _.template(CRM.menubar.branchTpl, {imports: {_: _, attr: attr, drillTpl: templates.drill}});
templates.tree = _.template(CRM.menubar.treeTpl, {imports: {branchTpl: templates.branch, searchTpl: templates.search, ts: ts}});
}
return templates[name];
Expand Down Expand Up @@ -470,6 +495,21 @@
return found;
}

function findRecursive(collection, searchTerm) {
var items = _.filter(collection, function(item) {
return item.label && _.includes(item.label.toLowerCase().replace(/ /g, ''), searchTerm);
});
_.each(collection, function(item) {
if (_.isPlainObject(item) && item.child) {
var childMatches = findRecursive(item.child, searchTerm);
if (childMatches.length) {
Array.prototype.push.apply(items, childMatches);
}
}
});
return items;
}

function attr(el, item) {
var ret = [], attr = _.cloneDeep(item.attr || {}), a = ['rel', 'accesskey', 'target'];
if (el === 'a') {
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/common/accesskeys.hlp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<li>{$accessKey}+<span>E</span> - {ts}Edit Contact (View Contact Summary Page){/ts}</li>
<li>{$accessKey}+<span>S</span> - {ts}Save Button{/ts}</li>
<li>{$accessKey}+<span>N</span> - {ts}Add a new record in each tab (Activities, Tags,..etc){/ts}</li>
<li>{$accessKey}+<span>M</span> - {ts}Open the CiviCRM menubar{/ts}</li>
<li>{$accessKey}+<span>M</span> - {ts}Find menu item...{/ts}</li>
<li>{$accessKey}+<span>Q</span> - {ts}Quicksearch{/ts}</li>
</ul>
{literal}<style type="text/css">
Expand Down