<commit_before>+function ($) {
    "use strict";

    var MediaFinder = function (element, options) {
        this.$el = $(element)
        this.options = options || {}
        this.init()
    }

    MediaFinder.prototype.init = function () {
        this.$container = $('.media-image', this.$el)
        this.$template = this.$el.get(0).querySelector('[data-image-template]')
        this.$blankTemplate = this.$el.get(0).querySelector('[data-blank-template]')
        this.$configTemplate = this.$el.get(0).querySelector('[data-config-modal-template]')

        if (this.options.isMulti === null) {
            this.options.isMulti = this.$el.hasClass('is-multi')
        }

        this.$el.on('click', '.find-button', $.proxy(this.onClickFindButton, this))
        this.$el.on('click', '.find-config-button', $.proxy(this.onClickConfigButton, this))
        this.$el.on('click', '.find-remove-button', $.proxy(this.onClickRemoveButton, this))
    }

    MediaFinder.prototype.dispose = function () {
        this.$el.off('click', '.find-button', $.proxy(this.onClickFindButton))
        this.$el.off('click', '.find-remove-button', $.proxy(this.onClickRemoveButton))
        this.$el.off('dispose-control', $.proxy(this.dispose))
        this.$el.removeData('ti.mediaFinder')

        this.$findValue = null
        this.$el = null
        this.options = null
    }

    MediaFinder.prototype.onClickRemoveButton = function (event) {
        var self = this,
            $button = $(event.target),
            $findId = $('[data-find-identifier]', $button.closest('.media-finder'))

        if (this.options.useAttachment) {
            $.ti.loadingIndicator.show()
            $.request(this.options.alias+'::onRemoveAttachment', {
                data: {media_id: $findId.val()}
            }).done(function () {
                self.removeMediaItem($button)
            }).always(function () {
                $.ti.loadingIndicator.hide()
            })
        } else {
            self.removeMediaItem($button)
        }
    }

    MediaFinder.prototype.onClickConfigButton = function (event) {
        var self = this,
            $container = $(event.target).closest('.media-finder'),
            $mediaIdentifier = $('[data-find-identifier]', $container).val(),
            $modalElement = $('<div/>', {
                id: this.options.alias+'attachment-config-modal',
                class: 'modal fade slideInDown',
                role: 'dialog',
                tabindex: -1,
                ariaLabelled: '#attachment-config-modal',
                ariaHidden: true,
            })

        $modalElement.html(this.$configTemplate.innerHTML)
        $modalElement.modal({backdrop: 'static', keyboard: false})

        $modalElement.one('shown.bs.modal', function (event) {
            $.request(self.options.alias + '::onLoadAttachmentConfig', {
                data: {media_id: $mediaIdentifier}
            }).done(function () {
                $modalElement.find('form').on('ajaxDone', function () {
                    $modalElement.modal('hide')
                })
            })
        })

        $modalElement.one('hide.bs.modal', function (event) {
            var $modalElement = $(event.target)

            $modalElement.remove()
        })
    }<commit_msg>Fix issue where media finder attachment config modal not opening (#1010)<commit_after>+function ($) {
    "use strict";

    var MediaFinder = function (element, options) {
        this.$el = $(element)
        this.options = options || {}
        this.init()
    }

    MediaFinder.prototype.init = function () {
        this.$container = $('.media-image', this.$el)
        this.$template = this.$el.get(0).querySelector('[data-image-template]')
        this.$blankTemplate = this.$el.get(0).querySelector('[data-blank-template]')
        this.$configTemplate = this.$el.get(0).querySelector('[data-config-modal-template]')

        if (this.options.isMulti === null) {
            this.options.isMulti = this.$el.hasClass('is-multi')
        }

        this.$el.on('click', '.find-button', $.proxy(this.onClickFindButton, this))
        this.$el.on('click', '.find-config-button', $.proxy(this.onClickConfigButton, this))
        this.$el.on('click', '.find-remove-button', $.proxy(this.onClickRemoveButton, this))
    }

    MediaFinder.prototype.dispose = function () {
        this.$el.off('click', '.find-button', $.proxy(this.onClickFindButton))
        this.$el.off('click', '.find-remove-button', $.proxy(this.onClickRemoveButton))
        this.$el.off('dispose-control', $.proxy(this.dispose))
        this.$el.removeData('ti.mediaFinder')

        this.$findValue = null
        this.$el = null
        this.options = null
    }

    MediaFinder.prototype.onClickRemoveButton = function (event) {
        var self = this,
            $button = $(event.target),
            $findId = $('[data-find-identifier]', $button.closest('.media-finder'))

        if (this.options.useAttachment) {
            $.ti.loadingIndicator.show()
            $.request(this.options.alias+'::onRemoveAttachment', {
                data: {media_id: $findId.val()}
            }).done(function () {
                self.removeMediaItem($button)
            }).always(function () {
                $.ti.loadingIndicator.hide()
            })
        } else {
            self.removeMediaItem($button)
        }
    }

    MediaFinder.prototype.onClickConfigButton = function (event) {
        var self = this, modal,
            $container = $(event.target).closest('.media-finder'),
            $mediaIdentifier = $('[data-find-identifier]', $container).val(),
            $modalElement = $('<div/>', {
                id: this.options.alias+'attachment-config-modal',
                class: 'modal fade slideInDown',
                role: 'dialog',
                tabindex: -1,
                ariaLabelled: '#attachment-config-modal',
                ariaHidden: true,
            })

        $modalElement.html(this.$configTemplate.innerHTML)
        modal = new bootstrap.Modal($modalElement, {backdrop: 'static', keyboard: false})
        modal.show()

        $modalElement.one('shown.bs.modal', function (event) {
            $.request(self.options.alias+'::onLoadAttachmentConfig', {
                data: {media_id: $mediaIdentifier}
            }).done(function () {
                $modalElement.find('form').on('ajaxDone', function () {
                    $modalElement.modal('hide')
                })
            })
        })

        $modalElement.one('hide.bs.modal', function (event) {
            var $modalElement = $(event.target)

            $modalElement.remove()
        })
    }
{'fraction_non_alphanumeric': 0.16317678731678134, 'fraction_numerical': 0.0017947950942267424, 'mean_word_length': 2.1073420074349443, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3747500', 'n_tokens_mistral': 1887, 'n_tokens_neox': 1852, 'n_words': 280}