user984003
user984003

Reputation: 29557

TinyMCE UndoManager. Get event to fire

I have made a webform that uses a TinyMCE editor. When the user clicks on a link to leave the page, I want a message to be displayed if he still has unsaved changes. For this, I was thinking of using the TinyMCE undoManager, http://www.tinymce.com/wiki.php/API3:class.tinymce.UndoManager

Essentially, I want the events onAdd, onUndo, OnRedo to fire. I will then keep track of the number of changes (if any) since the last save. But how do I get them to fire? Where do I set them up?

Also, it would be nice to have access to the hasUndo method in the rest of my javascript code. Again, not sure where to initiate this?

Not sure if it matters, but I'm using Django.

Edit: I have tried

tinyMCE.init({
    ...,
    setup : function(ed) {        
        ed.UndoManager.onAdd(function(ed) {   
        ed.windowManager.alert('added.');  
        });
    }      
});

This gives me an error: Unable to get value of the property 'onAdd': object is null or undefined

Upvotes: 2

Views: 2513

Answers (1)

Thariama
Thariama

Reputation: 50832

I created a tinym fiddle for this: http://fiddle.tinymce.com/H0caab . The solution is to use the oninit setting and to addresss the onAdd.add:

tinyMCE.init({
    ...
    setup : function(ed) {

      ed.onInit.add(function(ed) {

        ed.undoManager.onAdd.add(function(ed) {   
           alert('added.');  
        });

      });
    }

});

Upvotes: 1

Related Questions