Class: Blacklight::SearchBarComponent
- Includes:
- ContentAreasShim
- Defined in:
- app/components/blacklight/search_bar_component.rb
Direct Known Subclasses
Instance Method Summary collapse
- #advanced_search_enabled? ⇒ Boolean
-
#autocomplete_path ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #autofocus ⇒ Object
-
#initialize(url:, params:, advanced_search_url: nil, classes: ['search-query-form'], prefix: nil, method: 'GET', q: nil, query_param: :q, search_field: nil, search_fields: nil, autocomplete_path: nil, autofocus: nil, i18n: { scope: 'blacklight.search.form' }) ⇒ SearchBarComponent
constructor
rubocop:disable Metrics/ParameterLists.
- #search_fields ⇒ Object
Methods included from ContentAreasShim
Methods inherited from Component
Constructor Details
#initialize(url:, params:, advanced_search_url: nil, classes: ['search-query-form'], prefix: nil, method: 'GET', q: nil, query_param: :q, search_field: nil, search_fields: nil, autocomplete_path: nil, autofocus: nil, i18n: { scope: 'blacklight.search.form' }) ⇒ SearchBarComponent
rubocop:disable Metrics/ParameterLists
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/components/blacklight/search_bar_component.rb', line 11 def initialize( url:, params:, advanced_search_url: nil, classes: ['search-query-form'], prefix: nil, method: 'GET', q: nil, query_param: :q, search_field: nil, search_fields: nil, autocomplete_path: nil, autofocus: nil, i18n: { scope: 'blacklight.search.form' } ) @url = url @advanced_search_url = advanced_search_url @q = q || params[:q] @query_param = query_param @search_field = search_field || params[:search_field] @params = params.except(:q, :search_field, :utf8, :page) @prefix = prefix @classes = classes @method = method @autocomplete_path = autocomplete_path @autofocus = autofocus @search_fields = search_fields @i18n = i18n end |
Instance Method Details
#advanced_search_enabled? ⇒ Boolean
58 59 60 |
# File 'app/components/blacklight/search_bar_component.rb', line 58 def advanced_search_enabled? blacklight_config.advanced_search.enabled end |
#autocomplete_path ⇒ Object
rubocop:enable Metrics/ParameterLists
35 36 37 38 39 |
# File 'app/components/blacklight/search_bar_component.rb', line 35 def autocomplete_path return nil unless blacklight_config.autocomplete_enabled @autocomplete_path end |
#autofocus ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'app/components/blacklight/search_bar_component.rb', line 41 def autofocus if @autofocus.nil? blacklight_config. && controller.is_a?(Blacklight::Catalog) && controller.action_name == "index" && !controller.has_search_parameters? else @autofocus end end |
#search_fields ⇒ Object
52 53 54 55 56 |
# File 'app/components/blacklight/search_bar_component.rb', line 52 def search_fields @search_fields ||= blacklight_config.search_fields.values .select { |field_def| helpers.should_render_field?(field_def) } .collect { |field_def| [helpers.label_for_search_field(field_def.key), field_def.key] } end |