Sha256: 2d634badbc2013f9845543bd541b5ac5bcd0adfaf5b8e659c13652703c30a4c2

Contents?: true

Size: 1.95 KB

Versions: 61

Compression:

Stored size: 1.95 KB

Contents

import Autocomplete from 'hyrax/autocomplete'

/** Class for authority selection on an input field */
export default class AuthoritySelect {
    /**
     * Create an AuthoritySelect
     * @param {Editor} editor - The parent container
     * @param {string} selectBox - The selector for the select box
     * @param {string} inputField - The selector for the input field
     */
    constructor(options) {
    	this.selectBox = options.selectBox
    	this.inputField = options.inputField
    	this.selectBoxChange();
    	this.observeAddedElement();
    	this.setupAutocomplete();
    }

    /**
     * Bind behavior for select box
     */
    selectBoxChange() {
      	var selectBox = this.selectBox;
      	var inputField = this.inputField;
        var _this2 = this
      	$(selectBox).on('change', function(data) {
      	    var selectBoxValue = $(this).val();
      	    $(inputField).each(function (data) {
              $(this).data('autocomplete-url', selectBoxValue);
      	       _this2.setupAutocomplete()
            });
      	});
    }

    /**
     * Create an observer to watch for added input elements
     */
    observeAddedElement() {
      	var selectBox = this.selectBox;
      	var inputField = this.inputField;
        var _this2 = this

      	var observer = new MutationObserver((mutations) => {
      	    mutations.forEach((mutation) => {
      		      $(inputField).each(function (data) {
                  $(this).data('autocomplete-url', $(selectBox).val())
      		        _this2.setupAutocomplete();
                });
      	    });
      	});

      	var config = { childList: true };
      	observer.observe(document.body, config);
    }

    /**
     * intialize the Hyrax autocomplete with the fields that you are using
     */
    setupAutocomplete() {
      var inputField = $(this.inputField);
      var autocomplete = new Autocomplete()
      autocomplete.setup(inputField, inputField.data('autocomplete'), inputField.data('autocompleteUrl'))
    }
}

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
hyrax-2.5.1 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.5.0 app/assets/javascripts/hyrax/authority_select.es6
hyrax-3.0.0.pre.beta2 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.4.1 app/assets/javascripts/hyrax/authority_select.es6
hyrax-3.0.0.pre.beta1 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.4.0 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.3.3 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.3.2 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.3.1 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.3.0 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.2.4 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.2.3 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.2.2 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.2.1 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.2.0 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.1.0 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.1.0.rc4 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.1.0.rc3 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.1.0.rc2 app/assets/javascripts/hyrax/authority_select.es6
hyrax-2.1.0.rc1 app/assets/javascripts/hyrax/authority_select.es6