<commit_before>function init() {
  // ==========================================
  // =========== prepare data =================
  // ==========================================

  // define images for each task
  // TODO: replace your image urls
  /*var im_urls = ["http://www.nationalinterest.org/files/styles/main_image_on_posts/public/main_images/1280px-SR-71A_in_flight_near_Beale_AFB_1988.jpeg?itok=dtWTvSfA",
                 "http://orig01.deviantart.net/cedb/f/2013/113/f/5/basket_of_cats_by_chained2stone-dy75pd.jpg",
                 "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR_HqqOSDNsR4_m9Ofw1AwZeVlzsNLUzw_3DnLoXVLcpAD9nA1A",
                 "https://upload.wikimedia.org/wikipedia/commons/8/8a/Laitche-P013.jpg"]; */
  // seed image
  // set up hints
  // the location of hints were annotated in the category labeling stage
  // here 3 hints are corresponding to 3 images
  hints = new Array();
  hints[0] = {"x": [0.3],"y": [0.5], "cat_id":5};

  // image objects
  if (typeof im_urls === 'undefined') {
    setTimeout(function() {
      init();
    }, 50);
  } else {
  Im = new Array();

  // category information
  cat_id = [5]; // using cat for demo
  cat_name = 'Airplane';

  // Annotations for images
  // first index to index an object that stores annotations for an image
  Anno = new Array();

  // Marks that show on image
  // One for marker on magnifying glass and one for the markers on the <background></background>
  Marker = new Array();
  Marker_bg = new Array();

  // set timer
  init_time = 0;
  //category


  // Answers
  for (i=0; i< im_urls.length; i++){
      Anno[i] = new Object();
      Im[i] = new Image();
      Im[i].src = im_urls[i];
      console.log("in init");
      console.log(Im[i].src);
      Anno[i].cat_id = cat_id;
      // new annotations from this stage
      Anno[i].ans = [];
      Anno[i].annoloc = [];
      Anno[i].annoloc_percentage = [];
      for (var j=0; j < cat_id.length; j++){
          Anno[i].ans.push([[-1]]);
          Anno[i].annoloc.push([[-1,-1]]);
          Anno[i].annoloc_percentage.push([[-1,-1]]);
      }
  }

  var domIsReady = setInterval(function () {
    if (document.readyState === "complete") {
      clearInterval(domIsReady);
      init_time = $.now();
      console.log("Am I called");
      imClick_Ctrl();
      window.oncontextmenu = function() { return false };
    }
  }, 50);

  //$(window).load(function(){

  //});
  }
}

function setupImagePanels() {
  if (typeof im_urls === 'undefined') {
    setTimeout(function(){
      setupImagePanels();
    }, 50);
  } else {
    console.log(im_urls);
    var node = document.getElementById("images");
    node.appendChild($.parseHTML("<div class='im-panel' id='im-panel-0'><div class='imdiv' id='imdiv-0'><canvas class='img' id='img-0'></canvas></div></div>")[0]);
    for (i=1; i < im_urls.length; i++){
      node.appendChild($.parseHTML("<div class='im-panel' id='im-panel-"+i+"'><div class='imdiv' id='imdiv-"+i+"'><canvas class='img' id='img-"+i+"'></canvas></div></div>")[0]);
    }

    loadImages();
  }
}

function loadImages() {
  if (typeof(im_urls) == 'undefined') {
    setTimeout(function(){
      loadImages();
    }, 50);
  } else {
    for (var ii = 0; ii < im_urls.length; ii++) {
      var id = '#img-' + ii.toString();
      //console.log(ii);
      var canvas = $(id)[0]; //.attr('background', Im[i].src);
      var ctx = canvas.getContext("2d");
      var background = new Image();
      background.src = im_urls[ii];
      background.onload = function(background,canvas,ctx) {
        return function() {
          console.log(canvas);
          console.log(ctx);
          canvas.width = background.width;
          canvas.height = background.height;
          ctx.drawImage(background,0,0);
        };
      }(background,canvas,ctx);
    }
  }
}

Ctrler.prototype.turn_off_panels = function() {
  for (var ii = 0; ii < this.N; ii++) {
    $('#im-panel-' + ii).hide();
  }
}
// Ctrler controls the state of UI and rendering
function Ctrler(){
    this.N = 0;
    this.cur_img_idx = 0;  // image
    this.cur_obj_idx = 0;  // object category
    this.cur_anno_idx = 0;// annotation from 1 to 10, start from 0
    this.len_ratio = 2;
    this.hint_status = false;
}
// render image panel for given working image id
Ctrler.prototype.render_im_panel = function(){
    for (i = 0; i < this.N; i++){
        if (i == this.cur_img_idx){
            $('#im-panel-'+i).show();
        }else{
            $('#im-panel-'+i).hide();
        }
    }
    for (i = 0; i < this.N; i++){
        if (i == this.cur_img_idx){
            $('#category-panel-'+i).show();
        }else{
            $('#category-panel-'+i).hide();
        }
    }
    this.render_bgim();
}
// render category panel which includes icon and examples
Ctrler.prototype.render_category_panel = function(){
    var i = this.cur_img_idx;
    var j = this.cur_obj_idx;
    var cat_id = Anno[i].cat_id
    var src = 'static/img/categories/' + cat_id[0] + '.png';
    // render icon
    var cat_div = $('#div-cat-img');
    console.log(cat_div);
    cat_div.find('img').attr('src', src);
    cat_div.find('img').css('width',  80);
    cat_div.find('img').css('height', 80);
    // redner name
    $('#div-cat-name').html(cat_name);
}
Ctrler.prototype.render_hint = function(){
    $('.hint').stop(true);
    // load annotation from stage 2
    // render saved annotation for the first time
    var i = this.cur_img_idx;
    var j = this.cur_obj_idx;
    var x = Anno[i].x[j];
    var y = Anno[i].y[j];
    var img = $('#img-'+i);
    // compute hint's position
    var img_left = img.position().left;
    var img_top  = img.position().top;
    var img_wid  = parseFloat(img.css('width'));
    var img_hei  = parseFloat(img.css('height'));
    var pos_x = Math.round(img_left+x*img_wid);
    var pos_y = Math.round(img_top+y*img_hei);
    // show hints
    $('.hint').css('left', pos_x);
    $('.hint').css('top', pos_y);
    var cat_id = Anno[i].cat_id
    var src = 'static/img/categories/' + cat_id + '.png';
    $('.hint-img').attr('src', src);
    var s = 400;<commit_msg>Re-fixing absolute URLs to static content<commit_after>function init() {
  // ==========================================
  // =========== prepare data =================
  // ==========================================

  // define images for each task
  // TODO: replace your image urls
  /*var im_urls = ["http://www.nationalinterest.org/files/styles/main_image_on_posts/public/main_images/1280px-SR-71A_in_flight_near_Beale_AFB_1988.jpeg?itok=dtWTvSfA",
                 "http://orig01.deviantart.net/cedb/f/2013/113/f/5/basket_of_cats_by_chained2stone-dy75pd.jpg",
                 "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR_HqqOSDNsR4_m9Ofw1AwZeVlzsNLUzw_3DnLoXVLcpAD9nA1A",
                 "https://upload.wikimedia.org/wikipedia/commons/8/8a/Laitche-P013.jpg"]; */
  // seed image
  // set up hints
  // the location of hints were annotated in the category labeling stage
  // here 3 hints are corresponding to 3 images
  hints = new Array();
  hints[0] = {"x": [0.3],"y": [0.5], "cat_id":5};

  // image objects
  if (typeof im_urls === 'undefined') {
    setTimeout(function() {
      init();
    }, 50);
  } else {
  Im = new Array();

  // category information
  cat_id = [5]; // using cat for demo
  cat_name = 'Airplane';

  // Annotations for images
  // first index to index an object that stores annotations for an image
  Anno = new Array();

  // Marks that show on image
  // One for marker on magnifying glass and one for the markers on the <background></background>
  Marker = new Array();
  Marker_bg = new Array();

  // set timer
  init_time = 0;
  //category


  // Answers
  for (i=0; i< im_urls.length; i++){
      Anno[i] = new Object();
      Im[i] = new Image();
      Im[i].src = im_urls[i];
      console.log("in init");
      console.log(Im[i].src);
      Anno[i].cat_id = cat_id;
      // new annotations from this stage
      Anno[i].ans = [];
      Anno[i].annoloc = [];
      Anno[i].annoloc_percentage = [];
      for (var j=0; j < cat_id.length; j++){
          Anno[i].ans.push([[-1]]);
          Anno[i].annoloc.push([[-1,-1]]);
          Anno[i].annoloc_percentage.push([[-1,-1]]);
      }
  }

  var domIsReady = setInterval(function () {
    if (document.readyState === "complete") {
      clearInterval(domIsReady);
      init_time = $.now();
      console.log("Am I called");
      imClick_Ctrl();
      window.oncontextmenu = function() { return false };
    }
  }, 50);

  //$(window).load(function(){

  //});
  }
}

function setupImagePanels() {
  if (typeof im_urls === 'undefined') {
    setTimeout(function(){
      setupImagePanels();
    }, 50);
  } else {
    console.log(im_urls);
    var node = document.getElementById("images");
    node.appendChild($.parseHTML("<div class='im-panel' id='im-panel-0'><div class='imdiv' id='imdiv-0'><canvas class='img' id='img-0'></canvas></div></div>")[0]);
    for (i=1; i < im_urls.length; i++){
      node.appendChild($.parseHTML("<div class='im-panel' id='im-panel-"+i+"'><div class='imdiv' id='imdiv-"+i+"'><canvas class='img' id='img-"+i+"'></canvas></div></div>")[0]);
    }

    loadImages();
  }
}

function loadImages() {
  if (typeof(im_urls) == 'undefined') {
    setTimeout(function(){
      loadImages();
    }, 50);
  } else {
    for (var ii = 0; ii < im_urls.length; ii++) {
      var id = '#img-' + ii.toString();
      //console.log(ii);
      var canvas = $(id)[0]; //.attr('background', Im[i].src);
      var ctx = canvas.getContext("2d");
      var background = new Image();
      background.src = im_urls[ii];
      background.onload = function(background,canvas,ctx) {
        return function() {
          console.log(canvas);
          console.log(ctx);
          canvas.width = background.width;
          canvas.height = background.height;
          ctx.drawImage(background,0,0);
        };
      }(background,canvas,ctx);
    }
  }
}

Ctrler.prototype.turn_off_panels = function() {
  for (var ii = 0; ii < this.N; ii++) {
    $('#im-panel-' + ii).hide();
  }
}
// Ctrler controls the state of UI and rendering
function Ctrler(){
    this.N = 0;
    this.cur_img_idx = 0;  // image
    this.cur_obj_idx = 0;  // object category
    this.cur_anno_idx = 0;// annotation from 1 to 10, start from 0
    this.len_ratio = 2;
    this.hint_status = false;
}
// render image panel for given working image id
Ctrler.prototype.render_im_panel = function(){
    for (i = 0; i < this.N; i++){
        if (i == this.cur_img_idx){
            $('#im-panel-'+i).show();
        }else{
            $('#im-panel-'+i).hide();
        }
    }
    for (i = 0; i < this.N; i++){
        if (i == this.cur_img_idx){
            $('#category-panel-'+i).show();
        }else{
            $('#category-panel-'+i).hide();
        }
    }
    this.render_bgim();
}
// render category panel which includes icon and examples
Ctrler.prototype.render_category_panel = function(){
    var i = this.cur_img_idx;
    var j = this.cur_obj_idx;
    var cat_id = Anno[i].cat_id
    var src = 'https://cdn.rawgit.com/ghexp/turkform/master/static/img/categories/' + cat_id[0] + '.png';
    // render icon
    var cat_div = $('#div-cat-img');
    console.log(cat_div);
    cat_div.find('img').attr('src', src);
    cat_div.find('img').css('width',  80);
    cat_div.find('img').css('height', 80);
    // redner name
    $('#div-cat-name').html(cat_name);
}
Ctrler.prototype.render_hint = function(){
    $('.hint').stop(true);
    // load annotation from stage 2
    // render saved annotation for the first time
    var i = this.cur_img_idx;
    var j = this.cur_obj_idx;
    var x = Anno[i].x[j];
    var y = Anno[i].y[j];
    var img = $('#img-'+i);
    // compute hint's position
    var img_left = img.position().left;
    var img_top  = img.position().top;
    var img_wid  = parseFloat(img.css('width'));
    var img_hei  = parseFloat(img.css('height'));
    var pos_x = Math.round(img_left+x*img_wid);
    var pos_y = Math.round(img_top+y*img_hei);
    // show hints
    $('.hint').css('left', pos_x);
    $('.hint').css('top', pos_y);
    var cat_id = Anno[i].cat_id
    var src = 'https://cdn.rawgit.com/ghexp/turkform/master/static/img/categories/' + cat_id + '.png';
    $('.hint-img').attr('src', src);
    var s = 400;
{'fraction_non_alphanumeric': 0.19680764867930645, 'fraction_numerical': 0.015070491006319884, 'mean_word_length': 2.7032703270327034, 'pattern_counts': {'":': 6, '<': 45, '<?xml version=': 0, '>': 31, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, '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': '6575889', 'n_tokens_mistral': 4442, 'n_tokens_neox': 4295, 'n_words': 898}