X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fcrm.menubar.js;h=8360557f05daf8b5cb1ea4b7c60b990c0cabeaed;hb=c20b6c4438bc8997e5dd717ec0d8ea0d37f94ba3;hp=eba37ed3c46d6c90b6281b3be088900ce874018a;hpb=2ae6888d68e3b013b0497cef35b2b9441d517d79;p=civicrm-core.git diff --git a/js/crm.menubar.js b/js/crm.menubar.js index eba37ed3c4..8360557f05 100644 --- a/js/crm.menubar.js +++ b/js/crm.menubar.js @@ -8,6 +8,7 @@ data: null, settings: {collapsibleBehavior: 'accordion'}, position: 'over-cms-menu', + toggleButton: true, attachTo: (CRM.menubar && CRM.menubar.position === 'above-crm-container') ? '#crm-container' : 'body', initialize: function() { var cache = CRM.cache.get('menubar'); @@ -231,22 +232,31 @@ } }, initializePosition: function() { - if (CRM.menubar.position === 'over-cms-menu' || CRM.menubar.position === 'below-cms-menu') { + if (CRM.menubar.toggleButton && (CRM.menubar.position === 'over-cms-menu' || CRM.menubar.position === 'below-cms-menu')) { $('#civicrm-menu') .on('click', 'a[href="#toggle-position"]', function(e) { e.preventDefault(); CRM.menubar.togglePosition(); }) - .append('
  • '); + .append('
  • '); CRM.menubar.position = CRM.cache.get('menubarPosition', CRM.menubar.position); } $('body').addClass('crm-menubar-visible crm-menubar-' + CRM.menubar.position); }, + removeToggleButton: function() { + $('#crm-menubar-toggle-position').remove(); + CRM.menubar.toggleButton = false; + if (CRM.menubar.position === 'below-cms-menu') { + CRM.menubar.togglePosition(); + } + }, 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(); } @@ -306,6 +316,12 @@ }); }, 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) { @@ -328,7 +344,34 @@ CRM.menubar.open('QuickSearch'); } } - }); + }) + .autocomplete( "instance" )._renderItem = function( ul, item ) { + var uiMenuItemWrapper = $("
    "); + if (item.value == 0) { + // "No results" + uiMenuItemWrapper.text(item.label); + } + else { + uiMenuItemWrapper.append($('') + .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 $( "
  • " ) + .append(uiMenuItemWrapper) + .appendTo( ul ); + }; $('#crm-qsearch > a').keyup(function(e) { if ($(e.target).is(this)) { $('#crm-qsearch-input').focus(); @@ -357,10 +400,6 @@ 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() {