diff --git a/app/assets/javascripts/hyrax/search.js b/app/assets/javascripts/hyrax/search.js new file mode 100644 index 00000000..bfec4c3c --- /dev/null +++ b/app/assets/javascripts/hyrax/search.js @@ -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(''); + } + }, + + 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(); +}); diff --git a/app/assets/stylesheets/themes/dc_repository.scss b/app/assets/stylesheets/themes/dc_repository.scss index d171fc9e..98cc23f0 100644 --- a/app/assets/stylesheets/themes/dc_repository.scss +++ b/app/assets/stylesheets/themes/dc_repository.scss @@ -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; diff --git a/app/views/themes/dc_repository/catalog/_search_form.html.erb b/app/views/themes/dc_repository/catalog/_search_form.html.erb index 81851147..87e5b1aa 100644 --- a/app/views/themes/dc_repository/catalog/_search_form.html.erb +++ b/app/views/themes/dc_repository/catalog/_search_form.html.erb @@ -5,35 +5,28 @@ <%= hidden_field_tag :search_field, 'all_fields' %>