initializeResponsive: function() {
var $mainMenuState = $('#crm-menubar-state');
// hide mobile menu beforeunload
- $(window).on('beforeunload unload', function() {
- CRM.menubar.spin(true);
+ $(window).on('beforeunload unload', function(e) {
+ if (!e.originalEvent.returnValue) {
+ CRM.menubar.spin(true);
+ }
if ($mainMenuState[0].checked) {
$mainMenuState[0].click();
}
});
},
focus: function (event, ui) {
+ // This is when an item is 'focussed' by keyboard up/down or mouse hover.
+ // It is not the same as actually having focus, i.e. it is not :focus
+ var lis = $(event.currentTarget).find('li[data-cid="' + ui.item.value + '"]');
+ lis.children('div').addClass('ui-state-active');
+ lis.siblings().children('div').removeClass('ui-state-active');
+ // Returning false leaves the user-entered text as it was.
return false;
},
select: function (event, ui) {
CRM.menubar.open('QuickSearch');
}
}
- });
+ })
+ .autocomplete( "instance" )._renderItem = function( ul, item ) {
+ var uiMenuItemWrapper = $("<div class='ui-menu-item-uiMenuItemWrapper'>");
+ if (item.value == 0) {
+ // "No results"
+ uiMenuItemWrapper.text(item.label);
+ }
+ else {
+ uiMenuItemWrapper.append($('<a>')
+ .attr('href', CRM.url('civicrm/contact/view', {reset: 1, cid: item.value}))
+ .css({ display: 'block' })
+ .text(item.label)
+ .click(function(e) {
+ if (e.ctrlKey || e.shiftKey || e.altKey) {
+ // Special-clicking lets you open several tabs.
+ e.stopPropagation();
+ }
+ else {
+ // Fall back to original behaviour.
+ e.preventDefault();
+ }
+ }));
+ }
+
+ return $( "<li class='ui-menu-item' data-cid=" + item.value + ">" )
+ .append(uiMenuItemWrapper)
+ .appendTo( ul );
+ };
$('#crm-qsearch > a').keyup(function(e) {
if ($(e.target).is(this)) {
$('#crm-qsearch-input').focus();
var $selection = $('.crm-quickSearchField input:checked'),
label = $selection.parent().text(),
value = $selection.val();
- // These fields are not supported by advanced search
- if (!value || value === 'first_name' || value === 'last_name') {
- value = 'sort_name';
- }
$('#crm-qsearch-input').attr({name: value, placeholder: '\uf002 ' + label});
}
$('.crm-quickSearchField').click(function() {