<commit_before>// TODO(joel): teach KAS how to accept an answer only if it's expressed in
// terms of a certain type.
// TODO(joel): Allow sigfigs within a range rather than an exact expected
// value?

var _ = require("underscore");
var lens = require("../../hubble/index.js");

var ApiClassNames = require("../perseus-api.jsx").ClassNames;
var ApiOptions = require("../perseus-api.jsx").Options;
var Changeable = require("../mixins/changeable.jsx");
var EditorJsonify = require("../mixins/editor-jsonify.jsx");
var NumberInput = require("../components/number-input.jsx");
var { SignificantFigures, displaySigFigs } = require("../sigfigs.jsx");

var ALL = "all";
var SOME = "some";
var MAX_SIGFIGS = 10;

var countSigfigs = function(value) {
    return new SignificantFigures(value).sigFigs;
};

var sigfigPrint = function(num, sigfigs) {
    return displaySigFigs(num, sigfigs, -MAX_SIGFIGS, false);
};

/* I just wrote this, but it's old by analogy to `OldExpression`, in that it's
 * the version that non-mathquill platforms get stuck with. Constructed with an
 * <input>, a parser, popsicle sticks, and glue.
 *
 * In the same way as OldExpression, this parses continuously as you type, then
 * shows and hides an error buddy. The error message is only shown after a
* rolling two second delay, but hidden immediately on further typing.
 */
var OldUnitInput = React.createClass({
    mixins: [Changeable],

    propTypes: {
        value: React.PropTypes.string,
    },

    getDefaultProps: function() {
        return {
            apiOptions: ApiOptions.defaults,
            value: "",
        };
    },

    // TODO(joel) think about showing the error buddy
    render: function() {
        return <div className="old-unit-input">
            <input onChange={this.handleChange}
                   ref="input"
                   className={ApiClassNames.INTERACTIVE}
                   value={this.props.value}
                   onFocus={this.handleFocus}
                   onBlur={this.handleBlur} />
            <div ref="error"
                 className="error"
                 style={{display: "none"}}>
                <$_>{"I don't understand that"}</$_>
            </div>
        </div>;
    },

    _errorTimeout: null,

    _showError: function() {
        if (this.props.value === "") {
            return;
        }

        var $error = $(this.refs.error.getDOMNode());
        if (!$error.is(":visible")) {
            $error.css({ top: 50, opacity: 0.1 }).show()
                .animate({ top: 0, opacity: 1.0 }, 300);
        }
    },

    _hideError: function() {
        var $error = $(this.refs.error.getDOMNode());
        if ($error.is(":visible")) {
            $error.animate({ top: 50, opacity: 0.1 }, 300, function() {
                $(this).hide();
            });
        }
    },
<commit_msg>Use MathOutput for the iPad app.<commit_after>// TODO(joel): teach KAS how to accept an answer only if it's expressed in
// terms of a certain type.
// TODO(joel): Allow sigfigs within a range rather than an exact expected
// value?

var _ = require("underscore");
var lens = require("../../hubble/index.js");

var ApiClassNames = require("../perseus-api.jsx").ClassNames;
var ApiOptions = require("../perseus-api.jsx").Options;
var Changeable = require("../mixins/changeable.jsx");
var EditorJsonify = require("../mixins/editor-jsonify.jsx");
var MathOutput   = require("../components/math-output.jsx");
var NumberInput = require("../components/number-input.jsx");
var { SignificantFigures, displaySigFigs } = require("../sigfigs.jsx");

var ALL = "all";
var SOME = "some";
var MAX_SIGFIGS = 10;

var countSigfigs = function(value) {
    return new SignificantFigures(value).sigFigs;
};

var sigfigPrint = function(num, sigfigs) {
    return displaySigFigs(num, sigfigs, -MAX_SIGFIGS, false);
};

/* I just wrote this, but it's old by analogy to `OldExpression`, in that it's
 * the version that non-mathquill platforms get stuck with. Constructed with an
 * <input>, a parser, popsicle sticks, and glue.
 *
 * In the same way as OldExpression, this parses continuously as you type, then
 * shows and hides an error buddy. The error message is only shown after a
* rolling two second delay, but hidden immediately on further typing.
 */
var OldUnitInput = React.createClass({
    mixins: [Changeable],

    propTypes: {
        value: React.PropTypes.string,
    },

    getDefaultProps: function() {
        return {
            apiOptions: ApiOptions.defaults,
            value: "",
        };
    },

    // TODO(joel) think about showing the error buddy
    render: function() {
        var inputType = this.props.apiOptions.staticRender ?
                MathOutput.createFactory() :
                React.DOM.input;
        var input = inputType({
            onChange: this.handleChange,
            ref: "input",
            className: ApiClassNames.INTERACTIVE,
            value: this.props.value,
            onFocus: this.handleFocus,
            onBlur: this.handleBlur,
        });

        return <div className="old-unit-input">
            {input}
            <div ref="error"
                 className="error"
                 style={{display: "none"}}>
                <$_>{"I don't understand that"}</$_>
            </div>
        </div>;
    },

    _errorTimeout: null,

    _showError: function() {
        if (this.props.value === "") {
            return;
        }

        var $error = $(this.refs.error.getDOMNode());
        if (!$error.is(":visible")) {
            $error.css({ top: 50, opacity: 0.1 }).show()
                .animate({ top: 0, opacity: 1.0 }, 300);
        }
    },

    _hideError: function() {
        var $error = $(this.refs.error.getDOMNode());
        if ($error.is(":visible")) {
            $error.animate({ top: 50, opacity: 0.1 }, 300, function() {
                $(this).hide();
            });
        }
    },

{'fraction_non_alphanumeric': 0.14138339252494503, 'fraction_numerical': 0.006426517842042956, 'mean_word_length': 2.3113101903695408, 'pattern_counts': {'":': 4, '<': 18, '<?xml version=': 0, '>': 18, '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': '6471260', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1699, 'n_words': 484}