<commit_before>(function(Perseus) {

var SingleEditor = Perseus.SingleEditor = Perseus.Widget.extend({
    className: "perseus-single-editor",

    options: {
        content: ""
    },

    render: function() {
        var editor = this;

        this.$el.empty();

        var $textarea = this.$textarea = $("<textarea>").val(
                this.options.content);
        $textarea.on("input", function() {
            editor.options.content = $textarea.val();
            editor.trigger("change");
        });

        this.$el.append($textarea);

        return $.when(this);
    },

    set: function(options) {
        // Extend with default options specified above...
        // TODO(alpert): Should textarea val get set here? Not sure.
        this.options = _.defaults(options, this.constructor.prototype.options);
        if (!options.silent) {
            this.trigger("change");
        }
        return this;
    },

    focus: function() {
        this.$textarea.focus();
        return this;
    }
});

var QuestionEditor = Perseus.SingleEditor.extend({
    className: Perseus.SingleEditor.prototype.className +
            " perseus-question-editor"
});

var HintEditor = Perseus.SingleEditor.extend({
    className: Perseus.SingleEditor.prototype.className +
            " perseus-hint-editor",

    render: function() {
        var editor = this;

        this.$el.empty();

        var $removeHintDiv = this.$removeHintDiv = $("<div " +
            "class='remove-hint-container'>");
        var $removeHintButton = this.$removeHintButton = $("<a href='#' " +
            "class='simple-button orange icon-trash remove-hint-button'" +
            "alt='Remove this Hint'>");
        // Leading space because of FontAwesome icon.
        $removeHintButton.text(" Remove this hint");
        $removeHintButton.on("click", function() {
            editor.trigger("remove");
            return false;
        });
        $removeHintDiv.append($removeHintButton);

        var $textarea = this.$textarea = $("<textarea>").val(
                this.options.content);
        $textarea.on("input", function() {
            editor.options.content = $textarea.val();
            editor.trigger("change");
        });

        this.$el.append($textarea);
        this.$el.append($removeHintDiv);

        return $.when(this);
    }

    // TODO(alpert): Remove a hint
});

var AnswerAreaEditor = Perseus.Widget.extend({
    className: "perseus-answer-editor",

    options: {
        // TODO(alpert): Separate into validatey things
        type: "input-number"
    },

    initialize: function() {
        var cls = Perseus.Widgets._widgetTypes[this.options.type + "-editor"];
        // TODO(alpert): Ugh, too many things called editor
        this.editor = new cls();<commit_msg>Autoresize text areas for enhanced usability<commit_after>(function(Perseus) {

var _resizeTextarea = function($el) {
    $el.height(24);
    $el.height($el.prop("scrollHeight") + 12);
};

var SingleEditor = Perseus.SingleEditor = Perseus.Widget.extend({
    className: "perseus-single-editor",

    options: {
        content: ""
    },

    render: function() {
        var editor = this;

        this.$el.empty();

        var $textarea = this.$textarea = $("<textarea>").val(
                this.options.content);
        $textarea.on("input", function() {
            editor.options.content = $textarea.val();
            editor.trigger("change");
            _resizeTextarea($textarea);
        });

        this.$el.append($textarea);
        _resizeTextarea($textarea);

        return $.when(this);
    },

    set: function(options) {
        // Extend with default options specified above...
        // TODO(alpert): Should textarea val get set here? Not sure.
        this.options = _.defaults(options, this.constructor.prototype.options);
        if (!options.silent) {
            this.trigger("change");
        }
        return this;
    },

    focus: function() {
        this.$textarea.focus();
        return this;
    }
});

var QuestionEditor = Perseus.SingleEditor.extend({
    className: Perseus.SingleEditor.prototype.className +
            " perseus-question-editor"
});

var HintEditor = Perseus.SingleEditor.extend({
    className: Perseus.SingleEditor.prototype.className +
            " perseus-hint-editor",

    render: function() {
        var editor = this;

        this.$el.empty();

        var $removeHintDiv = this.$removeHintDiv = $("<div " +
            "class='remove-hint-container'>");
        var $removeHintButton = this.$removeHintButton = $("<a href='#' " +
            "class='simple-button orange icon-trash remove-hint-button'" +
            "alt='Remove this Hint'>");
        // Leading space because of FontAwesome icon.
        $removeHintButton.text(" Remove this hint");
        $removeHintButton.on("click", function() {
            editor.trigger("remove");
            return false;
        });
        $removeHintDiv.append($removeHintButton);

        var $textarea = this.$textarea = $("<textarea>").val(
                this.options.content);
        $textarea.on("input", function() {
            editor.options.content = $textarea.val();
            editor.trigger("change");
            _resizeTextarea($textarea);
        });

        this.$el.append($textarea);
        this.$el.append($removeHintDiv);
        _resizeTextarea($textarea);

        return $.when(this);
    }

    // TODO(alpert): Remove a hint
});

var AnswerAreaEditor = Perseus.Widget.extend({
    className: "perseus-answer-editor",

    options: {
        // TODO(alpert): Separate into validatey things
        type: "input-number"
    },

    initialize: function() {
        var cls = Perseus.Widgets._widgetTypes[this.options.type + "-editor"];
        // TODO(alpert): Ugh, too many things called editor
        this.editor = new cls();
{'fraction_non_alphanumeric': 0.14601769911504425, 'fraction_numerical': 0.0006807351940095302, 'mean_word_length': 2.2362334801762116, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '174594', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1604, 'n_words': 326}