Thank you for great work. Your solution is what I am looking for. But I develop in ASP.NET and C#. Can you suggest a sample for ASP.NET and C# to use your plugin. Can I use your plugin for many CKEditor instances in one page. Thank you in advance.
This pattern is what exactly I needed I've been looking for this kind of information and thanks be to you that you posted it here. I currently develop site using the ASP.net and any more suggestions in order this to working.
@lsdzung - yes you can use the plugin for more than one editor instance. The plugin uses editor name (http://docs.cksource.com/ckeditor_api/s ... .html#name) so that serverside could distuingish from which editor the request was sent.
Hi Jakub, I was trying your plugin and it works well. What I didn't find is a way how to pass some custom parameters along with the actual editor content. I would need to dynamically pass at least some ID (to update the right content in DB) and a method name (in case ckeditor is used on different places for different purposes). Ideally if I can access the form containing the textarea or any other way. Many thanks!
I thought this was being handled by assigning request params to URL. I thought that my plugin handles all the rest but it does handle it only for GET requests (which probably no one uses) and not for POST.
I think I will treat it as bug and will try to fix it this week. I'm also working on other change suggested by @robC user so I'm not yet sure If I will make two releases or just one.
Although I hate to bring another config option I think that this will be the only solution here. Of course I could tell user to simply add his params to URL in form of queryString but in case of POST request it does not seam right even if plugin could done all the queryString stripping in background.
Thank you for the response. I have to say that I didn't think of the option of configuring the URL within the actual page and adding URL parameters to it dynamically. So that actually solves the problem for me.
I was testing the plugin a bit more and was wondering if there's a way to intercept when content has been saved, e.g. via an event handler. So i can display a message to the user (in addition to the tick symbol). Something on the lines of :
CKEDITOR.instances.editor_id.on('autosave', ...)
I also haven't found a way to fire the autosave plugin using a shortcut. For standard save I've been able to configure Ctrl+S this way:
I've just found another thing. It seems that the autosave plugin breaks the checkDirty functionality. When using the plugin, the function always returns false even if there are changes. If I remove the plugin from config.extraPlugins then the checkDirty starts working properly again.
Thank you for the response. I have to say that I didn't think of the option of configuring the URL within the actual page and adding URL parameters to it dynamically. So that actually solves the problem for me.
There was no code to handle extra parameters so I think new config option is something that allows for adding new (even generated) parameters without modifying the code.
I was testing the plugin a bit more and was wondering if there's a way to intercept when
No, plugin does not fire it's own event. This is however something to consider. I'm not sure though when to fire such event. The content is being saved in asynchronous way - in callback function... it's to late. The first thing that comes to my mind is just before making AJAX request call.
So i can display a message
But plugin displays it's own messages in form of tooltip. Just hover the cross or tick and you will see. You can also change/add new messages.
I also haven't found a way to fire the autosave plugin using a shortcut.
Plugin does not have such option, yet again this is something to consider.
It seems that the autosave plugin breaks the checkDirty functionality.
It does not break it. It uses it. I guess that this is the main drawback of this plugin - checking and resetting dirty state. As I was saying in previous post I'm working on a way to change it but I'm not sure if this will work.
I'm not sure though when to fire such event. The content is being saved in asynchronous
Well there can be both events, although I think the more useful one is callback - that means the content has been actually saved. Like in Google Docs you have "All changes saved" message.
plugin displays it's own messages in form of tooltip
The tick / cross icons are really nice but a normal user might not understand that. I'd like to show my own messages to ensure the user the content has been saved successfully.
I also haven't found a way to fire the autosave plugin using a shortcut.
I thought that ckeditor itself is handling that. Anyway that would be very useful if shortcuts could trigger autosave. Many users (incl. me) have the habit of using Ctrl+S when writing longer documents:-)
It does not break it. It uses it. I guess that this is the main drawback of this plugin - checking and resetting dirty state.
I see you're resetting in order to count changes. Wouldn't it be enough to count key presses? Surely, you'll miss using mouse events changing the style for example but I think the main proportion of editing a document will still be key presses.
Thanks for your response and also thanks for the work on this plugin, it's one of the most useful ones in CKEditor!
I have thought about it a while and come to the same solution. Plugin could fire two events - beforeAutosave (before sending request) and afterAutosave (when saving was done).
Messages: Before you implement your own messages pleas bear in mind that this plugin has it's own "messaging system". Please also have a look at manual as it IMO explains it well. Just to give a quick summary - when contents were saved - message with time when it happened is displayed. When error occurs either message from server or plugin predefined one is displayed. To see the message you have to put mouse cursor over the icon.
Shotcut - Sorry it was quite late when I was reading and writing it:). Yes, this should be handled. I will check if there are any problems with it.
Wouldn't it be enough to count key presses?
- There are other events fired by dialog, non-dialog plugins, by undo/redo, fired in source-mode etc. Plugin registering only some changes and not all of them? Hmmm... I just don't see it, sorry. Anyway I have started to think of other way to handle saves. Method would be more intelligent and eventually could let me drop changes counter, interval and using dirty mechanism but this part might take some time as this change is quite big and to be honest it's back to the drawing board for me
Anyway I have started to think of other way to handle saves
I guess one way would be to keep a version of the document and comparing the current version to it and detect changes. Although that might be expensive. A good compromise might be to store the document length from last check and check against it like this:
var currentLength = getCurrentLength(); // just a mock method
if ( lastLength != currentLength )
{
autosaveCounter++ ;
lastLength = currentLength;
// change Icon to saveDirty
autosaveChangeIcon( editor, autosaveIcons[1].path,
autosaveIcons[1].title );
}
It's just my guess because i'm not aware of the inner logic of the plugin that much, but do you think it might work or is there some catch to it?
Simple catch. Let's say you have 'abc' in your editor and you change it to 'aac'. Length is the same but contents have changed. Length is just one 'component' that could be used here.
That's true, but that's only when the user selects one character and replace it with another and how often does that happen? Surely there are some other cases but 99% interactions will change the length which might be good enough. You can then even count how many characters were added / removed and fire autosave based on that. Cause with checking checkDirty there's no difference between typing one character and pasting 1000 characters. But anyway, that's just my suggestion.
New version of plugin with some small (but important) changes proposed by @petr82 was released.
It is now possible to define user specific request parameters, assign key shortcut to autosave button and execute user specific functions on two events fired by the plugin.
- There are other events fired by dialog, non-dialog plugins, by undo/redo, fired in source-mode etc. Plugin registering only some changes and not all of them? Hmmm... I just don't see it, sorry. Anyway I have started to think of other way to handle saves. Method would be more intelligent and eventually could let me drop changes counter, interval and using dirty mechanism but this part might take some time as this change is quite big and to be honest it's back to the drawing board for me
I actually have used code of your method. It showed me places I have missed. Now this pluging catches everything but the main problem is that some events, especially 'saveSnapshot', are fired to offten E.g. when you insert an Image 'saveSnapshot' gets fired 5 times. In fact all that is need here is that one time when change was actually made – it is important so that plugin didn’t send unchanged code and to manage “dirty icon” correctly. That is why I had to add this extra check to see if editor was "really dirty".
For ASP.Net, you can capture the output of this with a simple Generic Handler.
Right-Click your project > Add New Item... > Generic Handler Give it a name of AutoSave.ashx.
Replace all the code with whichever flavor below you like:
<%@ WebHandler Language="VB" Class="AutoSave" %>
Public Class AutoSave
Implements IHttpHandler, IRequiresSessionState
Public Sub ProcessRequest(ByVal context As HttpContext) _
Implements IHttpHandler.ProcessRequest
' Do something with the data
IO.File.WriteAllText("d:\path\to\save\content.txt", _
context.Request.Form("Content").ToString)
context.Response.Clear()
context.Response.ContentType = "text/xml;charset=UTF-8"
context.Response.StatusCode = 200
context.Response.Write("<result status=""ok"" />")
context.Response.Flush()
End Sub
Public ReadOnly Property IsReusable() As Boolean _
Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
I'm using Backbone.js so when autosave fires, I only want the Autosave plugin to call my custom callback (not fire off any HTTP requests on its own). Would that be possible without hacking in to your code?
Something like:
$('#editor').ckeditor(config).ckeditorGet().on('autosave', function(event) {
// Backbone Model .save() method will take care of hitting my API
event.editor.config.model.save({content: event.editor.getData()});
// return true/false so the plugin knows if saving was successful
return true;
});
j.swiderski wrote:@chrisbraddock - it sounds to me like you only want to know when something got changed in the editor and then fire your own custom code.
You can configure the onChange plugin with something like config.minimumChangeMilliseconds=1000 to fire the change event at most one per second. And it doesn't take into account just keypresses but it tries to detect any change to the content (formatting, inserting elements, etc...)
alfonsoml wrote:You can configure the onChange plugin with something like config.minimumChangeMilliseconds=1000 to fire the change event at most one per second. And it doesn't take into account just keypresses but it tries to detect any change to the content (formatting, inserting elements, etc...)
Ooh nice. I hadn't considered the formatting stuff. I'll give the onChange plugin another go. Thanks
This plugin is exactly what I want. Thanks! I have an odd behavior in Internet Explorer (9.0.8112.16421). When pressing any CKeditor button (e.g. Bold or Italic), the plugin shows the message about abandon the page: "You will lose changes you have made in the editor since last save". Both Firefox and Chrome works without any problem. To warn if there are unsaved modifications is a great functionality, so I wouldn't want to disable it.
Thanks for the post. I didn't reply as I didn't get any notification about it, sorry.
@ leocofre I have just tried this plugin and didn't get behaviour you were talking about. Could you perhaps send me private message explaining in more detail how you are getting this problem.
Please check the readme file. All is written there.
Please also note that under this URL config.autosaveTargetUrl = 'http://mywebsite.fr/media/autosave/save/'; you must have server-side code that will take data from editor and return proper response. This is AJAX plugin - it works with server side code.
Aren't you getting any errors in Firebug console or net tab? I assume you may be getting JS errors or 404 HTTP error. BY installing plugin correctly (not just Java Script, server code is also important) you should be able to work them out.
j.swiderski wrote:@ leocofre I have just tried this plugin and didn't get behaviour you were talking about. Could you perhaps send me private message explaining in more detail how you are getting this problem.
Re: Ajax Autosave
Your solution is what I am looking for. But I develop in ASP.NET and C#.
Can you suggest a sample for ASP.NET and C# to use your plugin.
Can I use your plugin for many CKEditor instances in one page.
Thank you in advance.
Re: Ajax Autosave
Re: Ajax Autosave
@lsdzung - yes you can use the plugin for more than one editor instance. The plugin uses editor name (http://docs.cksource.com/ckeditor_api/s ... .html#name) so that serverside could distuingish from which editor the request was sent.
About
Re: AJAX Autosave \ AJAX Save
@lsdzung thanks for idea on how to improve this plugin.
Re: Autosave \ Manual Save with AJAX
Re: Autosave \ Manual Save with AJAX
I thought this was being handled by assigning request params to URL. I thought that my plugin handles all the rest but it does handle it only for GET requests (which probably no one uses) and not for POST.
I think I will treat it as bug and will try to fix it this week. I'm also working on other change suggested by @robC user so I'm not yet sure If I will make two releases or just one.
Although I hate to bring another config option I think that this will be the only solution here. Of course I could tell user to simply add his params to URL in form of queryString but in case of POST request it does not seam right even if plugin could done all the queryString stripping in background.
@petr82 what do you think?
Re: Autosave \ Manual Save with AJAX
I was testing the plugin a bit more and was wondering if there's a way to intercept when content has been saved, e.g. via an event handler. So i can display a message to the user (in addition to the tick symbol). Something on the lines of :
I also haven't found a way to fire the autosave plugin using a shortcut. For standard save I've been able to configure Ctrl+S this way:
But if a try to change 'save' for 'autosave' or 'Autosave' it doesn't work. Could you please try if this also doesn't work for you.
Re: Autosave \ Manual Save with AJAX
Re: Autosave \ Manual Save with AJAX
There was no code to handle extra parameters so I think new config option is something that allows for adding new (even generated) parameters without modifying the code.
No, plugin does not fire it's own event. This is however something to consider. I'm not sure though when to fire such event. The content is being saved in asynchronous way - in callback function... it's to late. The first thing that comes to my mind is just before making AJAX request call.
But plugin displays it's own messages in form of tooltip. Just hover the cross or tick and you will see. You can also change/add new messages.
Plugin does not have such option, yet again this is something to consider.
It does not break it. It uses it. I guess that this is the main drawback of this plugin - checking and resetting dirty state. As I was saying in previous post I'm working on a way to change it but I'm not sure if this will work.
Re: Autosave \ Manual Save with AJAX
The tick / cross icons are really nice but a normal user might not understand that. I'd like to show my own messages to ensure the user the content has been saved successfully.
I thought that ckeditor itself is handling that. Anyway that would be very useful if shortcuts could trigger autosave. Many users (incl. me) have the habit of using Ctrl+S when writing longer documents:-)
I see you're resetting in order to count changes. Wouldn't it be enough to count key presses? Surely, you'll miss using mouse events changing the style for example but I think the main proportion of editing a document will still be key presses.
Thanks for your response and also thanks for the work on this plugin, it's one of the most useful ones in CKEditor!
Re: Autosave \ Manual Save with AJAX
I have thought about it a while and come to the same solution. Plugin could fire two events - beforeAutosave (before sending request) and afterAutosave (when saving was done).
Messages: Before you implement your own messages pleas bear in mind that this plugin has it's own "messaging system". Please also have a look at manual as it IMO explains it well.
Just to give a quick summary - when contents were saved - message with time when it happened is displayed.
When error occurs either message from server or plugin predefined one is displayed.
To see the message you have to put mouse cursor over the icon.
Shotcut - Sorry it was quite late when I was reading and writing it:). Yes, this should be handled. I will check if there are any problems with it.
- There are other events fired by dialog, non-dialog plugins, by undo/redo, fired in source-mode etc. Plugin registering only some changes and not all of them? Hmmm... I just don't see it, sorry.
Anyway I have started to think of other way to handle saves. Method would be more intelligent and eventually could let me drop changes counter, interval and using dirty mechanism but this part might take some time as this change is quite big and to be honest it's back to the drawing board for me
Re: Autosave \ Manual Save with AJAX
It's just my guess because i'm not aware of the inner logic of the plugin that much, but do you think it might work or is there some catch to it?
Re: Autosave \ Manual Save with AJAX
Re: Autosave \ Manual Save with AJAX
Re: Autosave \ Manual Save with AJAX
It is now possible to define user specific request parameters, assign key shortcut to autosave button and execute user specific functions on two events fired by the plugin.
@petr82 thanks for the tips.
Re: Autosave \ Manual Save with AJAX
Re: Autosave \ Manual Save with AJAX
Re: Autosave \ Manual Save with AJAX
That is why I had to add this extra check to see if editor was "really dirty".
Re: Autosave \ Manual Save with AJAX
For ASP.Net, you can capture the output of this with a simple Generic Handler.
Right-Click your project > Add New Item... > Generic Handler
Give it a name of AutoSave.ashx.
Replace all the code with whichever flavor below you like:
Autosave, callback only
Hey this plugin looks great.
I'm using Backbone.js so when autosave fires, I only want the Autosave plugin to call my custom callback (not fire off any HTTP requests on its own). Would that be possible without hacking in to your code?
Something like:
Re: Autosave \ Manual Save with AJAX
@chrisbraddock - it sounds to me like you only want to know when something got changed in the editor and then fire your own custom code.
If that's the case then what you really need is the onChange event part from the plugin. You're in luck because such event was created by @alfonsoml. You can find it on this forum and on his blog:
viewtopic.php?f=18&t=23605
http://alfonsoml.blogspot.com/2011/03/o ... ditor.html
Is this something you were looking for or my plugin has something more that you also need?
Re: Autosave \ Manual Save with AJAX
Re: Autosave \ Manual Save with AJAX
And it doesn't take into account just keypresses but it tries to detect any change to the content (formatting, inserting elements, etc...)
Re: Autosave \ Manual Save with AJAX
Ooh nice. I hadn't considered the formatting stuff. I'll give the onChange plugin another go. Thanks
Re: Autosave \ Manual Save with AJAX
I have an odd behavior in Internet Explorer (9.0.8112.16421). When pressing any CKeditor button (e.g. Bold or Italic), the plugin shows the message about abandon the page: "You will lose changes you have made in the editor since last save". Both Firefox and Chrome works without any problem.
To warn if there are unsaved modifications is a great functionality, so I wouldn't want to disable it.
Thanks in advance for any hint!
Re: Autosave \ Manual Save with AJAX
@ leocofre I have just tried this plugin and didn't get behaviour you were talking about.
Could you perhaps send me private message explaining in more detail how you are getting this problem.
Re: Autosave \ Manual Save with AJAX
Hello,
Above all, Thanks for your work and your sharing.
I am new to plugin installation.
Sorry for my english google translation. I am French. : s
I downloaded the archive:
http://code.google.com/p/ckeditor-ajax- ... _1.0.2.zip
I put the autosave folder in the ckeditor plugins folder ...
I added the lines in the config.js file of ckeditor:
Re: Autosave \ Manual Save with AJAX
Please check the readme file. All is written there.
Please also note that under this URL config.autosaveTargetUrl = 'http://mywebsite.fr/media/autosave/save/';
you must have server-side code that will take data from editor and return proper response.
This is AJAX plugin - it works with server side code.
Aren't you getting any errors in Firebug console or net tab? I assume you may be getting JS errors or 404 HTTP error. BY installing plugin correctly (not just Java Script, server code is also important) you should be able to work them out.
Re: Autosave \ Manual Save with AJAX
Re: Autosave \ Manual Save with AJAX
config.forcePasteAsPlainText = true;
And then I try to make a "paste" in the editor, this results in duplicate information.