Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I646 search dropdown #674

Merged
merged 5 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions app/assets/javascripts/hyrax/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Override Hyrax v3.6.0 to fix the set label and modify set form action to support searching with resource types

(function($){
Hyrax.Search = function (element) {
this.$element = $(element);

this.init = function() {
this.$label = this.$element.find('[data-search-element="label"]');
this.$visibleLabel = this.$element.find('.dropdown-toggle').find('span[aria-hidden="true"]');
this.$items = this.$element.find('[data-search-option]');
this.setDefault();
}

this.init();
this.attachEvents();
}


Hyrax.Search.prototype = {
attachEvents: function() {

_this = this;
this.$items.on('click', function(event) {
event.preventDefault();
_this.clicked($(this))
});
},

clicked: function($anchor) {
this.setLabel($anchor.data('search-label'));
this.setFormAction($anchor.data('search-option'));
},

setFormAction: function(path) {
this.$element.attr('action', path);
this.$element.find('input[type="hidden"]').remove();
var params = new URLSearchParams(path.split('?')[1]);
for (const [key, value] of params) {
this.$element.append('<input type="hidden" name="' + key + '" value="' + value + '">');
}
},

getLabelForValue: function(value) {
selected = this.$element.find('[data-search-option="'+ value +'"]');
return selected.data('search-label');
},

setDefault: function() {
this.setLabel(this.getLabelForValue(this.$element.attr('action')));
},

setLabel: function(label) {
this.$label.html(label);
this.$visibleLabel.html(label);
}

}

$.fn.search = function(option) {
return this.each(function() {
var $this = $(this);
var data = $this.data('search');

if (!data) $this.data('search', (data = new Hyrax.Search(this)));
})
}

})(jQuery);


Blacklight.onLoad(function() {
$('#search-form-header').search();
});
2 changes: 1 addition & 1 deletion app/assets/stylesheets/themes/dc_repository.scss
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ body.dc_repository {
border-radius: 0 !important;
position: relative;
z-index: 3;
padding: 0 !important;
padding: 0 1em !important;
min-height: auto;
border: none;
border-left: 2px solid $gray-0;
Expand Down
38 changes: 15 additions & 23 deletions app/views/themes/dc_repository/catalog/_search_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,34 @@
<%= hidden_field_tag :search_field, 'all_fields' %>
<div class="form-group">
<%# OVERRIDE: Hyrax v3.4.1 Remove label from form-group %>

<div class="input-group">
<%= text_field_tag :q, current_search_parameters , class: "q form-control", id: "search-field-header", placeholder: t("hyrax.search.form.q.placeholder") %>
<%# OVERRIDE: Hyrax v3.4.1 switch button order %>
<div class="input-group-btn">
<% if current_user %>
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">

<span class="sr-only" data-search-element="label"><%= t("hyrax.search.form.option.all.label_long", application_name: application_name) %></span>
<span aria-hidden="true"><%= t("hyrax.search.form.option.all.label_short") %></span>
<%# OVERRIDE: Hyrax v3.4.1 change dropdown icon %>
<span class="fa fa-thin fa-chevron-down"></span>
</button>

<ul class="dropdown-menu pull-right">
<li>
<%= link_to t("hyrax.search.form.option.all.label_long", application_name: application_name), "#",
data: { "search-option" => main_app.search_catalog_path, "search-label" => t("hyrax.search.form.option.all.label_short") } %>
</li>
<li>
<%= link_to t("hyrax.search.form.option.my_works.label_long"), "#",
data: { "search-option" => hyrax.my_works_path, "search-label" => t("hyrax.search.form.option.my_works.label_short") } %>
</li>
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">
<span class="sr-only" data-search-element="label"><%= t("hyrax.search.form.option.all.label_long", application_name: application_name) %></span>
<span aria-hidden="true"><%= t("hyrax.search.form.option.all.label_short") %></span>
<%# OVERRIDE: Hyrax v3.4.1 change dropdown icon %>
<span class="fa fa-thin fa-chevron-down"></span>
</button>
<ul class="dropdown-menu pull-right">
<li>
<%= link_to t("hyrax.search.form.option.all.label_long", application_name: application_name), "#",
data: { "search-option" => main_app.search_catalog_path, "search-label" => t("hyrax.search.form.option.all.label_short") } %>
</li>
<% Hyrax.config.registered_curation_concern_types.map(&:titleize).each do |concern| %>
<% next if concern == 'Attachment' %>
<li>
<%= link_to t("hyrax.search.form.option.my_collections.label_long"), "#",
data: { "search-option" => hyrax.my_collections_path, "search-label" => t("hyrax.search.form.option.my_collections.label_short") } %>
<%= link_to concern, "#",
data: { "search-option" => main_app.search_catalog_path(f: { human_readable_type_sim: [concern] }), "search-label" => concern } %>
</li>
<% end %>

</ul>
<button type="submit" class="btn" id="search-submit-header">
<span class="glyphicon glyphicon-search"></span>
<span class="search-submit-text"><%= t('hyrax.search.button.text') %></span>
</button>
</div><!-- /.input-group-btn -->
</div><!-- /.input-group -->

</div><!-- /.form-group -->
<% end %>
Loading