<commit_before>/*global zeit,Backbone,window,document*/
(function() {
    "use strict";

    var $ = window.jQuery;
    var _ = window.Underscore;

    zeit.cms.declare_namespace('zeit.content.image');
    zeit.cms.declare_namespace('zeit.content.image.browser');


    /* MODELS */

    zeit.content.image.Variant = Backbone.Model.extend({
        urlRoot: window.context_url + '/variants',

        make_url: function() {
            var self = this,
                url = self.get('url');
            return url + '?nocache=' + new Date().getTime();
        }
    });


    zeit.content.image.VariantList = Backbone.Collection.extend({

        model: zeit.content.image.Variant,
        url: window.context_url + '/variants'

    });


    zeit.content.image.VARIANTS = new zeit.content.image.VariantList();


    /* VIEWS */

    zeit.content.image.browser.Variant = Backbone.View.extend({

        img_css_class: 'preview',

        initialize: function(options) {
            this.index = options.index;
        },

        render: function() {
            var self = this;
            var content = $(_.template('<img class="{{css}}"/>')({
                    css: self.img_css_class}));

            content.on('load', function() {
                self.trigger('render');
            });

            content.attr('src', self.model.make_url());
            content.attr('width', 75 * (self.index + 2) + 'px');
            self.$el.replaceWith(content);
            self.setElement(content);

            if (self.model.has('css')) {
                self.$el.removeClass('preview');
                self.$el.addClass(self.model.get('css'));
            }

            if (self.model.has('width')) {
                self.$el.width(self.model.get('width'));
            }

            return self;
        },

        update_image: function() {
            this.$el.attr('src', this.model.make_url());
        }
    });


    zeit.content.image.browser.VariantList = Backbone.View.extend({

        el: '#variant-preview',

        initialize: function() {
            this.listenTo(zeit.content.image.VARIANTS, 'reset', this.reset);
            this.listenTo(zeit.content.image.VARIANTS, 'reload', this.reload);
            this.model_views = [];
        },

        reset: function() {
            var self = this;
            self.$el.empty();
            $(zeit.content.image.VARIANTS.models).each(function(index, variant) {
                var view = new zeit.content.image.browser.Variant(
                    {model: variant, index: index}<commit_msg>re DEV-781: Set width of preview images to max-size of XML config to display smaller images in their original size.<commit_after>/*global zeit,Backbone,window,document*/
(function() {
    "use strict";

    var $ = window.jQuery;
    var _ = window.Underscore;

    zeit.cms.declare_namespace('zeit.content.image');
    zeit.cms.declare_namespace('zeit.content.image.browser');


    /* MODELS */

    zeit.content.image.Variant = Backbone.Model.extend({
        urlRoot: window.context_url + '/variants',

        make_url: function() {
            var self = this,
                url = self.get('url');
            return url + '?nocache=' + new Date().getTime();
        }
    });


    zeit.content.image.VariantList = Backbone.Collection.extend({

        model: zeit.content.image.Variant,
        url: window.context_url + '/variants'

    });


    zeit.content.image.VARIANTS = new zeit.content.image.VariantList();


    /* VIEWS */

    zeit.content.image.browser.Variant = Backbone.View.extend({

        img_css_class: 'preview',

        render: function() {
            var self = this;
            var content = $(_.template('<img class="{{css}}"/>')({
                    css: self.img_css_class}));

            content.on('load', function() {
                self.trigger('render');
            });

            content.attr('src', self.model.make_url());
            self.$el.replaceWith(content);
            self.setElement(content);

            if (self.model.has('css')) {
                self.$el.removeClass('preview');
                self.$el.addClass(self.model.get('css'));
            }

            if (self.model.has('width')) {
                self.$el.width(self.model.get('width'));
            }

            if (self.model.has('max-size')) {
                var size = self.model.get('max-size').split('x');
                self.$el.width(size[0]);
            }

            return self;
        },

        update_image: function() {
            this.$el.attr('src', this.model.make_url());
        }
    });


    zeit.content.image.browser.VariantList = Backbone.View.extend({

        el: '#variant-preview',

        initialize: function() {
            this.listenTo(zeit.content.image.VARIANTS, 'reset', this.reset);
            this.listenTo(zeit.content.image.VARIANTS, 'reload', this.reload);
            this.model_views = [];
        },

        reset: function() {
            var self = this;
            self.$el.empty();
            $(zeit.content.image.VARIANTS.models).each(function(index, variant) {
                var view = new zeit.content.image.browser.Variant(
                    {model: variant}
{'fraction_non_alphanumeric': 0.15381672087239334, 'fraction_numerical': 0.001339200306102927, 'mean_word_length': 1.8413043478260869, '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': '1456099', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1461, 'n_words': 239}