<commit_before>var compose = (function () {

var exports = {};
var is_composing_message = false;
var focused_recipient;
var message_snapshot;
var empty_subject_placeholder = "(no topic)";

// This function resets an input type="file".  Pass in the
// jquery object.
function clear_out_file_list(jq_file_list) {
    var clone_for_ie_sake = jq_file_list.clone(true);
    jq_file_list.replaceWith(clone_for_ie_sake);

    // Hack explanation:
    // IE won't let you do this (untested, but so says StackOverflow):
    //    $("#file_input").val("");
}

// Show the compose box.
function show_box(tabname, focus_area) {
    if (tabname === "stream") {
        $('#private-message').hide();
        $('#stream-message').show();
        $("#stream_toggle").addClass("active");
        $("#private_message_toggle").removeClass("active");
    } else {
        $('#private-message').show();
        $('#stream-message').hide();
        $("#stream_toggle").removeClass("active");
        $("#private_message_toggle").addClass("active");
    }
    $("#send-status").removeClass(status_classes).hide();
    $('#compose').css({visibility: "visible"});
    $("#new_message_content").trigger("autosize");
    $(".new_message_textarea").css("min-height", "3em");

    if (focus_area !== undefined) {
        focus_area.focus().select();
    }

    // If the compose box is obscuring the currently selected message,
    // scroll up until the message is no longer occluded.
    if (current_msg_list.selected_id() === -1) {
        // If there's no selected message, there's no need to
        // scroll the compose box to avoid it.
        return;
    }
    var selected_row = current_msg_list.selected_row();
    var cover = selected_row.offset().top + selected_row.height()
        - $("#compose").offset().top;
    if (cover > 0) {
        viewport.user_initiated_animate_scroll(cover+5);
    }

    // Disable the notifications bar if it overlaps with the composebox
    notifications_bar.maybe_disable();
}

function clear_box() {
    exports.snapshot_message();
    $("#compose").find('input[type=text], textarea').val('');
    $("#new_message_content").trigger('autosize');
    $("#send-status").hide(0);
}

function hide_box() {
    $('.message_comp').find('input, textarea, button').blur();
    $('#stream-message').hide();
    $('#private-message').hide();
    $(".new_message_textarea").css("min-height", "");
    notifications_bar.enable();
    exports.unfade_messages(true);
    $('.message_comp').hide();
    $("#compose_controls").show();
}

function update_lock_icon_for_stream(stream_name) {
    var icon = $("#compose-lock-icon");
    if (subs.get_invite_only(stream_name)) {
        icon.show();
    } else {
        icon.hide();
    }
}

// In an attempt to decrease mixing, make the composebox's
// stream bar look like what you're replying to.
// (In particular, if there's a color associated with it,
//  have that color be reflected here too.)
exports.decorate_stream_bar = function (stream_name) {
    var color = subs.get_color(stream_name);
    update_lock_icon_for_stream(stream_name);
    $("#stream-message .message_header_stream")
        .css('background-color', color)
        .removeClass(stream_color.color_classes)
        .addClass(stream_color.get_color_class(color));
};

exports.unfade_messages = function (clear_state) {
    if (focused_recipient === undefined) {
        return;
    }

    rows.get_table(current_msg_list.table_name).find(".recipient_row, .message_row")
                                               .removeClass("faded").addClass("unfaded");
    if (clear_state === true) {
        focused_recipient = undefined;
    }
    ui.update_floating_recipient_bar();
};

exports.update_faded_messages = function () {
    if (focused_recipient === undefined) {
        return;
    }

    if ((focused_recipient.type === "stream" && focused_recipient.subject === "") ||
        (focused_recipient.type === "private" && focused_recipient.reply_to === "")) {
        exports.unfade_messages();
        return;
    }

    var i;
    var all_elts = rows.get_table(current_msg_list.table_name).find(".recipient_row, .message_row");
    var should_fade_message = false;
    // Note: The below algorithm relies on the fact that all_elts is
    // sorted as it would be displayed in the message view
    for (i = 0; i < all_elts.length; i++) {
        var elt = $(all_elts[i]);
        if (elt.hasClass("recipient_row")) {
            should_fade_message = !util.same_recipient(focused_recipient, current_msg_list.get(rows.id(elt)));
        }

        if (should_fade_message) {
            elt.removeClass("unfaded").addClass("faded");
        } else {
            elt.removeClass("faded").addClass("unfaded");
        }<commit_msg>Add hasClass() optimization for fading.<commit_after>var compose = (function () {

var exports = {};
var is_composing_message = false;
var focused_recipient;
var message_snapshot;
var empty_subject_placeholder = "(no topic)";

// This function resets an input type="file".  Pass in the
// jquery object.
function clear_out_file_list(jq_file_list) {
    var clone_for_ie_sake = jq_file_list.clone(true);
    jq_file_list.replaceWith(clone_for_ie_sake);

    // Hack explanation:
    // IE won't let you do this (untested, but so says StackOverflow):
    //    $("#file_input").val("");
}

// Show the compose box.
function show_box(tabname, focus_area) {
    if (tabname === "stream") {
        $('#private-message').hide();
        $('#stream-message').show();
        $("#stream_toggle").addClass("active");
        $("#private_message_toggle").removeClass("active");
    } else {
        $('#private-message').show();
        $('#stream-message').hide();
        $("#stream_toggle").removeClass("active");
        $("#private_message_toggle").addClass("active");
    }
    $("#send-status").removeClass(status_classes).hide();
    $('#compose').css({visibility: "visible"});
    $("#new_message_content").trigger("autosize");
    $(".new_message_textarea").css("min-height", "3em");

    if (focus_area !== undefined) {
        focus_area.focus().select();
    }

    // If the compose box is obscuring the currently selected message,
    // scroll up until the message is no longer occluded.
    if (current_msg_list.selected_id() === -1) {
        // If there's no selected message, there's no need to
        // scroll the compose box to avoid it.
        return;
    }
    var selected_row = current_msg_list.selected_row();
    var cover = selected_row.offset().top + selected_row.height()
        - $("#compose").offset().top;
    if (cover > 0) {
        viewport.user_initiated_animate_scroll(cover+5);
    }

    // Disable the notifications bar if it overlaps with the composebox
    notifications_bar.maybe_disable();
}

function clear_box() {
    exports.snapshot_message();
    $("#compose").find('input[type=text], textarea').val('');
    $("#new_message_content").trigger('autosize');
    $("#send-status").hide(0);
}

function hide_box() {
    $('.message_comp').find('input, textarea, button').blur();
    $('#stream-message').hide();
    $('#private-message').hide();
    $(".new_message_textarea").css("min-height", "");
    notifications_bar.enable();
    exports.unfade_messages(true);
    $('.message_comp').hide();
    $("#compose_controls").show();
}

function update_lock_icon_for_stream(stream_name) {
    var icon = $("#compose-lock-icon");
    if (subs.get_invite_only(stream_name)) {
        icon.show();
    } else {
        icon.hide();
    }
}

// In an attempt to decrease mixing, make the composebox's
// stream bar look like what you're replying to.
// (In particular, if there's a color associated with it,
//  have that color be reflected here too.)
exports.decorate_stream_bar = function (stream_name) {
    var color = subs.get_color(stream_name);
    update_lock_icon_for_stream(stream_name);
    $("#stream-message .message_header_stream")
        .css('background-color', color)
        .removeClass(stream_color.color_classes)
        .addClass(stream_color.get_color_class(color));
};

exports.unfade_messages = function (clear_state) {
    if (focused_recipient === undefined) {
        return;
    }

    rows.get_table(current_msg_list.table_name).find(".recipient_row, .message_row")
                                               .removeClass("faded").addClass("unfaded");
    if (clear_state === true) {
        focused_recipient = undefined;
    }
    ui.update_floating_recipient_bar();
};

exports.update_faded_messages = function () {
    if (focused_recipient === undefined) {
        return;
    }

    if ((focused_recipient.type === "stream" && focused_recipient.subject === "") ||
        (focused_recipient.type === "private" && focused_recipient.reply_to === "")) {
        exports.unfade_messages();
        return;
    }

    var i;
    var all_elts = rows.get_table(current_msg_list.table_name).find(".recipient_row, .message_row");
    var should_fade_message = false;
    // Note: The below algorithm relies on the fact that all_elts is
    // sorted as it would be displayed in the message view
    for (i = 0; i < all_elts.length; i++) {
        var elt = $(all_elts[i]);
        if (elt.hasClass("recipient_row")) {
            should_fade_message = !util.same_recipient(focused_recipient, current_msg_list.get(rows.id(elt)));
        }

        // Usually we are not actually switching up the classes here, so the hasClass()
        // calls here will usually short circuit two function calls that are more expensive.
        // So, while the hasClass() checks are semantically unnecessary, they should improve
        // performance.  See trac #1633 for more context.
        if (should_fade_message) {
            if (!elt.hasClass("faded")) {
                elt.removeClass("unfaded").addClass("faded");
            }
        } else {
            if (!elt.hasClass("unfaded")) {
                elt.removeClass("faded").addClass("unfaded");
            }
        }
{'fraction_non_alphanumeric': 0.1528, 'fraction_numerical': 0.0016, 'mean_word_length': 3.1394867549668874, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7208547', 'n_tokens_mistral': 3065, 'n_tokens_neox': 2988, 'n_words': 638}