diff --git a/better_exposed_filters.js b/better_exposed_filters.js index 87d606e..8bcfcf1 100644 --- a/better_exposed_filters.js +++ b/better_exposed_filters.js @@ -98,6 +98,33 @@ } // attach: function() { }; // Drupal.behaviors.better_exposed_filters = { + // This is only needed to provide ajax functionality + Drupal.behaviors.better_exposed_filters_select_as_links = { + attach: function(context) { + + $('.bef-select-as-links', context).once(function() { + var $widgets = $('.views-exposed-widgets'); + // Hide the actual form elements from the user. + $widgets.find('.views-submit-button input, .bef-select-as-links select').hide(); + var $options = $('.bef-select-as-links select option'); + $(this).find('a').click(function(event) { + // We have to prevent the page load triggered by the links. + event.preventDefault(); + event.stopPropagation(); + var text = $(this).text(); + // Set the corresponding option inside the select element + $options.filter(function() { + return $(this).text() == text; + }).attr('selected', true); + $('.bef-new-value').val($options.filter(':selected').val()); + + // Submit the form. + $widgets.find('.views-submit-button input').click(); + }); + }); + } + }; + /* * Helper functions */ diff --git a/better_exposed_filters.theme b/better_exposed_filters.theme index 57835e2..9a0c7c0 100644 --- a/better_exposed_filters.theme +++ b/better_exposed_filters.theme @@ -482,8 +482,9 @@ function theme_select_as_links($vars) { $output = ''; diff --git a/better_exposed_filters_exposed_form_plugin.inc b/better_exposed_filters_exposed_form_plugin.inc index 0d0fe1d..2877be2 100644 --- a/better_exposed_filters_exposed_form_plugin.inc +++ b/better_exposed_filters_exposed_form_plugin.inc @@ -655,7 +655,7 @@ Title Desc|Z -> A Leave the replacement value blank to remove an option al case 'bef_links': $show_apply = TRUE; - + drupal_add_js(drupal_get_path('module', 'better_exposed_filters') . '/better_exposed_filters.js'); $form[$field_id]['#theme'] = 'select_as_links'; break;