<commit_before>// easyAnnotate JavaScript.

// define a 'constant' so we can easily select video, no matter what we choose to call it in final HTML implementation...
var VIDEO_SELECTOR = 'video'

//  global variables
//  number of whole seconds that the video's been playing for.
var currentTime = 0;
//  an array that holds annotation objects.
var annotationsArray = [];

//  annotation object prototype.
function annotation(text, imageUrl, xPosition, yPosition, width, height, startTime, endTime) {
    this.text = text;
    this.imageUrl = imageUrl;
    this.xPosition = xPosition;
    this.yPosition = yPosition;
    this.width = width;
    this.height = height;
    this.startTime = startTime;
    this.endTime = endTime;
}

function testAnnotation(){
  var newAnnotation = new annotation('Annotation', null, 30, 30, 30, 30, 3, 5);
  annotationsArray.push(newAnnotation);
  console.log(annotationsArray);

}

//  the update method, to be called every time the running time of the video changes by a whole second
function update(){
  console.log('update called.');
  // we want annotations that have a start time greater than or equal to the current playback time,
  // but also an end time less than the current time.

  // some funky jquery to search through the array.
  var currentAnnotations = $.grep(annotationsArray, function(e) {
    return (currentTime >= e.startTime  && currentTime < e.endTime);
  });

  console.log(currentAnnotations);
}

//  jQuery events.
$(document).ready(function(){
  //the DOM has loaded, so let's begin...
  console.log('ready');

  //super super handy reference for video tag info... http://www.w3schools.com/tags/ref_av_dom.asp

  $(VIDEO_SELECTOR).bind("play", function() {
    console.log('started playing.');
    // NOTE: This is also called on resume from a pause, it's not unique to the video's first play.
    // call update manually - there could be annotations that need to be shown at 0 secs!
    update();
  });

  $(VIDEO_SELECTOR).bind('pause', function() {
    console.log('playback paused.');
  });

  $(VIDEO_SELECTOR).bind('ended', function() {
    console.log('finished playing.');
    // reset current time variable (but do not call update!)
    currentTime = 0;
  });

  $(VIDEO_SELECTOR).bind('timeupdate', function() {
    //  the current video play time, in whole seconds (rounded down)
    newTime = Math.floor(this.currentTime);
    // okay, we only care about updating if the time is different (in whole seconds)
    // otherwise, the user's getting absolutely hammered with the DOM redrawing etc.
    if(newTime != currentTime){
      // a whole second has passed (or many seconds if they video's been skipped)
      console.log('seconds changed: ' + newTime);

      //update current time to new time.
      currentTime = newTime;

      update();
    }
  });

});
<commit_msg>Added new/old annotations too so we know what to remove/add when<commit_after>// easyAnnotate JavaScript.

// define a 'constant' so we can easily select video, no matter what we choose to call it in final HTML implementation...
var VIDEO_SELECTOR = 'video'

//  global variables
//  number of whole seconds that the video's been playing for.
var currentTime = 0;
//  an array that holds annotation objects.
var annotationsArray = [];

//  annotation object prototype.
function annotation(text, imageUrl, xPosition, yPosition, width, height, startTime, endTime) {
    this.text = text;
    this.imageUrl = imageUrl;
    this.xPosition = xPosition;
    this.yPosition = yPosition;
    this.width = width;
    this.height = height;
    this.startTime = startTime;
    this.endTime = endTime;
}

function testAnnotation(){
  var newAnnotation = new annotation('Annotation', null, 30, 30, 30, 30, 3, 5);
  annotationsArray.push(newAnnotation);
  console.log(annotationsArray);

}

//  the update method, to be called every time the running time of the video changes by a whole second
function update(){
  console.log('update called.');
  // we want annotations that have a start time greater than or equal to the current playback time,
  // but also an end time less than the current time.

  // some funky jquery to search through the array.
  var currentAnnotations = $.grep(annotationsArray, function(e) {
    return (currentTime >= e.startTime  && currentTime < e.endTime);
  });

  // these things might also be useful to know I guess...

  // get annotations that need to be added (i.e. have a start time of the current second)
  var newAnnotations = $.grep(annotationsArray, function(e) {
    return (currentTime == e.startTime);
  });

  // and get annotations that need to be removed (i.e. have an end time of the current second)
  var newAnnotations = $.grep(annotationsArray, function(e) {
    return (currentTime == e.endTime);
  })

  console.log(currentAnnotations);
}

//  jQuery events.
$(document).ready(function(){
  //the DOM has loaded, so let's begin...
  console.log('ready');

  //super super handy reference for video tag info... http://www.w3schools.com/tags/ref_av_dom.asp

  $(VIDEO_SELECTOR).bind("play", function() {
    console.log('started playing.');
    // NOTE: This is also called on resume from a pause, it's not unique to the video's first play.
    // call update manually - there could be annotations that need to be shown at 0 secs!
    update();
  });

  $(VIDEO_SELECTOR).bind('pause', function() {
    console.log('playback paused.');
  });

  $(VIDEO_SELECTOR).bind('ended', function() {
    console.log('finished playing.');
    // reset current time variable (but do not call update!)
    currentTime = 0;
  });

  $(VIDEO_SELECTOR).bind('timeupdate', function() {
    //  the current video play time, in whole seconds (rounded down)
    newTime = Math.floor(this.currentTime);
    // okay, we only care about updating if the time is different (in whole seconds)
    // otherwise, the user's getting absolutely hammered with the DOM redrawing etc.
    if(newTime != currentTime){
      // a whole second has passed (or many seconds if they video's been skipped)
      console.log('seconds changed: ' + newTime);

      //update current time to new time.
      currentTime = newTime;

      update();
    }
  });

});

{'fraction_non_alphanumeric': 0.11440541411537222, 'fraction_numerical': 0.0045117628101836935, 'mean_word_length': 3.3619114546732254, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '25675', 'n_tokens_mistral': 1806, 'n_tokens_neox': 1731, 'n_words': 675}