<commit_before>'use strict';

var app = angular.module('iicms', []);

app.controller('feCntrl', function ($scope, $http) {
  $scope.changes = [];
});

app.controller('iicmsCntrl', function ($scope, $http) {
  $scope.activeEditor = null;

  var lastPost = {
    then: function (f) {
      return f.apply();
    }
  };

  $scope.showEditor = function (editor) {
    if ($scope.activeEditor) {
      $scope.activeEditor.hide();
    }
    $scope.activeEditor = editor;
    editor.show();
    editor.find('textarea').focus();
  };

  $scope.saveFragment = function (fragment) {
    lastPost = lastPost.then(function () {
      return $http.post('/cms', JSON.stringify(fragment), {
        headers: {
          'Content-Type': 'application/json'
        }
      });
    });
  };
});

app.directive('iicmsfragment', ['$compile',
  function ($compile) {
    return {
      restrict: 'E',
      scope: true,
      link: function (scope, elm, attrs) {

        var origContent = elm.html();
        scope.content = origContent;
        scope.fragmentPath = attrs.path;

        var edit = angular.element('<div class="cms-edit"><span>edit</span></div>');
        var editor = $compile(angular.element(' \
              <div class="cms-editor"> \
                <a href="#" class="close">close</a> \
                <h4>Fragment Editor</h4> \
                <h5>{{fragmentPath}}</h5> \
                <textarea type=text ng-model="content"></textarea> \
              </div> \
              '))(scope);

        angular.element('body').append(editor);

        elm.after(edit);

        editor.keyup(function (e) {
          if (e.keyCode === 27) {
            editor.hide();
          }
        });

        editor.find('.close').bind('click', function (e) {
          e.preventDefault();
          editor.hide();
        });

        edit.find('span').bind('click', function () {
          scope.showEditor(editor);
        });

        elm.after($compile(angular.element('<span ng-bind-html-unsafe="content" />'))(scope));
        elm.remove();

        scope.$watch('content', function (newVal, oldVal) {
          if (newVal !== oldVal) {
            var sanitizedFragment =
              angular.element.parseHTML(newVal).map(function (el) {
                return el.outerHTML || el.textContent;
              }).join('');
            scope.saveFragment({
              fragment: attrs.path,
              content: sanitizedFragment
            });
          }
        });
<commit_msg>Supress default link click events.<commit_after>'use strict';

var app = angular.module('iicms', []);

app.controller('feCntrl', function ($scope, $http) {
  $scope.changes = [];
});

app.controller('iicmsCntrl', function ($scope, $http) {
  $scope.activeEditor = null;

  var lastPost = {
    then: function (f) {
      return f.apply();
    }
  };

  $scope.showEditor = function (editor) {
    if ($scope.activeEditor) {
      $scope.activeEditor.hide();
    }
    $scope.activeEditor = editor;
    editor.show();
    editor.find('textarea').focus();
  };

  $scope.saveFragment = function (fragment) {
    lastPost = lastPost.then(function () {
      return $http.post('/cms', JSON.stringify(fragment), {
        headers: {
          'Content-Type': 'application/json'
        }
      });
    });
  };
});

app.directive('iicmsfragment', ['$compile',
  function ($compile) {
    return {
      restrict: 'E',
      scope: true,
      link: function (scope, elm, attrs) {

        var origContent = elm.html();
        scope.content = origContent;
        scope.fragmentPath = attrs.path;

        var edit = angular.element('<div class="cms-edit"><span>edit</span></div>');
        var editor = $compile(angular.element(' \
              <div class="cms-editor"> \
                <a href="#" class="close">close</a> \
                <h4>Fragment Editor</h4> \
                <h5>{{fragmentPath}}</h5> \
                <textarea type=text ng-model="content"></textarea> \
              </div> \
              '))(scope);

        angular.element('body').append(editor);

        elm.after(edit);

        editor.keyup(function (e) {
          if (e.keyCode === 27) {
            editor.hide();
          }
        });

        editor.find('.close').bind('click', function (e) {
          e.preventDefault();
          editor.hide();
        });

        edit.find('span').bind('click', function (e) {
          e.preventDefault();
          scope.showEditor(editor);
        });

        elm.after($compile(angular.element('<span ng-bind-html-unsafe="content" />'))(scope));
        elm.remove();

        scope.$watch('content', function (newVal, oldVal) {
          if (newVal !== oldVal) {
            var sanitizedFragment =
              angular.element.parseHTML(newVal).map(function (el) {
                return el.outerHTML || el.textContent;
              }).join('');
            scope.saveFragment({
              fragment: attrs.path,
              content: sanitizedFragment
            });
          }
        });

{'fraction_non_alphanumeric': 0.17151394422310756, 'fraction_numerical': 0.002390438247011952, 'mean_word_length': 1.960495283018868, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '2248893', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1448, 'n_words': 256}