<commit_before>﻿/* global angular:false */

(function () {

    "use strict";

    angular.module('jsnbt')
        .directive('ctrlHtml', ['$rootScope', '$timeout', '$q', 'CONTROL_EVENTS', function ($rootScope, $timeout, $q, CONTROL_EVENTS) {

            var HtmlControl = function (scope, element, attrs) {
                jsnbt.controls.FormControlBase.apply(this, $rootScope.getBaseArguments(scope, element, attrs));

                var self = this;

                element.addClass('ctrl');
                element.addClass('ctrl-html');

                scope.enabled = true;

                var editorId = 'editor_' + scope.id;

                $timeout(function () {
                    var $editor = $('#' + editorId);

                    var updating = false;

                    var opts = {
                        buttons: ['formatting', 'bold', 'italic', 'deleted',
                            'unorderedlist', 'orderedlist', 'outdent', 'indent',
                            'image', 'file', 'link', 'alignment', 'horizontalrule']
                    };

                    var options = {
                        minHeight: scope.ngHeight,
                        maxHeight: scope.ngMaxHeight || scope.ngHeight,
                        buttons: scope.ngToolbar
                    };

                    $.extend(opts, options, {
                        changeCallback: function () {
                            if (!updating) {
                                scope.ngModel = this.code.get();
                                scope.changed();
                            }
                        }
                    })

                    $editor.redactor(opts);
                    
                    scope.$watch('ngDisabled', function (newValue) {
                        scope.enabled = newValue !== undefined ? newValue : true;

                        var editableContainer = $('.redactor-editor', element);
                        editableContainer.prop('contenteditable', scope.enabled);
                    });
                    
                    scope.$watch('ngModel', function (value) {

                        if (value !== $editor.redactor('code.get')) {
                            updating = true;
                            $editor.redactor('code.set', (value || ''));
                            $timeout(function () {
                                updating = false;
                            }, 100);
                        }

                        self.validate();
                    });

                    $editor.redactor('code.set', (scope.ngModel || ''));

                    self.init();

                });
            };
            HtmlControl.prototype = Object.create(jsnbt.controls.FormControlBase.prototype);

            HtmlControl.prototype.isValid = function () {
                var deferred = $q.defer();

                var self = this;

                jsnbt.controls.FormControlBase.prototype.isValid.apply(this, arguments).then(function (valid) {
                    if (valid && self.isValidating()) {

                        if (self.scope.ngRequired) {
                            valid = !!self.scope.ngModel && self.scope.ngModel !== '';
                        }

                    }

                    self.scope.valid = valid;
                    deferred.resolve(valid);
                });

                return deferred.promise;
            };

            return {
                restrict: 'E',
                replace: true,
                scope: $.extend(true, jsnbt.controls.FormControlBase.prototype.properties, {
                    ngToolbar: '=',
                    ngHeight: '=',
                    ngMaxHeight: '='
                }),
                link: function (scope, element, attrs) {
                    var control = new HtmlControl(scope, element, attrs);
                    $rootScope.controller.register(control);
                    return control;
                },
                templateUrl: 'tmpl/core/controls/form/ctrlHtml.html'
            };

        }]);

})();<commit_msg>ctrlHtml fix<commit_after>﻿/* global angular:false */

(function () {

    "use strict";

    angular.module('jsnbt')
        .directive('ctrlHtml', ['$rootScope', '$timeout', '$q', 'CONTROL_EVENTS', function ($rootScope, $timeout, $q, CONTROL_EVENTS) {

            var HtmlControl = function (scope, element, attrs) {
                jsnbt.controls.FormControlBase.apply(this, $rootScope.getBaseArguments(scope, element, attrs));

                var self = this;

                element.addClass('ctrl');
                element.addClass('ctrl-html');

                scope.enabled = true;

                var editorId = 'editor_' + scope.id;

                $timeout(function () {
                    var $editor = $('#' + editorId);

                    var updating = false;

                    var opts = {
                        buttons: ['formatting', 'bold', 'italic', 'deleted',
                            'unorderedlist', 'orderedlist', 'outdent', 'indent',
                            'image', 'file', 'link', 'alignment', 'horizontalrule']
                    };

                    var options = {
                        minHeight: scope.ngHeight || 60,
                        maxHeight: scope.ngMaxHeight || scope.ngHeight,
                        buttons: scope.ngToolbar
                    };

                    $.extend(opts, options, {
                        changeCallback: function () {
                            if (!updating) {
                                var editorCode = this.code.get();
                                if (scope.ngModel === undefined)
                                    scope.ngModel = '';

                                if (!_.isEqual(editorCode, scope.ngModel)) {
                                    scope.ngModel = this.code.get();
                                    scope.changed();
                                }
                            }
                        }
                    })

                    $editor.redactor(opts);
                    
                    scope.$watch('ngDisabled', function (newValue) {
                        scope.enabled = newValue !== undefined ? newValue : true;

                        var editableContainer = $('.redactor-editor', element);
                        editableContainer.prop('contenteditable', scope.enabled);
                    });
                    
                    scope.$watch('ngModel', function (value) {
                        if (value !== $editor.redactor('code.get')) {
                            updating = true;
                            $editor.redactor('code.set', (value || ''));
                            $timeout(function () {
                                updating = false;
                            }, 100);
                        }

                        self.validate();
                    });

                    $editor.redactor('code.set', (scope.ngModel || ''));

                    self.init();

                });
            };
            HtmlControl.prototype = Object.create(jsnbt.controls.FormControlBase.prototype);

            HtmlControl.prototype.isValid = function () {
                var deferred = $q.defer();

                var self = this;

                jsnbt.controls.FormControlBase.prototype.isValid.apply(this, arguments).then(function (valid) {
                    if (valid && self.isValidating()) {

                        if (self.scope.ngRequired) {
                            valid = !!self.scope.ngModel && self.scope.ngModel !== '';
                        }

                    }

                    self.scope.valid = valid;
                    deferred.resolve(valid);
                });

                return deferred.promise;
            };

            return {
                restrict: 'E',
                replace: true,
                scope: $.extend(true, jsnbt.controls.FormControlBase.prototype.properties, {
                    ngToolbar: '=',
                    ngHeight: '=',
                    ngMaxHeight: '='
                }),
                link: function (scope, element, attrs) {
                    var control = new HtmlControl(scope, element, attrs);
                    $rootScope.controller.register(control);
                    return control;
                },
                templateUrl: 'tmpl/core/controls/form/ctrlHtml.html'
            };

        }]);

})();
{'fraction_non_alphanumeric': 0.11612676879897088, 'fraction_numerical': 0.0009355630920360191, 'mean_word_length': 1.0284629981024669, 'pattern_counts': {'":': 0, '<': 3, '<?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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6266253', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1850, 'n_words': 342}