Sha256: 2d406a038df14bfe8701363aaf695311f3db48f9770d70325dea5909def3766f

Contents?: true

Size: 1.52 KB

Versions: 9

Compression:

Stored size: 1.52 KB

Contents

/** Class for authority selection on an input field */
export default class AuthoritySelect {
    /**
     * Create an AuthoritySelect
     * @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;
    }

    /**
     * Bind behavior for select box
     */
    selectBoxChange() {
	var selectBox = this.selectBox;
	var inputField = this.inputField;
	
	$(selectBox).on('change', function (data) {
	    var selectBoxValue = $(this).val();
	    $(inputField).each(function (data) { $(this).data('autocomplete-url', selectBoxValue);
						 
					       });
	    setupAutocomplete();
	});
    }
    /**
     * Create an observer to watch for added input elements
     */
    observeAddedElement() {
	var selectBox = this.selectBox;
	var inputField = this.inputField;
	
	
	var observer = new MutationObserver(function (mutations) {
	    mutations.forEach(function (mutation) {
		$(inputField).each(function (data) { $(this).data('autocomplete-url', $(selectBox).val()) });
		setupAutocomplete();
	    });
	});

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

    /**
     * Initialize bindings
     */
    initialize() {
	this.selectBoxChange();
	this.observeAddedElement();
	setupAutocomplete();
    }
}

/**
 * intialize the Hyrax autocomplete with the fields that you are using
 */
function setupAutocomplete() {
  Hyrax.autocomplete()
};

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hyrax-1.1.1 app/assets/javascripts/hyrax/authority_select.es6
hyrax-1.1.0 app/assets/javascripts/hyrax/authority_select.es6
hyrax-1.0.5 app/assets/javascripts/hyrax/authority_select.es6
hyrax-1.0.4 app/assets/javascripts/hyrax/authority_select.es6
hyrax-1.0.3 app/assets/javascripts/hyrax/authority_select.es6
hyrax-1.0.2 app/assets/javascripts/hyrax/authority_select.es6
hyrax-1.0.1 app/assets/javascripts/hyrax/authority_select.es6
hyrax-1.0.0.rc2 app/assets/javascripts/hyrax/authority_select.es6
hyrax-1.0.0.rc1 app/assets/javascripts/hyrax/authority_select.es6