Select2 - Fix auto-expanding collapsible optgroups for multi-selects
[civicrm-core.git] / js / Common.js
index c17432bb7f379badfe85bf60e33cd44d751a2f82..fb9d0c3d8af55d7cfb770590f55daa21d661bcfd 100644 (file)
@@ -368,6 +368,9 @@ if (!CRM.vars) CRM.vars = {};
         settings.width = '' + parseInt(percentage+gap-((screenWidth - 700)/7*(gap)/100), 10) + '%';
       }
     }
+    if (settings.dialogClass && !_.includes(settings.dialogClass, 'crm-container')) {
+      settings.dialogClass += ' crm-container';
+    }
     return settings;
   };
 
@@ -480,8 +483,8 @@ if (!CRM.vars) CRM.vars = {};
           $('.crm-select2-row-description', '#select2-drop').each(function() {
             $(this).closest('.select2-result-label').attr('title', $(this).text());
           });
-          // Collapsible optgroups should be expanded when searching
-          if ($('#select2-drop.collapsible-optgroups-enabled .select2-search input.select2-input').val()) {
+          // Collapsible optgroups should be expanded when searching (searching happens within select2-drop for single selects, but within the element for multiselects; this handles both)
+          if ($('#select2-drop.collapsible-optgroups-enabled .select2-search input.select2-input, .select2-dropdown-open.collapsible-optgroups .select2-search-field input.select2-input').val()) {
             $('#select2-drop.collapsible-optgroups-enabled li.select2-result-with-children')
               .addClass('optgroup-expanded');
           }
@@ -1145,10 +1148,11 @@ if (!CRM.vars) CRM.vars = {};
           $(this).addClass('crm-tooltip-down');
         }
         if (!$(this).children('.crm-tooltip-wrapper').length) {
+          var tooltipContents = $(this)[0].hasAttribute('data-tooltip-url') ? $(this).attr('data-tooltip-url') : this.href;
           $(this).append('<div class="crm-tooltip-wrapper"><div class="crm-tooltip"></div></div>');
           $(this).children().children('.crm-tooltip')
             .html('<div class="crm-loading-element"></div>')
-            .load(this.href);
+            .load(tooltipContents);
         }
       })
       .on('mouseleave', 'a.crm-summary-link', function () {