<commit_before>
//add annotation to fedora

function islandora_postData(title, data, type, color) {

  data = encodeURI(data);
  $.ajax({
    type:'POST',
    async:false,
    url: window.parent.Drupal.settings.basePath + islandora_canvas_params.islandora_post_url,
    data: {
      title:title,
      data:data,
      type:type,
      color:color
    },
    success: function(data,status,xhr) {
      islandora_getAnnotation(data);
    },
    error: function(data,status,xhr) {
      alert('Failed to post')
    }
  });

}

// Adds divs for each type
//

function islandora_getList() {

  var tabs = $('#tabs').tabs();
  tabs.tabs('select', 3);
  islandora_canvas_params.mappings = new Array();
  $.ajax({
    type:'GET',
    async:false,
    url: window.parent.Drupal.settings.basePath + islandora_canvas_params.get_annotation_list_url,
    success: function(data,status,xhr) {
   
      if(data != 'null'){
        var listdata = $.parseJSON(data);
        var pids = listdata.pids;
        var types = listdata.types;

       // create the divs
   
        if( listdata!= null && types != null){
          for (var i=0,info;i < types.length;i++){
            var fixed_cat = types[i].replace(/[^\w]/g,'');
            var type_class = "annoType_" + fixed_cat;
            var blockId = 'islandora_annoType_'+ fixed_cat;
            var contentId = 'islandora_annoType_content_'+ fixed_cat;
            var idSelector = '#' + blockId;

            if($(idSelector).length == 0){

              header =  '<div class = "islandora_comment_type" id = "'+ blockId + '">';
              header += '<div class = "islandora_comment_type_title">' + types[i] + '</div>';
              header += '<div class = "islandora_comment_type_content" style = "display:none" id = "'+ contentId + '"></div>';
              header += '</div>';

              $('#comment_annos_block').append(header);
            }

          }
        }
//populate the divs

        if( listdata!= null && pids != null){
          for (var i=0,info;i < pids.length;i++){
            islandora_canvas_params.mappings[pids[i]['urn']] = pids[i]['color']
            var pid = pids[i]['id'];
            $('#canvases .canvas').each(function() {
              // console.log(temp + " " + pid)
              var cnv = $(this).attr('canvas');
              islandora_getAnnotation(pid);
            });
      
          }
        }

        $(".islandora_comment_type_title").off();

        $(".islandora_comment_type_title").ready().on("click", function(){
          $(this).siblings('.islandora_comment_type_content').toggle();
        });
      }
    },
    error: function(data,status,xhr) {
    // alert('Failed to retrieve List')
    }

  });
 
}


// get annotation data from Fedora and send it to load_comment_anno to be displayed

function islandora_getAnnotation(pid) {

  $.ajax({
    type:'GET',
    url: window.parent.Drupal.settings.basePath + islandora_canvas_params.islandora_get_annotation + pid,
    success: function(data,status,xhr) {
      load_commentAnno(data);
     
    },
    error: function(data,status,xhr) {
      
    }
  });
}

// deletes annotation from fedora
function islandora_deleteAnno(urn) {

  var selector = '#anno_'+urn;
  $parent = $(selector).closest('.islandora_comment_type');
  length = $parent.find('.canvas_annotation').length;

  if (length ==1){
    $parent.remove();
  }

  var classSelector = '.svg_'+urn;
  $.ajax({
    type:'POST',
    url: window.parent.Drupal.settings.basePath + islandora_canvas_params.islandora_delete_annotation + urn,
    data: urn,
    success: function(data,status,xhr) {
      $(selector).next().remove();
      $(selector).remove();
      $(classSelector).remove();

    },
    error: function(data,status,xhr) {
    //   alert('Failed to delete annotation')
    }
  });
}

//updates existing annotations

function islandora_updateAnno(urn, title,annoType, content, color){
  $.ajax({
    type:'POST',
    url: window.parent.Drupal.settings.basePath + islandora_canvas_params.islandora_update_annotation,
    data: {
      urn:urn,
      title:title,
      annoType:annoType,
      content:content,
      color:color
    },
    success: function(data,status,xhr) {
      $('#create_annotation_box').hide();
      var selector = '#anno_'+urn;
      var text = $(selector).text().trim().substring(2,100);
      old_title = $(selector).html();
      new_title = old_title.replace(text, title);

      $(selector).html(new_title);
      $(selector).next('.comment_text').find('.comment_type').text(annoType);
      $(selector).next('.comment_text').find('.comment_content').text(content);
      var fixed_cat = annoType.replace(/[^\w]/g,'');

      $annotation = $(selector).closest('.canvas_annotation');
      $destination = $('#islandora_annoType_content_' + fixed_cat);
      $annotation.appendTo($destination);
     
    },
    error: function(data,status,xhr) {
      alert('Failed to update annotation')
    }
  });
  $('#create_annotation').empty().append('Annotate');
  $('#create_annotation').css({
    color:'#000000'
  });
}<commit_msg>added logic to prevent double slashes in urls<commit_after>
//add annotation to fedora

function islandora_postData(title, data, type, color) {

  data = encodeURI(data);
  $.ajax({
    type: 'POST',
    async: false,
    url: islandora_get_basepath() + islandora_canvas_params.islandora_post_url,
    data: {
      title: title,
      data: data,
      type: type,
      color: color
    },
    success: function(data, status, xhr) {
      islandora_getAnnotation(data);
    },
    error: function(data, status, xhr) {
      alert('Failed to post')
    }
  });

}

// Adds divs for each type
//

function islandora_getList() {

  var tabs = $('#tabs').tabs();
  tabs.tabs('select', 3);
  islandora_canvas_params.mappings = new Array();
  $.ajax({
    type: 'GET',
    async: false,
    url: islandora_get_basepath() + islandora_canvas_params.get_annotation_list_url,
    success: function(data, status, xhr) {

      if (data != 'null') {
        var listdata = $.parseJSON(data);
        var pids = listdata.pids;
        var types = listdata.types;

        // create the divs

        if (listdata != null && types != null) {
          for (var i = 0, info; i < types.length; i++) {
            var fixed_cat = types[i].replace(/[^\w]/g, '');
            var type_class = "annoType_" + fixed_cat;
            var blockId = 'islandora_annoType_' + fixed_cat;
            var contentId = 'islandora_annoType_content_' + fixed_cat;
            var idSelector = '#' + blockId;

            if ($(idSelector).length == 0) {

              header = '<div class = "islandora_comment_type" id = "' + blockId + '">';
              header += '<div class = "islandora_comment_type_title">' + types[i] + '</div>';
              header += '<div class = "islandora_comment_type_content" style = "display:none" id = "' + contentId + '"></div>';
              header += '</div>';

              $('#comment_annos_block').append(header);
            }

          }
        }
//populate the divs

        if (listdata != null && pids != null) {
          for (var i = 0, info; i < pids.length; i++) {
            islandora_canvas_params.mappings[pids[i]['urn']] = pids[i]['color']
            var pid = pids[i]['id'];
            $('#canvases .canvas').each(function() {
              // console.log(temp + " " + pid)
              var cnv = $(this).attr('canvas');
              islandora_getAnnotation(pid);
            });

          }
        }

        $(".islandora_comment_type_title").off();

        $(".islandora_comment_type_title").ready().on("click", function() {
          $(this).siblings('.islandora_comment_type_content').toggle();
        });
      }
    },
    error: function(data, status, xhr) {
      // alert('Failed to retrieve List')
    }

  });

}


// get annotation data from Fedora and send it to load_comment_anno to be displayed

function islandora_getAnnotation(pid) {

  $.ajax({
    type: 'GET',
    url: islandora_get_basepath() + islandora_canvas_params.islandora_get_annotation + pid,
    success: function(data, status, xhr) {
      load_commentAnno(data);

    },
    error: function(data, status, xhr) {

    }
  });
}

// deletes annotation from fedora
function islandora_deleteAnno(urn) {

  var selector = '#anno_' + urn;
  $parent = $(selector).closest('.islandora_comment_type');
  length = $parent.find('.canvas_annotation').length;

  if (length == 1) {
    $parent.remove();
  }

  var classSelector = '.svg_' + urn;
  $.ajax({
    type: 'POST',
    url: islandora_get_basepath() + islandora_canvas_params.islandora_delete_annotation + urn,
    data: urn,
    success: function(data, status, xhr) {
      $(selector).next().remove();
      $(selector).remove();
      $(classSelector).remove();

    },
    error: function(data, status, xhr) {
      //   alert('Failed to delete annotation')
    }
  });
}

//updates existing annotations

function islandora_updateAnno(urn, title, annoType, content, color) {
  $.ajax({
    type: 'POST',
    url: islandora_get_basepath() + islandora_canvas_params.islandora_update_annotation,
    data: {
      urn: urn,
      title: title,
      annoType: annoType,
      content: content,
      color: color
    },
    success: function(data, status, xhr) {
      $('#create_annotation_box').hide();
      var selector = '#anno_' + urn;
      var text = $(selector).text().trim().substring(2, 100);
      old_title = $(selector).html();
      new_title = old_title.replace(text, title);

      $(selector).html(new_title);
      $(selector).next('.comment_text').find('.comment_type').text(annoType);
      $(selector).next('.comment_text').find('.comment_content').text(content);
      var fixed_cat = annoType.replace(/[^\w]/g, '');

      $annotation = $(selector).closest('.canvas_annotation');
      $destination = $('#islandora_annoType_content_' + fixed_cat);
      $annotation.appendTo($destination);

    },
    error: function(data, status, xhr) {
      alert('Failed to update annotation')
    }
  });
  $('#create_annotation').empty().append('Annotate');
  $('#create_annotation').css({
    color: '#000000'
  });
}

// Prevents urls starting with double slashes.
function islandora_get_basepath() {
  var basepath = window.parent.Drupal.settings.basePath;
  if (basepath === '/') {
    basepath = '';
  }
  return basepath;
}
{'fraction_non_alphanumeric': 0.16046176046176047, 'fraction_numerical': 0.002886002886002886, 'mean_word_length': 2.7221625492302186, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, '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': '5317458', 'n_tokens_mistral': 3335, 'n_tokens_neox': 3263, 'n_words': 625}