{"size": 1508, "ext": "js", "max_stars_repo_path": "src/georgezhang/public/js/count.js", "max_stars_repo_name": "mainnote/mainnoteJS", "max_stars_repo_stars_event_min_datetime": "2017-04-19T02:34:34.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-19T02:34:34.000Z", "max_issues_repo_path": "src/georgezhang/public/js/count.js", "max_issues_repo_name": "mainnote/groupComponentJS", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/georgezhang/public/js/count.js", "max_forks_repo_name": "mainnote/groupComponentJS", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.16, "max_line_length": 73, "alphanum_fraction": 0.4270557029}
define(['jquery', 'component', 'tpl!templates/count'
	], function ($, Component, tpl) {
    var Count = Component.create('Count');
    Count.extend({
        tpl: tpl,
        setup: function (opt) {
            var that = this;
            this.watchComp.on('input', function (e) {
                e.preventDefault();
                e.stopPropagation();
                var val = $(this).val();
                var opt_ = {
                    val: val,
                };
                that.count(opt_);
            });
            return this.comp;
        },

        render: function (opt) {
            var showTpl = $(this.template());
            opt.comp.after(showTpl);
            this.comp = showTpl;
            this.watchComp = opt.comp;
            this.maxCount = opt.maxCount;
            return this.setup();
        },

        count: function (opt) {
            var count = opt.val.length;
            if (this.maxCount) {
                var remaining = this.maxCount - count;
                if (remaining < 0) {
                    this.overMaxCount(opt);
                } else {
                    this.comp.text(remaining + ' characters remaining');
                }
            } else {
                this.comp.text(count + ' characters totally');
            }
        },

        overMaxCount: function (opt) {
            this.watchComp.val(opt.val.substring(0, this.maxCount));
        },
    });

    return Count;
});
