Sha256: 2a5d298db3239d158585944eabcbf3162540c2a0ad2307829837c76faa13aae9

Contents?: true

Size: 1.4 KB

Versions: 83

Compression:

Stored size: 1.4 KB

Contents

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

    this.init = function() {
      this.$label = this.$element.find('[data-search-element="label"]');
      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);
    },

    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);
    }

  }

  $.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();
});

Version data entries

83 entries across 83 versions & 2 rubygems

Version Path
hyrax-5.0.1 app/assets/javascripts/hyrax/search.js
hyrax-5.0.0 app/assets/javascripts/hyrax/search.js
hyrax-5.0.0.rc3 app/assets/javascripts/hyrax/search.js
hyrax-5.0.0.rc2 app/assets/javascripts/hyrax/search.js
hyrax-5.0.0.rc1 app/assets/javascripts/hyrax/search.js
hyrax-3.6.0 app/assets/javascripts/hyrax/search.js
hyrax-4.0.0 app/assets/javascripts/hyrax/search.js
hyrax-4.0.0.rc3 app/assets/javascripts/hyrax/search.js
hyrax-4.0.0.rc2 app/assets/javascripts/hyrax/search.js
hyrax-4.0.0.rc1 app/assets/javascripts/hyrax/search.js
hyrax-3.5.0 app/assets/javascripts/hyrax/search.js
hyrax-4.0.0.beta2 app/assets/javascripts/hyrax/search.js
hyrax-3.4.2 app/assets/javascripts/hyrax/search.js
hyrax-4.0.0.beta1 app/assets/javascripts/hyrax/search.js
hyrax-3.4.1 app/assets/javascripts/hyrax/search.js
hyrax-3.4.0 app/assets/javascripts/hyrax/search.js
hyrax-3.3.0 app/assets/javascripts/hyrax/search.js
hyrax-3.2.0 app/assets/javascripts/hyrax/search.js
hyrax-2.9.6 app/assets/javascripts/hyrax/search.js
hyrax-3.1.0 app/assets/javascripts/hyrax/search.js