0

I am working on a jQuery Editor. I want to capture all changes made in div.
I went through some of stack overflow questions like jquery-listen-to-changes-within-a-div-and-act-accordingly, fire-jquery-event-on-div-change
These questions were used to get information when a change happens, but i need to know details about what are all changes made within a div like any text added or removed and at what position etc.
The position and value is needed so that i can use it for my algorithm

var editorText = $(".jqte_editor").html();
//editorText = "This is a simple editor"
//Convert text into array
var array = editorText.match(/.{1,5}/g);

var newText = "is not";
var position = 2;

//Add new text and again split it if size is more than 5
if(newText.length > 5)
{
    var newArray = abc.match(/.{1,5}/g);

    for(var i=0;i<newArray.length;i++)
    {
            array.splice(position+i, 0, newArray[i]);
    }

    array.splice(pos-1, 1);
}   

console.log("Array after rendering"+array);

So here if i can get newText and position, i can update array easily.

Community
  • 1
  • 1
Abhishek
  • 1,999
  • 5
  • 26
  • 52
  • What do you want to implement? Undo? Versioning? Posting content to the server using diffs? – pawel Sep 26 '13 at 06:56
  • I am writing my own diff algorithm, so need to know where exactly a change happened and what value was changed – Abhishek Sep 26 '13 at 06:59
  • I am converting text into blocks of fixed length and storing it in a linked List. So whenever a change happens, i need position and value so that algorithm goes to particular block using position and updates text – Abhishek Sep 26 '13 at 07:03
  • How about creating a second instance of the list, then comparing these two lists to find changes? Also a bit of code would be helpful, I'm not sure I understand your concept. – pawel Sep 26 '13 at 07:09

0 Answers0