<commit_before>var pageEditor = {
    event: 0 , //Use this var to store the event object, which will be passed for editor.
    m4pageedittype: '',
    savedHtml: '',
    startEdit: function(event)
    {
	event.stopPropagation();
	event.preventDefault();
	pageEditor.event = event;
	pageEditor.m4pageedittype = $(event.target).attr('m4pageedittype');
	$('*').removeClass('highlightOnSelect');
	if($(event.target).attr('m4pageedittype') == 'text')
	{
	    $(event.target).addClass('highlightOnSelect'); // To show selected element

	    $('#edit-text').show();	    
	    $('#add-audio').show();
	    $('#replace-image').hide();
	    $('#delete-image').hide();

	    $('#pub_overlay').slideDown();
	    $('#element_edit_overlay').slideDown();
	    
	    // At this point 'displayEditor' function will be performed on click of 'Edit Text' button
	    // displayEditor function is in ui.js file
	}
	else if($(event.target).attr('m4pageedittype') == 'image')
	{
	    $(event.target).addClass('highlightOnSelect'); // To show selected element

	    $('#replace-image').show();
	    $('#delete-image').show();
	    $('#add-audio').hide();
	    $('#edit-text').hide();

	    $('#element_edit_overlay').slideDown();
	    $('#pub_overlay').slideDown();
	    // At this point 'imageReplacer' function will be performed on click of 'Replace Image' button
	    // imageReplacer function is in ui.js
	} else {
	    $('#element_edit_overlay').slideUp();

	    $('#edit-text').hide();
	    $('#add-audio').hide();
	    $('#replace-image').hide();
	    $('#delete-image').hide();
	}
    },
    // addLink: function(){
    // 	$(pageEditor.event.target).mouseup(pageEditor.handler);
    // },
    handler: function()
    {
	var sel = window.getSelection();
	y = sel.anchorOffset;
	z = sel.focusOffset;
	if(y != z)
	{
	    pageEditor.savedHtml = $('#editor').html();
	    var url = prompt("Enter url");
	    sel.anchorNode.textContent = sel.anchorNode.textContent.substr(0,y)+'<a href="'+url+'">'+sel.anchorNode.textContent.substr(y,z-y)+"</a>"+sel.anchorNode.textContent.substr(z);
	    abc = $('#editor').html();
	    abc = abc.replace(/(&lt;)/g,'<');
	    abc = abc.replace(/(&gt;)/g,'>');
	    $('#editor').html(abc);
	    // manager.updateText(pageEditor.event.target);
	    //$(pageEditor.event.target).unbind('mouseup', pageEditor.handler);
	}
	else{
	    //
	}
    },
    
    addAudio: function(){
	url = prompt("enter an .ogg audio link");
	if(url.substr(-4) =='.ogg'){
	    manager.recordAudio(pageEditor.event.target);
	}
	else{
	}
    },

    deleteImage: function(){
	manager.deleteImage(pageEditor.event.target);
	pageEditor.cleanUp(pageEditor.event.target);
    },
    
    cleanUp: function(element)
    {
	if(util.hasChangesPending()) {
	    $('#undo-button').button('option', 'disabled', false); // Another way of enabling UI-JQUERY button
	    $('#publish-button').button({ disabled: false}); // Enabling UI-JQUERY button
	} else {
	    $('#undo-button').button({ disabled: true}); // Disabling button
	    $('#publish-button').button({ disabled: true}); // Disabling button
	}

	$(element).attr('m4pageedittype', pageEditor.m4pageedittype);
	$(element).children().attr('m4pageedittype', pageEditor.m4pageedittype);

	$(document).mouseover(a11ypi.highlightOnHover);
	$(document).mouseout(a11ypi.unhighlightOnMouseOut);
//	$(event.target).removeClass('highlightOnSelect'); // Remove highlighted selected element
    },
};

var DOM = {
    getXpath : function (element)
    {
	var str = '';
	var currentNode = element;
	var path = '';
	var index = -1;

	if (currentNode.nodeName != "#text")
	{
	    path = DOM.makePath(currentNode);
	}
	else
	{
	    path = DOM.makePath(currentNode.parentNode);
	}

    	
	return path;
    },
    getElementIdx : function getElementIdx(elt)
    {
	var count = 1;
	for (var sib = elt.previousSibling; sib ; sib = sib.previousSibling)
	{
	    if(sib.nodeType == 1 && sib.tagName == elt.tagName)count++
	}
	
	return count;
    },
    
    makePath : function makePath(elt){
	if(elt.tagName != 'IMG')
	    elt = elt.parentNode;
    	var path = '';
	for (; elt && elt.nodeType == 1; elt = elt.parentNode)
	{
	    if(elt.id == "")
	    {
		idx = DOM.getElementIdx(elt);
		xname = elt.tagName;
		if (idx > 1) 
		    xname += "[" + idx + "]";
		path = "/" + xname + path;
	    }<commit_msg>Xpath was being calculated wrongly<commit_after>var pageEditor = {
    event: 0 , //Use this var to store the event object, which will be passed for editor.
    m4pageedittype: '',
    savedHtml: '',
    startEdit: function(event)
    {
	event.stopPropagation();
	event.preventDefault();
	pageEditor.event = event;
	pageEditor.m4pageedittype = $(event.target).attr('m4pageedittype');
	$('*').removeClass('highlightOnSelect');
	if($(event.target).attr('m4pageedittype') == 'text')
	{
	    $(event.target).addClass('highlightOnSelect'); // To show selected element

	    $('#edit-text').show();	    
	    $('#add-audio').show();
	    $('#replace-image').hide();
	    $('#delete-image').hide();

	    $('#pub_overlay').slideDown();
	    $('#element_edit_overlay').slideDown();
	    
	    // At this point 'displayEditor' function will be performed on click of 'Edit Text' button
	    // displayEditor function is in ui.js file
	}
	else if($(event.target).attr('m4pageedittype') == 'image')
	{
	    $(event.target).addClass('highlightOnSelect'); // To show selected element

	    $('#replace-image').show();
	    $('#delete-image').show();
	    $('#add-audio').hide();
	    $('#edit-text').hide();

	    $('#element_edit_overlay').slideDown();
	    $('#pub_overlay').slideDown();
	    // At this point 'imageReplacer' function will be performed on click of 'Replace Image' button
	    // imageReplacer function is in ui.js
	} else {
	    $('#element_edit_overlay').slideUp();

	    $('#edit-text').hide();
	    $('#add-audio').hide();
	    $('#replace-image').hide();
	    $('#delete-image').hide();
	}
    },
    // addLink: function(){
    // 	$(pageEditor.event.target).mouseup(pageEditor.handler);
    // },
    handler: function()
    {
	var sel = window.getSelection();
	y = sel.anchorOffset;
	z = sel.focusOffset;
	if(y != z)
	{
	    pageEditor.savedHtml = $('#editor').html();
	    var url = prompt("Enter url");
	    sel.anchorNode.textContent = sel.anchorNode.textContent.substr(0,y)+'<a href="'+url+'">'+sel.anchorNode.textContent.substr(y,z-y)+"</a>"+sel.anchorNode.textContent.substr(z);
	    abc = $('#editor').html();
	    abc = abc.replace(/(&lt;)/g,'<');
	    abc = abc.replace(/(&gt;)/g,'>');
	    $('#editor').html(abc);
	    // manager.updateText(pageEditor.event.target);
	    //$(pageEditor.event.target).unbind('mouseup', pageEditor.handler);
	}
	else{
	    //
	}
    },
    
    addAudio: function(){
	url = prompt("enter an .ogg audio link");
	if(url.substr(-4) =='.ogg'){
	    manager.recordAudio(pageEditor.event.target);
	}
	else{
	}
    },

    deleteImage: function(){
	manager.deleteImage(pageEditor.event.target);
	pageEditor.cleanUp(pageEditor.event.target);
    },
    
    cleanUp: function(element)
    {
	if(util.hasChangesPending()) {
	    $('#undo-button').button('option', 'disabled', false); // Another way of enabling UI-JQUERY button
	    $('#publish-button').button({ disabled: false}); // Enabling UI-JQUERY button
	} else {
	    $('#undo-button').button({ disabled: true}); // Disabling button
	    $('#publish-button').button({ disabled: true}); // Disabling button
	}

	$(element).attr('m4pageedittype', pageEditor.m4pageedittype);
	$(element).children().attr('m4pageedittype', pageEditor.m4pageedittype);

	$(document).mouseover(a11ypi.highlightOnHover);
	$(document).mouseout(a11ypi.unhighlightOnMouseOut);
//	$(event.target).removeClass('highlightOnSelect'); // Remove highlighted selected element
    },
};

var DOM = {
    getXpath : function (element)
    {
	var str = '';
	var currentNode = element;
	var path = '';
	var index = -1;

	if (currentNode.nodeName != "#text")
	{
	    path = DOM.makePath(currentNode);
	}
	else
	{
	    path = DOM.makePath(currentNode.parentNode);
	}

    	
	return path;
    },
    getElementIdx : function getElementIdx(elt)
    {
	var count = 1;
	for (var sib = elt.previousSibling; sib ; sib = sib.previousSibling)
	{
	    if(sib.nodeType == 1 && sib.tagName == elt.tagName)count++
	}
	
	return count;
    },
    
    makePath : function makePath(elt){
	var path = '';
	for (; elt && elt.nodeType == 1; elt = elt.parentNode)
	{
	    if(elt.id == "")
	    {
		idx = DOM.getElementIdx(elt);
		xname = elt.tagName;
		if (idx > 1) 
		    xname += "[" + idx + "]";
		path = "/" + xname + path;
	    }
{'fraction_non_alphanumeric': 0.1945996275605214, 'fraction_numerical': 0.004888268156424581, 'mean_word_length': 3.3115905669844454, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4480092', 'n_tokens_mistral': 2952, 'n_tokens_neox': 2842, 'n_words': 526}