<commit_before>/**
 * User: <NAME>
 * Date: 13.08.13
 * Time: 18:30
 *
 * Extension to backbone_forms
 */

require(["jquery", "underscore", "backbone", "backbone_forms"],function ($, _, Backbone, BackboneForm) {
    var self = this.Tornado || {};
    var Tornado = this.Tornado = self;

    Tornado.BackboneForm = function (element, options) {
        this.$element = $(element);
        this.options = $.extend({}, Tornado.BackboneForm.DEFAULTS, options);

        if (this.options.model) {
            if (typeof this.options.model == "string") {
                this.model = this.options.model = new window[this.options.model]();
            } else {
                this.model = this.options.model;
            }
        }

        this.form = new Backbone.Form(this.options);
    };
    Tornado.BackboneForm.DEFAULTS = {};

    /**
     * (re)render the form
     *
     * Based on backbone-forms.js/render by <NAME>
     */
    Tornado.BackboneForm.prototype.render = function () {
        var self = this.form,
            $form = this.$element,
            fields = this.form.fields;

        //Render standalone editors
        $form.find('[data-editors]').add($form).each(function (i, el) {
            var $container = $(el),
                selection = $container.data('editors');

            if (_.isUndefined(selection)) {
                return;
            }

            //Work out which fields to include
            var keys = (selection == '*')
                ? self.selectedFields || _.keys(fields)
                : selection.split(',');

            //Add them
            _.each(keys, function (key) {
                var field = fields[key];

                $container.append(field.editor.render().el);
            });

            $container.removeAttr('data-editors');
        });

        //Render standalone fields
        $form.find('[data-fields]').add($form).each(function (i, el) {
            var $container = $(el),
                selection = $container.data('fields');

            if (_.isUndefined(selection)) {
                return;
            }

            //Work out which fields to include
            var keys = (selection == '*')
                ? self.selectedFields || _.keys(fields)
                : selection.split(',');

            //Add them
            _.each(keys, function (key) {
                var field = fields[key];

                field.schema = field.schema || {};
                field.schema = _.extend(field.schema, $container.data("schema"));

                var $el = $container.append(field.render().el);

                // Update editor Attrs
                field.schema.editorAttrs = field.schema.editorAttrs || {};
                field.schema.editorAttrs = _.extend(field.schema.editorAttrs, $container.data("editorAttrs"));
                $el.find("[data-editor] input").attr(field.schema.editorAttrs);

            });

            $container.removeAttr('data-fields');
        });

        //Render fieldsets
        $form.find('[data-fieldsets]').add($form).each(function (i, el) {
            var $container = $(el),
                selection = $container.data('fieldsets');

            if (_.isUndefined(selection)) return;

            _.each(self.fieldsets, function (fieldset) {
                $container.append(fieldset.render().el);
            });

            $container.removeAttr('data-fieldsets');
        });

        //Set the main element
        self.setElement($form);

        //Set class
        $form.addClass(self.className);

        return self;
    };

    /**
     * Allows to facility html elements with backbone-forms or model functionality
     *
     * @param option
     */
    $.fn.backbone = function (option) {
        return this.each(function () {
            var $this = $(this);
            var data = $this.data('tb.backbone');

            var options = typeof option == 'object' && option;<commit_msg>Support webshim lib<commit_after>/**
 * User: <NAME>
 * Date: 13.08.13
 * Time: 18:30
 *
 * Extension to backbone_forms
 */

require(["jquery", "underscore", "backbone", "backbone_forms"],function ($, _, Backbone, BackboneForm) {
    var self = this.Tornado || {};
    var Tornado = this.Tornado = self;

    Tornado.BackboneForm = function (element, options) {
        this.$element = $(element);
        this.options = $.extend({}, Tornado.BackboneForm.DEFAULTS, options);

        if (this.options.model) {
            if (typeof this.options.model == "string") {
                this.model = this.options.model = new window[this.options.model]();
            } else {
                this.model = this.options.model;
            }
        }

        this.form = new Backbone.Form(this.options);
    };
    Tornado.BackboneForm.DEFAULTS = {};

    /**
     * (re)render the form
     *
     * Based on backbone-forms.js/render by <NAME>
     */
    Tornado.BackboneForm.prototype.render = function () {
        var self = this.form,
            $form = this.$element,
            fields = this.form.fields;

        //Render standalone editors
        $form.find('[data-editors]').add($form).each(function (i, el) {
            var $container = $(el),
                selection = $container.data('editors');

            if (_.isUndefined(selection)) {
                return;
            }

            //Work out which fields to include
            var keys = (selection == '*')
                ? self.selectedFields || _.keys(fields)
                : selection.split(',');

            //Add them
            _.each(keys, function (key) {
                var field = fields[key];

                var $el, el = field.editor.render().el;
                if ($.webshims) {
                    $el = $container.appendPolyfill(el);
                } else {
                    $el = $container.append(el);
                }
            });

            $container.removeAttr('data-editors');
        });

        //Render standalone fields
        $form.find('[data-fields]').add($form).each(function (i, el) {
            var $container = $(el),
                selection = $container.data('fields');

            if (_.isUndefined(selection)) {
                return;
            }

            //Work out which fields to include
            var keys = (selection == '*')
                ? self.selectedFields || _.keys(fields)
                : selection.split(',');

            //Add them
            _.each(keys, function (key) {
                var field = fields[key];

                field.schema = field.schema || {};
                field.schema = _.extend(field.schema, $container.data("schema"));

                var $el, el = field.render().el;
                if ($.webshims) {
                    $el = $container.appendPolyfill(el);
                } else {
                    $el = $container.append(el);
                }

                // Update editor Attrs
                field.schema.editorAttrs = field.schema.editorAttrs || {};
                field.schema.editorAttrs = _.extend(field.schema.editorAttrs, $container.data("editorAttrs"));
                $el.find("[data-editor] input").attr(field.schema.editorAttrs);

            });

            $container.removeAttr('data-fields');
        });

        //Render fieldsets
        $form.find('[data-fieldsets]').add($form).each(function (i, el) {
            var $container = $(el),
                selection = $container.data('fieldsets');

            if (_.isUndefined(selection)) return;

            _.each(self.fieldsets, function (fieldset) {

                var $el, el = fieldset.render().el;
                if ($.webshims) {
                    $el = $container.appendPolyfill(el);
                } else {
                    $el = $container.append(el);
                }

                // Update editor Attrs
                fieldset.schema.editorAttrs = fieldset.schema.editorAttrs || {};
                fieldset.schema.editorAttrs = _.extend(fieldset.schema.editorAttrs, $container.data("editorAttrs"));
                $el.find("[data-editor] input").attr(fieldset.schema.editorAttrs);
            });

            $container.removeAttr('data-fieldsets');
        });

        //Set the main element
        self.setElement($form);

        //Set class
        $form.addClass(self.className);

        return self;
    };

    /**
     * Allows to facility html elements with backbone-forms or model functionality
     *
     * @param option
     */
    $.fn.backbone = function (option) {
        return this.each(function () {
            var $this = $(this);
            var data = $this.data('tb.backbone');

            var options = typeof option == 'object' && option;
{'fraction_non_alphanumeric': 0.14315209910529939, 'fraction_numerical': 0.0022941041523285156, 'mean_word_length': 1.6112608565438755, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4987395', 'n_tokens_mistral': 2456, 'n_tokens_neox': 2308, 'n_words': 465}