(function($) { Drupal.behaviors.custom_search = { attach: function(context) { if (!Drupal.settings.custom_search.solr) { // Check if the search box is not empty on submit $('form.search-form', context).submit(function(){ var $this = $(this); var box = $this.find('input.custom-search-box'); if (box.val() != undefined && box.val() == '') { $this.find('input.custom-search-box').addClass('error'); return false; } // If basic search is hidden, copy or value to the keys if ($this.find('#edit-keys').parents('div.element-invisible').attr('class') == 'element-invisible') { $this.find('#edit-keys').val($this.find('#edit-or').val()); $this.find('#edit-or').val(''); } return true; }); } // Search from target $('form.search-form').attr('target', Drupal.settings.custom_search.form_target); // Displays Popup. $('form.search-form input.custom-search-box', context).bind('click focus', function(e){ var $parentForm = $(this).parents('form'); // check if there's something in the popup and displays it var popup = $parentForm.find('fieldset.custom_search-popup'); if (popup.find('input,select').length && !popup.hasClass('opened')) { popup.fadeIn().addClass('opened'); } e.stopPropagation(); }); $(document).bind('click focus', function(){ $('fieldset.custom_search-popup').hide().removeClass('opened'); }); // Handle checkboxes $('.custom-search-selector input:checkbox', context).each(function(){ var el = $(this); if (el.val() == 'c-all') { el.change(function(){ $(this).parents('.custom-search-selector').find('input:checkbox[value!=c-all]').attr('checked', false); }); } else { if (el.val().substr(0,2) == 'c-') { el.change(function(){ $('.custom-search-selector input:checkbox').each(function(){ if ($(this).val().substr(0,2) == 'o-') { $(this).attr('checked', false); } }); $(this).parents('.custom-search-selector').find('input:checkbox[value=c-all]').attr('checked', false); }); } else { el.change(function(){ $(this).parents('.custom-search-selector').find('input:checkbox[value!=' + el.val() + ']').attr('checked', false); }); } } }); // Handle popup. var popup = $('fieldset.custom_search-popup:not(.custom_search-processed)', context).addClass("custom_search-processed"); popup.click(function(e){ e.stopPropagation(); }) popup.append('' + Drupal.t('Close') + ''); $('a.custom_search-popup-close').click(function(e){ $('fieldset.custom_search-popup.opened').hide().removeClass('opened'); e.preventDefault(); }); } } })(jQuery);