<commit_before>/**
 * Binds a TinyMCE widget to <textarea> elements.
 */
angular.module('ui.tinymce', [])
  .value('uiTinymceConfig', {})
  .directive('uiTinymce', ['$rootScope', '$window', 'uiTinymceConfig', function($rootScope, $window, uiTinymceConfig) {
    uiTinymceConfig = uiTinymceConfig || {};
    var generatedIds = 0;
    return {
      require: 'ngModel',
      link: function(scope, element, attrs, ngModel) {
        if (!$window.tinymce) {
          return;
        }

        var expression, options, tinyInstance,
          updateView = function (editor) {
            if (options.raw === true) {
              ngModel.$setViewValue(editor.getContent({format: 'text'}).trim());
            } else {
              ngModel.$setViewValue(editor.getContent().trim());
            }
            if (!$rootScope.$$phase) {
              scope.$apply();
            }
          };

        // generate an ID if not present
        if (!attrs.id) {
          attrs.$set('id', 'uiTinymce' + generatedIds++);
        }

        expression = {};

        angular.extend(expression, scope.$eval(attrs.uiTinymce));

        // make config'ed setup method available
        if (expression.setup) {
          var configSetup = expression.setup;
          delete expression.setup;
        }

        options = {
          // Update model when calling setContent (such as from the source editor popup)
          setup: function(ed) {
            var args;
            ed.on('init', function(args) {
              ngModel.$render();
              ngModel.$setPristine();
            });
            // Update model on button click
            ed.on('ExecCommand', function(e) {
              ed.save();
              updateView(ed);
            });
            // Update model on keypress
            ed.on('KeyUp', function(e) {
              ed.save();
              updateView(ed);
            });
            // Update model on change, i.e. copy/pasted text, plugins altering content
            ed.on('SetContent', function(e) {
              if (!e.initial && ngModel.$viewValue !== e.content) {
                ed.save();
                updateView(ed);
              }
            });
            ed.on('blur', function(e) {
              element[0].blur();
            });
            // Update model when an object has been resized (table, image)
            ed.on('ObjectResized', function(e) {
              ed.save();
              updateView(ed);
            });
            if (configSetup) {
              configSetup(ed);
            }
          },
          selector: '#' + attrs.id
        };
        // extend options with initial uiTinymceConfig and options from directive attribute value
        angular.extend(options, uiTinymceConfig, expression);
        tinymce.init(options);

        ngModel.$render = function() {
          if (!tinyInstance) {
            tinyInstance = tinymce.get(attrs.id);
          }
          if (tinyInstance) {
            tinyInstance.setContent(ngModel.$viewValue || '');
          }<commit_msg>Provide helper object as second argument to `configSetup` method<commit_after>/**
 * Binds a TinyMCE widget to <textarea> elements.
 */
angular.module('ui.tinymce', [])
  .value('uiTinymceConfig', {})
  .directive('uiTinymce', ['$rootScope', '$window', 'uiTinymceConfig', function($rootScope, $window, uiTinymceConfig) {
    uiTinymceConfig = uiTinymceConfig || {};
    var generatedIds = 0;
    return {
      require: 'ngModel',
      link: function(scope, element, attrs, ngModel) {
        if (!$window.tinymce) {
          return;
        }

        var expression, options, tinyInstance,
          updateView = function(editor) {
            if (options.raw === true) {
              ngModel.$setViewValue(editor.getContent({format: 'text'}).trim());
            } else {
              ngModel.$setViewValue(editor.getContent().trim());
            }
            if (!$rootScope.$$phase) {
              scope.$apply();
            }
          };

        // generate an ID if not present
        if (!attrs.id) {
          attrs.$set('id', 'uiTinymce' + generatedIds++);
        }

        expression = {};

        angular.extend(expression, scope.$eval(attrs.uiTinymce));

        // make config'ed setup method available
        if (expression.setup) {
          var configSetup = expression.setup;
          delete expression.setup;
        }

        options = {
          // Update model when calling setContent (such as from the source editor popup)
          setup: function(ed) {
            var args;
            ed.on('init', function(args) {
              ngModel.$render();
              ngModel.$setPristine();
            });
            // Update model on button click
            ed.on('ExecCommand', function(e) {
              ed.save();
              updateView(ed);
            });
            // Update model on keypress
            ed.on('KeyUp', function(e) {
              ed.save();
              updateView(ed);
            });
            // Update model on change, i.e. copy/pasted text, plugins altering content
            ed.on('SetContent', function(e) {
              if (!e.initial && ngModel.$viewValue !== e.content) {
                ed.save();
                updateView(ed);
              }
            });
            ed.on('blur', function(e) {
              element[0].blur();
            });
            // Update model when an object has been resized (table, image)
            ed.on('ObjectResized', function(e) {
              ed.save();
              updateView(ed);
            });
            if (configSetup) {
              configSetup(ed, {
                updateView: updateView
              });
            }
          },
          selector: '#' + attrs.id
        };
        // extend options with initial uiTinymceConfig and options from directive attribute value
        angular.extend(options, uiTinymceConfig, expression);
        tinymce.init(options);

        ngModel.$render = function() {
          if (!tinyInstance) {
            tinyInstance = tinymce.get(attrs.id);
          }
          if (tinyInstance) {
            tinyInstance.setContent(ngModel.$viewValue || '');
          }
{'fraction_non_alphanumeric': 0.12979066022544283, 'fraction_numerical': 0.0006441223832528181, 'mean_word_length': 1.5750414593698177, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6090544', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1644, 'n_words': 365}