<commit_before>girder.wrap(girder.views.ItemView, 'render', function (render) {
    // ItemView is a special case in which rendering is done asynchronously,
    // so we must listen for a render event.
    this.once('g:rendered', function () {
        new girder.views.ImageViewerSelectWidget({
            el: $('<div>', {class: 'g-item-image-viewer-select'})
                .insertAfter(this.$('.g-item-info')),
            parentView: this,
            imageModel: this.model
        });
    }, this);
    render.call(this);
});


girder.views.ImageViewerSelectWidget = girder.View.extend({
    events: {
        'change select': function (event) {
            this._selectViewer(event.target.value);
        }
    },

    initialize: function (settings) {
        this.imageModel = settings.imageModel;
        this.currentViewer = null;
        this.viewers = [
            {
                name: 'openseadragon',
                label: 'OpenSeaDragon',
                type: girder.views.OpenseadragonImageViewerWidget
            },
            {
                name: 'leaflet',
                label: 'Leaflet',
                type: girder.views.LeafletImageViewerWidget
            },
            {
                name: 'openlayers',
                label: 'OpenLayers',
                type: girder.views.OpenlayersImageViewerWidget
            },
            {
                name: 'geojs',
                label: 'GeoJS',
                type: girder.views.GeojsImageViewerWidget
            }
            //{
            //    name: 'slideatlas',
            //    label: 'SlideAtlas',
            //    type: girder.views.SlideatlasImageViewerWidget
            //},
        ];

        this.render()
    },

    render: function () {
        this.$el.html(girder.templates.imageViewerSelectWidget({
            viewers: this.viewers
        }));
        // TODO: choose an actual default, and update the option element to match
        this._selectViewer(this.viewers[0].name);
        return this;
    },

    _selectViewer: function (viewerName) {
        if (this.currentViewer) {
            this.currentViewer.destroy();
            this.currentViewer = null;
        }
        this.$('.image-viewer').toggleClass('hidden', true);

        var viewerType = _.findWhere(this.viewers, {name: viewerName}).type;
        // GeoJs isn't always fully removing itself from its element when
        // destroyed, so use dedicated elements for each viewer for now
        var viewerEl = this.$('#' + viewerName);
        viewerEl.toggleClass('hidden', false);
        this.currentViewer = new viewerType({
            el: viewerEl,
            parentView: this,
            //itemId: this.imageModel.id,
            itemId: 'test'
        });
    }

});<commit_msg>Fetch actual images if available<commit_after>girder.wrap(girder.views.ItemView, 'render', function (render) {
    // ItemView is a special case in which rendering is done asynchronously,
    // so we must listen for a render event.
    this.once('g:rendered', function () {
        if (this.model.get('largeImage')) {
            new girder.views.ImageViewerSelectWidget({
                el: $('<div>', {class: 'g-item-image-viewer-select'})
                    .insertAfter(this.$('.g-item-info')),
                parentView: this,
                imageModel: this.model
            });
        }
    }, this);
    render.call(this);
});


girder.views.ImageViewerSelectWidget = girder.View.extend({
    events: {
        'change select': function (event) {
            this._selectViewer(event.target.value);
        }
    },

    initialize: function (settings) {
        this.itemId = settings.imageModel.get('largeImage') === 'test' ?
            'test' :
            settings.imageModel.id;
        this.currentViewer = null;
        this.viewers = [
            {
                name: 'openseadragon',
                label: 'OpenSeaDragon',
                type: girder.views.OpenseadragonImageViewerWidget
            },
            {
                name: 'leaflet',
                label: 'Leaflet',
                type: girder.views.LeafletImageViewerWidget
            },
            {
                name: 'openlayers',
                label: 'OpenLayers',
                type: girder.views.OpenlayersImageViewerWidget
            },
            {
                name: 'geojs',
                label: 'GeoJS',
                type: girder.views.GeojsImageViewerWidget
            }
            //{
            //    name: 'slideatlas',
            //    label: 'SlideAtlas',
            //    type: girder.views.SlideatlasImageViewerWidget
            //},
        ];

        this.render()
    },

    render: function () {
        this.$el.html(girder.templates.imageViewerSelectWidget({
            viewers: this.viewers
        }));
        // TODO: choose an actual default, and update the option element to match
        this._selectViewer(this.viewers[0].name);
        return this;
    },

    _selectViewer: function (viewerName) {
        if (this.currentViewer) {
            this.currentViewer.destroy();
            this.currentViewer = null;
        }
        this.$('.image-viewer').toggleClass('hidden', true);

        var viewerType = _.findWhere(this.viewers, {name: viewerName}).type;
        // GeoJs isn't always fully removing itself from its element when
        // destroyed, so use dedicated elements for each viewer for now
        var viewerEl = this.$('#' + viewerName);
        viewerEl.toggleClass('hidden', false);
        this.currentViewer = new viewerType({
            el: viewerEl,
            parentView: this,
            itemId: this.itemId
        });
    }

});
{'fraction_non_alphanumeric': 0.11862624846679516, 'fraction_numerical': 0.0003504468196951113, 'mean_word_length': 1.6340562990309184, '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': '2126641', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1540, 'n_words': 321}