(function (Joomla) {
	window.jSelectEdocmanCategoryShortcode = function (id, title) {
		
        var editor = Joomla.getOptions('EDEditor');
        var tag = '{edocmancategory ' + id + '}';
        window.parent.Joomla.editors.instances[editor].replaceSelection(tag);

        if (Joomla.getOptions('isJoomla4')) {
            window.parent.Joomla.Modal.getCurrent().close();
        } else {
            window.parent.jModalClose();
        }
    };

    document.addEventListener('DOMContentLoaded', function () {
        var functionName;
        // Get the elements
        var elements = document.querySelectorAll('.select-link');

        for (var i = 0, l = elements.length; l > i; i++) {
            // Listen for click event
            elements[i].addEventListener('click', function (event) {
                event.preventDefault();
                functionName = event.target.dataset.function;
                window[functionName](event.target.dataset.id, event.target.dataset.itemid, event.target.dataset.title);
            })
        }
    });
})(Joomla);
