<commit_before>/*global define*/
/**
 * To load this extension, add the following to your custom.js:
 *
 * IPython.load_extensions('nbgrader');
 *
**/

define([
    'require',
    'jquery',
    'base/js/namespace',
    'notebook/js/celltoolbar',

], function (require, $, IPython, celltoolbar) {
    "use strict";

    var CellToolbar = celltoolbar.CellToolbar;

    /**
     * Is the cell a solution cell?
     */
    var is_solution = function (cell) {
        if (cell.metadata.nbgrader === undefined) {
            cell.metadata.nbgrader = {};
            return false;
        } else if (cell.metadata.nbgrader.solution === undefined) {
            return false;
        } else {
            return cell.metadata.nbgrader.solution;
        }
    };

    /**
     * Is the cell a grade cell?
     */
    var is_grade = function (cell) {
        if (cell.metadata.nbgrader === undefined) {
            cell.metadata.nbgrader = {};
            return false;
        } else if (cell.metadata.nbgrader.grade === undefined) {
            return false;
        } else {
            return cell.metadata.nbgrader.grade;
        }
    };

    /**
     * Add a display class to the cell element, depending on the
     * nbgrader cell type.
     */
    var display_cell = function (cell) {
        var grader = is_grade(cell),
            grade_cls = "nbgrader-grade-cell",
            elem = cell.element;

        if (!elem) {
            return;
        }

        if (grader && !elem.hasClass(grade_cls)) {
            elem.addClass(grade_cls);
        } else if (!grader && elem.hasClass(grade_cls)) {
            elem.removeClass(grade_cls);
        }
    };

    /**
     * Create a checkbox to mark whether the cell is a grader cell or
     * not.
     */
    var create_grader_checkbox = function (div, cell, celltoolbar) {
        var chkb = $('<input/>').attr('type', 'checkbox');
        var lbl = $('<label/>').append($('<span/>').text("Grade? "));
        lbl.append(chkb);
        chkb.attr("checked", is_grade(cell));
        chkb.click(function () {
            cell.metadata.nbgrader.grade = !is_grade(cell);
            celltoolbar.rebuild();
            display_cell(cell);
        });
        display_cell(cell);
        $(div).append($('<span/>').append(lbl));
    };

    /**<commit_msg>Hide nbgrader css when toolbars are rebuilt/hidden<commit_after>/*global define*/
/**
 * To load this extension, add the following to your custom.js:
 *
 * IPython.load_extensions('nbgrader');
 *
**/

define([
    'require',
    'jquery',
    'base/js/namespace',
    'notebook/js/celltoolbar',
    'base/js/events'

], function (require, $, IPython, celltoolbar, events) {
    "use strict";

    var grade_cls = "nbgrader-grade-cell";
    var CellToolbar = celltoolbar.CellToolbar;

    // trigger an event when the toolbar is being rebuilt
    CellToolbar.prototype._rebuild = CellToolbar.prototype.rebuild;
    CellToolbar.prototype.rebuild = function () {
        events.trigger('toolbar_rebuild.CellToolbar', this.cell);
        this._rebuild();
    };

    // trigger an event when the toolbar is being (globally) hidden
    CellToolbar._global_hide = CellToolbar.global_hide;
    CellToolbar.global_hide = function () {
        CellToolbar._global_hide();
        for (var i=0; i < CellToolbar._instances.length; i++) {
            events.trigger('global_hide.CellToolbar', CellToolbar._instances[i].cell);
        }
    };

    // remove nbgrader class when the cell is either hidden or rebuilt
    events.on("global_hide.CellToolbar toolbar_rebuild.CellToolbar", function (evt, cell) {
        if (cell.element && cell.element.hasClass(grade_cls)) {
            cell.element.removeClass(grade_cls);
        }
    });

    /**
     * Is the cell a solution cell?
     */
    var is_solution = function (cell) {
        if (cell.metadata.nbgrader === undefined) {
            cell.metadata.nbgrader = {};
            return false;
        } else if (cell.metadata.nbgrader.solution === undefined) {
            return false;
        } else {
            return cell.metadata.nbgrader.solution;
        }
    };

    /**
     * Is the cell a grade cell?
     */
    var is_grade = function (cell) {
        if (cell.metadata.nbgrader === undefined) {
            cell.metadata.nbgrader = {};
            return false;
        } else if (cell.metadata.nbgrader.grade === undefined) {
            return false;
        } else {
            return cell.metadata.nbgrader.grade;
        }
    };

    /**
     * Add a display class to the cell element, depending on the
     * nbgrader cell type.
     */
    var display_cell = function (cell) {
        if (cell.element && is_grade(cell) && !cell.element.hasClass(grade_cls)) {
            cell.element.addClass(grade_cls);
        }
    };

    /**
     * Create a checkbox to mark whether the cell is a grader cell or
     * not.
     */
    var create_grader_checkbox = function (div, cell, celltoolbar) {
        var chkb = $('<input/>').attr('type', 'checkbox');
        var lbl = $('<label/>').append($('<span/>').text("Grade? "));
        lbl.append(chkb);
        chkb.attr("checked", is_grade(cell));
        chkb.click(function () {
            cell.metadata.nbgrader.grade = !is_grade(cell);
            celltoolbar.rebuild();
            display_cell(cell);
        });
        display_cell(cell);
        $(div).append($('<span/>').append(lbl));
    };

    /**
{'fraction_non_alphanumeric': 0.13956914012152458, 'fraction_numerical': 0.00018412815319462345, 'mean_word_length': 2.0898748577929465, 'pattern_counts': {'":': 0, '<': 12, '<?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': '888774', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1610, 'n_words': 358}