app/assets/javascripts/hyrax/authority_select.es6 in hyrax-1.1.1 vs app/assets/javascripts/hyrax/authority_select.es6 in hyrax-2.0.0.beta1

- old
+ new

@@ -1,62 +1,56 @@ /** 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; + constructor(editor, options) { + this.editor = editor + 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; - - $(selectBox).on('change', function (data) { - var selectBoxValue = $(this).val(); - $(inputField).each(function (data) { $(this).data('autocomplete-url', selectBoxValue); - - }); - setupAutocomplete(); - }); + 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 observer = new MutationObserver(function (mutations) { - mutations.forEach(function (mutation) { - $(inputField).each(function (data) { $(this).data('autocomplete-url', $(selectBox).val()) }); - setupAutocomplete(); - }); - }); + var selectBox = this.selectBox; + var inputField = this.inputField; - var config = { childList: true }; - observer.observe(document.body, config); + var observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + $(inputField).each(function (data) { $(this).data('autocomplete-url', $(selectBox).val()) }); + this.setupAutocomplete(); + }); + }); + + var config = { childList: true }; + observer.observe(document.body, config); } /** - * Initialize bindings + * intialize the Hyrax autocomplete with the fields that you are using */ - initialize() { - this.selectBoxChange(); - this.observeAddedElement(); - setupAutocomplete(); + setupAutocomplete() { + this.editor.autocomplete() } } - -/** - * intialize the Hyrax autocomplete with the fields that you are using - */ -function setupAutocomplete() { - Hyrax.autocomplete() -};