<commit_before>define(['jquery'], function($) {

    // Constructor 
    var CardTemplatePreview = function(options) {
        this.selectEl = $(options.selectEl); // the <select> element
        this.previewEl = $(options.previewEl); // the <div> element that will hold the preview
        this.url = this.previewEl.data('fetch-url'); // url to fetch preview
        this.defaultText = this.previewEl.html(); // default text to display
        this.cache = {}; // cache for the template previews to minimize network traffic
    };

    // Initializes the listeners
    CardTemplatePreview.prototype.init = function() {
        var that = this;
        this.selectEl.on("change", function() {
            var card_template_id = $(this).find(":selected").val();
            if(card_template_id) {
                that.load(card_template_id);
            } else {
                that.reset();
            }
        });
    };

    // Updates the preview 
    CardTemplatePreview.prototype.update = function(html) {
        this.previewEl.html(html);
    };

    // Resets the preview to the default text
    CardTemplatePreview.prototype.reset = function() {
        this.update(this.defaultText);
    };

    // Loads the preview for the given card template ID
    CardTemplatePreview.prototype.load = function(cardTemplateId) {
        var that = this;
        if(this.cache[cardTemplateId]) {
            this.update(this.cache[cardTemplateId]);
        } else {
            $.ajax({
                url: this.url,
                data: { "card_template_id": cardTemplateId },
                dataType: 'html',
                success: function(data) {
                    that.cache[cardTemplateId] = data;
                    that.update.call(that, data);
                }
            });
        }
    };

    return CardTemplatePreview;
});
<commit_msg>refactored card template preview<commit_after>define(['jquery'], function($) {

    // Constructor 
    var CardTemplatePreview = function(options) {
        this.selectEl = $(options.selectEl); // the <select> element
        this.previewEl = $(options.previewEl); // the <div> element that will hold the preview
        this.url = this.previewEl.data('fetch-url'); // url to fetch preview
        this.defaultText = this.previewEl.html(); // default text to display
        this.cache = {}; // cache for the template previews to minimize network traffic
    };

    // Initializes the listeners
    CardTemplatePreview.prototype.init = function() {
		this.onSelect = $.proxy(this.onSelect, this); // bind context 
        this.selectEl.on("change", this.onSelect);
    };

	// Handles the select element change event.
	CardTemplatePreview.prototype.onSelect = function() {
		var card_template_id = this.selectEl.find(":selected").val();
		this.select(card_template_id);
	};

	// Selects the template to show.
	CardTemplatePreview.prototype.select = function(cardTemplateId) {
		if(cardTemplateId) {
			this.load(cardTemplateId);
		} else {
			this.reset();
		}
	};

    // Updates the preview 
    CardTemplatePreview.prototype.update = function(html) {
        this.previewEl.html(html);
    };

    // Resets the preview to the default text
    CardTemplatePreview.prototype.reset = function() {
        this.update(this.defaultText);
    };

    // Loads the preview for the given card template ID
    CardTemplatePreview.prototype.load = function(cardTemplateId) {
        var that = this;
        if(this.cache[cardTemplateId]) {
            this.update(this.cache[cardTemplateId]);
        } else {
            $.ajax({
                url: this.url,
                data: { "card_template_id": cardTemplateId },
                dataType: 'html',
                success: function(data) {
                    that.cache[cardTemplateId] = data;
                    that.update.call(that, data);
                }
            });
        }
    };

    return CardTemplatePreview;
});

{'fraction_non_alphanumeric': 0.12, 'fraction_numerical': 0.0, 'mean_word_length': 2.145700636942675, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, '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': '6954952', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1039, 'n_words': 239}