codedance / jquery.AreYouSure

A light-weight jQuery "dirty forms" Plugin - it monitors html forms and alerts users to unsaved changes if they attempt to close the browser or navigate away from the page. (Are you sure?)
508 stars 145 forks source link

Tinymce support? #65

Open nikmauro opened 9 years ago

nikmauro commented 9 years ago

The script not recognize changes from tinymce editor 4

codedance commented 9 years ago

Hi Nikmauro, You may need to trigger are-you-sure to perform a manual check for change. Issue #17 and #62 provide some examples.

https://github.com/codedance/jquery.AreYouSure/issues/17 https://github.com/codedance/jquery.AreYouSure/issues/62

Hope this helps.

amitpatelx commented 8 years ago

Here is how I configure tinyMCE but it doesn't work.

if (typeof tinyMCE != 'undefined') {
          tinyMCE.init({
            selector: "textarea.tinymce",
            toolbar: ["bold italic | styleselect | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"],
            plugins: "image,link,paste",
            menubar: false,
            invalid_elements: "div",
            paste_data_images: true,
            setup: function(ed) { 
              ed.on('change', function(e) { $('#post-form').trigger('checkform.areYouSure'); }); 
              ed.on('keyup', function(e) { $('#post-form').trigger('checkform.areYouSure'); }); 
            }
          });
        } else {
          setTimeout(arguments.callee, 50);
        }
amitpatelx commented 8 years ago

I got a solution which might not optimal but works perfectly.

ed.on('change', function(e) { tinyMCE.triggerSave(); $('#post-form').trigger('checkform.areYouSure'); }); 
ed.on('keyup', function(e) { tinyMCE.triggerSave(); $('#post-form').trigger('checkform.areYouSure'); });
mmichaa commented 8 years ago

Thank you for your post, @AmitPatel-BoTreeConsulting This really helped me! But tweaked the setupfunction a little bit (for my usecase):

function(editor) {
    editor.on('dirty', function(event) {
        editor.save();
        $('.js-dirty-tracking').trigger('checkform.areYouSure');
    });
}

For my usecase this works well. The benefit of using the dirty event ist, that it will be fired only once (at becoming dirty the first time). Maybe I should to say, that I'm using TinyMCE v4.