<commit_before>define(['underscore', 'htmlparser', 'htmlparserToString', 'jquery'], function (_, htmlParser, toString, $) {

    'use strict';

    return {

        getWidgetsHtml: function (viewHtml, options) {
            var self = this;
            if (!_.size(this.widgets)) {
                return options.success(viewHtml);
            }

            this._parse(viewHtml, {
                success: function (list) {
                    self._addWidgetsToList(list, {
                        success: function (list) {
                            options.success(toString(list));
                        },
                        error: options.error
                    });
                },
                error: options.error
            });
        },

        attachWidgets: function (options) {
            var $descViews = this.$('[lazo-view]');
            var $widgets = this.$('[lazo-widget]');
            var self = this;

            // filter out widgets of descendent views
            $widgets.filter(function () {
                var widgetEl = this;
                return $descViews.each(function () {
                    return !$.contains(this, widgetEl);
                });
            });

            var expected = $widgets.length;
            var attached = 0;
            $widgets.each(function () {
                var $widget = $(this);
                var name = $widget.attr('lazo-widget');
                self._resolveWidget(name, {
                    success: function (Widget) {
                        var widget = new Widget(_.extend({
                            view: self },
                            self._resolveWidgetElAttrs($widget[0])));

                        widget.el = $widget[0];
                        widget.bind($widget[0]);
                        attached++;
                        self.widgets[name] = _.isArray(self.widgets[name]) ? self.widgets[name] : [];
                        self.widgets[name].push(widget);
                        if (attached === expected) {
                            options.success(true);
                        }
                    },
                    error: options.error
                });
            });
        },

        _resolveWidgetElAttrs: function (el) {
            var retVal = {};
            for (var i = 0; i < el.attributes.length; i++) {
                retVal[el.attributes[i].name] = el.attributes[i].value;<commit_msg>widget binding bug<commit_after>define(['underscore', 'htmlparser', 'htmlparserToString', 'jquery'], function (_, htmlParser, toString, $) {

    'use strict';

    return {

        getWidgetsHtml: function (viewHtml, options) {
            var self = this;
            if (!_.size(this.widgets)) {
                return options.success(viewHtml);
            }

            this._parse(viewHtml, {
                success: function (list) {
                    self._addWidgetsToList(list, {
                        success: function (list) {
                            options.success(toString(list));
                        },
                        error: options.error
                    });
                },
                error: options.error
            });
        },

        attachWidgets: function (options) {
            var $descViews = this.$('[lazo-view]');
            var $widgets = this.$('[lazo-widget]');
            var self = this;

            // filter out widgets of descendent views
            $widgets.filter(function () {
                var widgetEl = this;
                return $descViews.each(function () {
                    return !$.contains(this, widgetEl);
                });
            });

            var expected = $widgets.length;
            var attached = 0;
            if (!expected) {
                options.success(true);
            }
            $widgets.each(function () {
                var $widget = $(this);
                var name = $widget.attr('lazo-widget');
                self._resolveWidget(name, {
                    success: function (Widget) {
                        var widget = new Widget(_.extend({
                            view: self },
                            self._resolveWidgetElAttrs($widget[0])));

                        widget.el = $widget[0];
                        widget.bind($widget[0]);
                        attached++;
                        self.widgets[name] = _.isArray(self.widgets[name]) ? self.widgets[name] : [];
                        self.widgets[name].push(widget);
                        if (attached === expected) {
                            options.success(true);
                        }
                    },
                    error: options.error
                });
            });
        },

        _resolveWidgetElAttrs: function (el) {
            var retVal = {};
            for (var i = 0; i < el.attributes.length; i++) {
                retVal[el.attributes[i].name] = el.attributes[i].value;
{'fraction_non_alphanumeric': 0.11907144286571943, 'fraction_numerical': 0.0020012007204322593, 'mean_word_length': 1.111533586818758, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3596040', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1139, 'n_words': 230}