<commit_before>// An Angular.js app that displays code examples.
// Create by <NAME> 2014
// Updated April 2015
var app = angular.module('exampleViewerApp', ['ngRoute']);

// Set up routes.
app.config(function($routeProvider) {
  $routeProvider.
    when('/', {
      templateUrl: 'example-list.html',
      controller: 'ExampleListCtrl'
    }).
    when('/:exampleNumber', {
      templateUrl: 'example-detail.html',
      controller: 'ExampleDetailCtrl'
    }).
    otherwise({
      redirectTo: '/'
    });
});

// This service works with slides.json.
app.factory('examples', function($http){

  function getData(callback){
    $http({
      method: 'GET',
      url: '../slides.json',
      cache: true
    }).success(callback);
  }

  return {

    // examples.list(callback) lists all examples.
    list: getData,

    // examples.find gets details about one specific example.
    find: function(exampleNumber, callback){
      getData(function(data) {
        var index = parseInt(exampleNumber) - 1;
        callback(data[index]);
      });
    }
  };
});

// This service works with project.json.
app.factory('project', function($http){
  return {
    getData: function (callback){
      $http({
        method: 'GET',
        url: '../project.json',
        cache: true
      }).success(callback);
    }
  };
});

// Responsible for navigating based on key events.
app.controller('MainCtrl', function ($scope, $document, $location, examples){

  // Show the iframe running the example code by default.
  // This can be toggled by pressing "p".
  $scope.showIFrame = true;

  examples.list(function(examples){

    // These are key codes from key down events.
    var LEFT = 37,
        RIGHT = 39,
        PAGEUP = 33,
        PAGEDOWN = 34,
        BACKSPACE = 8,
        ESC = 27,
        P = 80;

    $scope.onKeydown = function(e) {

      if (e.srcElement.type === 'textarea') {
        //disable keyboard navigation from code text editor
        return;
      }

      // Use left and right arrows for navigation
      var path = $location.path(),
          // The example number
          n;

      if(path.length > 1) {
        // Extract the example number from the path.
        n = parseInt(path.substr(1), 10);
      }
      else {
        n = ''
      }

      // Increment or decrement the example number.
      switch(e.keyCode) {
        case ESC:
          n = '';
          break;

        case RIGHT:
        case PAGEDOWN:
          if (n < examples.length)  n++;
          break;

        case LEFT:
        case PAGEUP:
          if (n == 1)  n = '';
          if (n > 1)  n--;
          break;

        case BACKSPACE:
          n = 1;
          break;
      }
      
      // Navigate to the previous or next example.
      $location.path('/' + n);

      // Use the "p" key to toggle visibility of the iframe.
      if(e.keyCode === P){
        $scope.showIFrame = !$scope.showIFrame;
      }
    };
  });
});

app.controller('ExampleListCtrl', function ($scope, examples, project){
  examples.list(function(examples) {
    $scope.examples = examples;
  });
  project.getData(function(project){
    $scope.title = project.title;
    $scope.date = project.date;
    $scope.author = project.author;
    $scope.authorLink = project.authorLink;
  });
});

app.controller('ExampleDetailCtrl',
  function ($scope, $routeParams, $http, $sce, examples){
  examples.find($routeParams.exampleNumber, function(example) {
    $scope.example = example;
    if (example.iframe === true) {
      $scope.iframe = '../examples/' + example.files[0];
    } else {<commit_msg>do not use project.json<commit_after>// An Angular.js app that displays code examples.
// Create by <NAME> 2014
// Updated April 2015
var app = angular.module('exampleViewerApp', ['ngRoute']);

// Set up routes.
app.config(function($routeProvider) {
  $routeProvider.
    when('/', {
      templateUrl: 'example-list.html',
      controller: 'ExampleListCtrl'
    }).
    when('/:exampleNumber', {
      templateUrl: 'example-detail.html',
      controller: 'ExampleDetailCtrl'
    }).
    otherwise({
      redirectTo: '/'
    });
});

// This service works with slides.json.
app.factory('examples', function($http){

  function getData(callback){
    $http({
      method: 'GET',
      url: '../slides.json',
      cache: true
    }).success(callback);
  }

  return {

    // examples.list(callback) lists all examples.
    list: getData,

    // examples.find gets details about one specific example.
    find: function(exampleNumber, callback){
      getData(function(data) {
        var index = parseInt(exampleNumber) - 1;
        callback(data[index]);
      });
    }
  };
});

// This service works with project.json.
// app.factory('project', function($http){
//   return {
//     getData: function (callback){
//       $http({
//         method: 'GET',
//         url: '../project.json',
//         cache: true
//       }).success(callback);
//     }
//   };
// });

// Responsible for navigating based on key events.
app.controller('MainCtrl', function ($scope, $document, $location, examples){

  // Show the iframe running the example code by default.
  // This can be toggled by pressing "p".
  $scope.showIFrame = true;

  examples.list(function(examples){

    // These are key codes from key down events.
    var LEFT = 37,
        RIGHT = 39,
        PAGEUP = 33,
        PAGEDOWN = 34,
        BACKSPACE = 8,
        ESC = 27,
        P = 80;

    $scope.onKeydown = function(e) {

      if (e.srcElement.type === 'textarea') {
        //disable keyboard navigation from code text editor
        return;
      }

      // Use left and right arrows for navigation
      var path = $location.path(),
          // The example number
          n;

      if(path.length > 1) {
        // Extract the example number from the path.
        n = parseInt(path.substr(1), 10);
      }
      else {
        n = ''
      }

      // Increment or decrement the example number.
      switch(e.keyCode) {
        case ESC:
          n = '';
          break;

        case RIGHT:
        case PAGEDOWN:
          if (n < examples.length)  n++;
          break;

        case LEFT:
        case PAGEUP:
          if (n == 1)  n = '';
          if (n > 1)  n--;
          break;

        case BACKSPACE:
          n = 1;
          break;
      }
      
      // Navigate to the previous or next example.
      $location.path('/' + n);

      // Use the "p" key to toggle visibility of the iframe.
      if(e.keyCode === P){
        $scope.showIFrame = !$scope.showIFrame;
      }
    };
  });
});

app.controller('ExampleListCtrl', function ($scope, examples, project){
  examples.list(function(examples) {
    $scope.examples = examples;
  });
  // project.getData(function(project){
  //   $scope.title = project.title;
  //   $scope.date = project.date;
  //   $scope.author = project.author;
  //   $scope.authorLink = project.authorLink;
  // });
});

app.controller('ExampleDetailCtrl',
  function ($scope, $routeParams, $http, $sce, examples){
  examples.find($routeParams.exampleNumber, function(example) {
    $scope.example = example;
    if (example.iframe === true) {
      $scope.iframe = '../examples/' + example.files[0];
    } else {
{'fraction_non_alphanumeric': 0.14427723319066685, 'fraction_numerical': 0.008283860278889962, 'mean_word_length': 2.0799319727891157, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7284376', 'n_tokens_mistral': 2257, 'n_tokens_neox': 2132, 'n_words': 577}