My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
GettingStarted  
Getting started with the TinyAutoSave plugin for TinyMCE.
Featured, Documentation
Updated Nov 19, 2009 by t...@speednet.biz

Getting Started with TinyAutoSave

Installation Instructions

1. Download the .zip file containing the plugin. Copy the tinyautosave folder and all contents within it into the TinyMCE plugins folder.

2. Add the plugin to the TinyMCE plugin option list. For example:

plugins: "tinyautosave"
3. Add the button control name to a toolbar row in the theme. For example:
theme_advanced_buttons1: "tinyautosave,|,cut,copy,paste"

Initialization Example

tinyMCE.init({
	theme: "advanced",
	mode: "textareas",
	plugins: "tinyautosave",
	theme_advanced_buttons1_add: "tinyautosave"
});

Plugin options

tinyautosave_key - String, default = editor id

A string value used to identify the autosave storage and settings to use for the plug instance. If tinyautosave_key is not specified, then the editor's id property is used. If you set the tinyautosave_key for all editors to the same value, that would create a single autosave storage instance and a single set of autosave settings to use with all editors. Because each key maintains its own plugin settings, tinyautosave_key can also be used to apply a different UI or behavior to individual editors. For example, two editors on the same page could use different progress images, or they could autosave at different intervals.
tinyautosave_interval_seconds - Number, default = 60
The number of seconds between automatic saves. When the editor is first displayed, an autosave will not occur for at least this amount of time. This option can also be specified as tinyautosave_interval.
tinyautosave_retention_minutes - Number, default = 20
The number of minutes since the last autosave that content will remain in the rescue storage space before it is automatically expired. This option can also be specified as tinyautosave_retention.
tinyautosave_minlength - Number, default = 50
The minimum number of characters that must be in the editor before an autosave will occur. The character count includes all non-visible characters, such as HTML tags. Although this can be set to 0 (zero), it is not recommended. Doing so would open the possibility that if the user accidentally refreshes the page, the empty editor contents would overwrite the rescue content, effectively defeating the purpose of the plugin.
tinyautosave_oninit - String, default = null
The name of a function to call immediately after the plugin instance is initialized. Can include dot-notation, e.g., myObject.myFunction. The context of the function call (the value of this) is the plugin instance. This function is a good place to set any of the public properties that you want to configure.
tinyautosave_showsaveprogress - Boolean, default = true
When true, the toolbar button will show a brief animation every time an autosave occurs.

Public properties and methods

The following two sections describe the properties and methods of the TinyAutoSave plugin that can be read, set, and called by your own JavaScript code.

Your JavaScript code interacts with the TinyAutoSave plugin "instance" that is created by TinyMCE. They are not static properties and methods. One instance of the plugin is created for each editor displayed on the page. (This is how all plugins work.)

If your code will interact with a TinyAutoSave plugin instance multiple times on the same page, it may be convenient to use the tinyautosave_oninit configuration option (see above) in order to save a reference to the plugin instance. When the function you specify in tinyautosave_oninit is invoked, the value of this will be the plugin instance, so you can easily save a reference to it with a line of code such as:

var tinyautosave = this;

Or, save the reference in a global variable:

window.tinyautosave = this;

Once you have a reference to the plugin, you can interact with it in any way you see fit, setting public properties and calling public methods. For example:

tinyautosave.setProgressImage("/images/spinner.gif");
tinyautosave.progressDisplayTime = 900;

Below, you can find a complete list of the public properties that you can read and set, and the public methods you can call.

Public properties

editor - Object

A reference to the TinyMCE editor instance that contains this TinyAutoSave plugin instance.
url - String
The URL of the folder containing the TinyAutoSave plugin. Does not include a trailing slash.
key - String, default = editor id
A string value identifying the storage and settings for the plugin, as set by tinyautosave_key. Contains the editor id if not specified.
onPreSave - String or Function, default = null
Can be set to the name of a function (String type) or to a function (Function type) that will be called just before each auto-save occurs. The context of the function (the value of this) is set to the editor instance. The function must return a Boolean value indicating if the auto-save is to proceed normally (true) or be canceled (false).
onPostSave - String or Function, default = null
Can be set to the name of a function (String type) or to a function (Function type) that will be called just after each auto-save occurs. The context of the function (the value of this) is set to the editor instance. Any return value from the function is ignored.
onSaveError - String or Function, default = null
Can be set to the name of a function (String type) or to a function (Function type) that will be called every time an error occurs during an auto-save operation. The context of the function (the value of this) is set to the editor instance. Any return value from the function is ignored.
onPreRestore - String or Function, default = null
Can be set to the name of a function (String type) or to a function (Function type) that will be called just before each restore request is carried out. The context of the function (the value of this) is set to the editor instance. The function must return a Boolean value indicating if the restore is to proceed normally (true) or be canceled (false).
onPostRestore - String or Function, default = null
Can be set to the name of a function (String type) or to a function (Function type) that will be called just after each restore request is carried out. The context of the function (the value of this) is set to the editor instance. Any return value from the function is ignored.
onRestoreError - String or Function, default = null
Can be set to the name of a function (String type) or to a function (Function type) that will be called every time an error occurs during a restore operation. The context of the function (the value of this) is set to the editor instance. Any return value from the function is ignored.
progressDisplayTime - Number, default = 1200
Number of milliseconds that the progress image is displayed after an auto-save. The default of 1200 is the equivalent of 1.2 seconds.
showSaveProgress - Boolean, default = true
When true, the toolbar button will show a brief animation every time an autosave occurs. This property is initially set to the value of the tinyautosave_showsaveprogress configuration option, but this property allows the animation to be controlled dynamically.

Public methods

init() - Arguments: Editor instance (Object), URL of plugin folder (String); Return value: none

Called by TinyMCE to initialize the plugin.
getInfo() - Arguments: none; Return value: Information about the plugin (Object)
Called by TinyMCE to retrieve information about the plugin.
clear() - Arguments: none; Return value: none
Clears any auto-saved content currently stored, and "dims" the Restore toolbar button.
hasSavedContent() - Arguments: none; Return value: true if rescue content is available (Boolean)
Returns true if there is auto-save content available to be restored, or false if not.
setProgressImage() - Arguments: Image URL (String); Return value: none
Sets the URL of the image that will be displayed every time an auto-save occurs.

More information

For additional in-depth information about TinyAutoSave, please review the following topics.

  • Overview - Describes the purpose of the plugin
  • Features - Summary of the plugin features
  • Functionality - Functionality provided by the plugin
  • Technology - A discussion of technology used in the plugin
Comment by a.fah...@gmail.com, Jun 1, 2009

Hello, sorry but I know nothing about coding. I am using TInyMCE in my drupal site. I want to know where exactly do I insert these lines of code like the initialization example.

Comment by project member t...@speednet.biz, Jun 1, 2009

You'll have to track down where the tinyMCE.init statement exists in the code. It's a JavaScript? command, so you'll either find it embedded in the page or else in a ".js" file that is referenced in the page. Perhaps you can use a "find" command is whatever development tool you use? Also, you can try posting a question on the TinyMCE forums on their web site. Maybe another Drupal user can guide you. You can find the TinyMCE site by clicking "Project Home" at the top of this page, then click "TinyMCE" in the Links section on the right.

Comment by a.fah...@gmail.com, Jun 9, 2009

OK i think it's the tinymce-3.js file. Here's the part of the code that shows the tinyMCE.init part:

// Initialize editor configurations. for (var format in settings) {
tinyMCE.init(settingsformat?); if (Drupal.settings.wysiwyg.pluginsformat?) {
// Load native external plugins. // Array syntax required; 'native' is a predefined token in JavaScript?. for (var plugin in Drupal.settings.wysiwyg.pluginsformat?['native']) {
tinymce.PluginManager?.load(plugin, Drupal.settings.wysiwyg.pluginsformat?['native']plugin?);
} // Load Drupal plugins. for (var plugin in Drupal.settings.wysiwyg.pluginsformat?.drupal) {
Drupal.wysiwyg.editor.instance.tinymce.addPlugin(plugin, Drupal.settings.wysiwyg.pluginsformat?.drupalplugin?, Drupal.settings.wysiwyg.plugins.drupalplugin?);
}
}
}

};

Can you help with that? :) I will be asking in the forums too, but your prompt reply encouraged me to post here again

Comment by artform...@gmail.com, Dec 4, 2009

Too bad, I can't get it working with TinyMCE nowadays... version 3.2.7 of TinyMCE

Comment by project member t...@speednet.biz, Dec 4, 2009

Please post any problems on the issues list, along with specific problems that are encountered. I have TinyAutoSave? working with 3.2.7 on several sites with no problems -- and the new version of TinyMCE will include this version of TinyAutoSave? as a standard included plugin (renamed to "AutoSave?") -- so it does indeed work great with the latest version of TinyMCE.

Comment by softsh...@gmail.com, Dec 18, 2009

Can TinyAutoSave? be configured to work without the toolbar button ? Like Google Sites, for example.

1) Instead of the toolbar, the text "Autosaved on 7:16 pm" is displayed on the status bar. 2) When the editor's form is submitted, it clears autosaved content. 3) If the form was not submitted, but user came to the page again, it displays a message "The following content was autosaved: Here You Have A Few First Wor... Would you like to restore it ?"

Comment by project member t...@speednet.biz, Dec 18, 2009

@softshape:

Sure, all those things are possible -- you can easily eliminate the toolbar button by not setting the option in the config, and you can do all the messaging things using the built-in events described on this page. That's one of the things that makes TinyMCE such a great text editor platform. It is easily extensible using its rich events model.

Comment by softsh...@gmail.com, Dec 18, 2009

Sorry Todd, but I cannot locate any method to start restore process, to write something like -

if (save1.hasSavedContent()) { save1.restoreSavedContent() }

I see no restoreSavedContent or like that in your API description.

Comment by tnorth...@gmail.com, Dec 18, 2009

Simply execute the command "mceTinyAutoSaveRestore" on the editor to restore the content. That's what the restore button executes. (Check the init() function in the source code if you need to see it in action.)

Comment by softsh...@gmail.com, Dec 20, 2009

That works ! But by some reason always skips the first call. It also shows "saving" message only once (not every 15 secs as stated in settings). I put your modified demo on http://www.irk.fm/tmp/demo/demo.htm, you see two buttons Restore and Clear. Type some text in ed1, wait, then Ctrl+F5 it and press Restore. It never fills ed1 from the first time, you'd need to press it a few times. The code used is -

tinyMCE.execCommand('mceTinyAutoSaveRestore', false, "ed1");

Is it correct ?

Comment by tnorth...@gmail.com, Dec 20, 2009

Sorry, I can't debug people's scripts, but I can tell you that the code that triggers an autosave every "XX" seconds is working correctly and the autosave command itself is working well. So if something is not being triggered properly, it is most likely a problem with the logic in your code. Use all common debugging techniques to trace the source of the problem.

Comment by phillipm...@gmail.com, Apr 16, 2010

how can this be run with 6 text fields?

i have two as 'basic' 4 as 'advanced' - each textarea has unique names -- so this so far, i have not been able to figure out... suggestions?


Sign in to add a comment
Powered by Google Project Hosting