Is autosave support limited to the default Drupal textarea and FCKEditor? If yes, then that would explain the following observations with the tinyMCE module installed on my site.

After setting up autosave with default settings for all content types, a new node autosaves only once. When editing a published node, autosave does not seem to occur.

Comments

erikringmar’s picture

Hi there, it would be good to get some feedback on this. I have the same problem. With TinyMCE installed (well, Moxie, actually) it saves only new modes, not edited old ones. (I lost some work today when the server went down and I was hoping there'd be a back-up -- but nada).

yours,

Erik

erikringmar’s picture

Title: tinyMCE Support » tinyMCE Support -- additional point

Hi again,

I just discovered that the problem seems to be fixed when I add the "texy" input filter. Why this would be is beyond me.

yours,

Glottus’s picture

Version: 5.x-1.1 » 5.x-1.2
Priority: Normal » Critical

I have the same behavior. Autosave does not seem to recognize TinyMCE edit areas (similar to the FCK problem that was fixed?). I don't think installing the texy input filter is going to be an option for me, and I don't plan to change over to the FCK editor at this point either.

Am I missing something here? This would be a critical improvement to my site, but I just can't get it to work with TinyMCE. I see that autosave is kicking in nicely when I edit the title of a page or other node, but NOT when I'm working in an TinyMCE edit area, so I know this is the source of the issue.

maz-1’s picture

Title: tinyMCE Support -- additional point » tinyMCE Support -- additional point (SOLUTION)

tinyMCE provides no documented way to implement a callback after it has been initialized. As a result, a small change to the tinymce module has to be made. Not sure if this is the correct way to implement this, if it's not, I would appreciate know what is the correct way.

In: modules/tinymce/tinymce.module
at: around line 114 before: $enable = t('enable rich-text')
add the following lines:
if(module_exists('autosave')) {
$settings[] = 'onchange_callback : "autosave_tinymce"';
}

In: modules/autosave/autosave.js
at: around line 48 before: $('form#node-form').ajaxSubmit(options);
Add the following lines:
if(tinyMCE) {
tinyMCE.triggerSave(false,true);
}

At the end of: modules/autosave/autosave.js
add the following lines:
function autosave_tinymce() {
changed = true;
}

jochenh’s picture

I am also using tinyMCE on a site where a client has requested auto-save capabilities. Even after somewhat blindly inserting the additional function calls as outlined above I still can't get this to work...

btully’s picture

any update on whether anyone actually has this working with Drupal 5.x on a node using TinyMCE for the body?

btully’s picture

maz -

thanks a bunch for your work in getting autosave to recognize the TinyMCE fields. I think we're close.

When I create a new node, the autosave seems to work fairly well in that it recognizes all TinyMCE fields (i'm using several on the page).

However, when I edit an existing node, and am modifying the content of a TinyMCE field, the autosave does not get triggered. It does if I put the focus on a non TinyMCE area and change the value there.

Any idea why the changes in TinyMCE fields are not triggering the autosave when editing an existing node?

thanks again!

edmund.kwok’s picture

I'll look into getting autosave working for TinyMCE after Dec 14th. Thanks.

btully’s picture

thanks edkwh! with the above patches i've been able to get the autosave to work with TinyMCE.

however it's not elegant in how it handles the autosave from a user perspective. what happens is the save occurs while a user is typing in the tinymce field, and then the cursor gets placed at the beginning of the field after the save is complete, which means that while the user is typing the cursor jumps and the user thinks something is broken.

ideally some type of warning/animated gif would appear notifying them that autosave is about to run and/or the cursor could be placed back to where it was before the save occurred to make it less jarring. I'm pretty sure there's a function within TinyMCE to get the current cursor position, so maybe within the onchange_callback the cursor position can be saved as a var, the save gets triggered and then the cursor is placed back?

otherwise if this is to complex, maybe we need to make the textarea readonly while the save occurs?

edmund.kwok’s picture

Status: Active » Needs review

Hi,

I think maz's way is the best way to go for now. Not sure if TinyMCE has a global onChange callback function like FCKeditor. The following should be the simplest way to get autosave working with TinyMCE. I don't think it's appropriate to submit a patch for TinyMCE module in this queue so just make these changes:

In tinymce.module, at around line 121, replace:

  tinyMCE.init({
    $tinymce_settings
  });

With:

  tinyMCE.init({
    $tinymce_settings,
    onchange_callback : function() { tinyMCE.triggerSave(); changed = true; },
  });

Btw, I don't seem to have problems with the cursor moving to the beginning of the field every time autosave gets triggered. Try the above change and see if the cursor is still a problem.

btully’s picture

hey there edkwh -

thanks a bunch for your suggestion and for your commitment to getting this working with TinyMCE. :)

However if i make the change within tinymce.module, won't that then apply the function to every TinyMCE instance, regardless of node type?

Would one be able to apply this via a theme_tinymce_theme function in template.php?

e.g.,

function mytheme_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {

  switch ($textarea_name) {

    case 'edit-body':
    case 'edit-comment';
      $init['theme'] = 'advanced';
      break;

    default:
      unset($init);
  }

  if (isset($init)) {
    switch ($theme_name) {
      case 'advanced';
        $init['onchange_callback'] = 'function() { tinyMCE.triggerSave(); changed = true; }';
        break;
    }
  }
  return $init;
}

Also, regarding the jumping cursor, the page we're using autosave on has multiple TinyMCE textarea fields. Might that have something to do with it? Or did the page you tried it on successfully also have more than one TinyMCE instance?

Thanks again for your help on this!

liquidcms’s picture

open a new issue for Tiny support with 5.2 version (saved forms, not nodes) of autosave.

itman’s picture

Hi,
yes it IS the problem, at least in some browsers. I would suggest removing tinyMCE.triggerSave. It seems to work without it and the cursor is not moving.

liquidcms’s picture

btw - i fixed the autosave module (ver 5.2) to work with TinyMCE a few wks ago. This includes the jumping cursor issue and couple other issues.

see: http://drupal.org/node/207902

itman’s picture

BTW, the last comma is extra: it causes a JS error in some browsers, including Opera.

pdxrod’s picture

Thanks....
tinyMCE.init({
... various tinymce settings...
onchange_callback : function() { tinyMCE.triggerSave(); changed = true; },
});
worked for me in a Rails project... http://pdxspurs.com

GiorgosK’s picture

It can grab wysiwyg tinyMCE content but it can not place it on it later on

it can add it on the textarea if you "disable rich-text" but not when its enabled

liquidcms’s picture

the 5.x version of autosave works with Dr5 and Tiny 2.x - i know someone has provided a port for Dr6 but not sure how well tested it is (i have not tested it).

I am currently working on redoing existing 6.x version of autosave to work with wysiwyg module and hopefully little or no dependency on the specific editor (maybe not possible) - but, if there is dependencies my first work will be with Tiny 3.x. Hopefully finish this up in next week or so.