I just moved over to 4.1, and I'm really excited about this shared spaces feature.
I have a problem with a plugin I've written however. The plugin breaks out into a jqueryUI application via a menu button. Pressing the menu button loses focuses (blur is executed).
Since blur has been run, when I attempt to return data back from the jqueryUI application, I cannot, as there is no "active" or in focus editor.
Apparently a few people are running into this problem, as I found a post about it on stackoverflow - but the technique for dealing with it seems a little brain dead. Basically keep a global variable and track the editor name by updating the global every time you blur. Then upon storing data from your plugin you use the reference from global to submit the data back to the correct editor.
If there was a way to see "most recently focused instance" via the focusManager that would probably help. Maybe there are other ways to do it as well.
My first thought (and I spent a lot of time on it) was to try lock/unlock with the focusManager within my plugin. However the plugin loses logical scope through my jqueryUI application, at which point I once again would need a reference to the editor name.
Ideas here? This technique sucks...
If I understood correctly,
If I understood correctly, you have a button and few editors. This button, when pressed, should perform some action in the recently focused editor. In this case, there's no better way than to listen on focus event in every editor and update reference (it does not have to be a global - you can wrap this in a closure or set as property of some object) to the recently focused editor.
There's of course CKEDITOR.currentInstance but it is set to null when editor is blurred, so it's not a helper for you.
Also, there would be a better solution if you had a button per editor. Then you could add it to focusManager using the #add method, and when this element will gain focus editor won't be blurred, because that element will be a part of editor's UI.
If you want a perfect solution, then you should add this button to active element's focusManager and unregister it (using #remove) on editor blur. This way even when editors will reuse single button, you'll be able to keep editor focused when button gains focus.
And the last solution which came to my mind is preventing default action on button#mousedown event. This will prevent from moving focus to it and you'll be able to get current instance from CKEDITOR.currentInstance. Not a perfect solution though.
Piotrek (Reinmar) Koszuliński
CKEditor JavaScript Developer
--
CKSource - http://cksource.com
--
Follow CKEditor on: Twitter | Facebook | Google+
Thanks for the reply. Yeah
Thanks for the reply. Yeah you understand the problem.
The tool that I am building helps the end user create html email messages. A template is provided to the user, and certain areas of the template allow the user to enter content into the template. Each one of these areas is a CKEditor instance.
Previously I created an instance of CKEditor each time someone clicked, which was slow. I had to do this since shared space was not available when I first implemented it. Basically each time they click a modal window was created, and then the toolbar displayed. There was only 1 editor possible at any given point in time, and when they submit I destroyed the editor. Very slow!
Now I create all the instances at page load time. There can be upwards of 10 at once, but so far no memory issues. However I cannot have 10 toolbars, that is just not usable. Also some of the areas are very small, so having a floating toolbar that displays upon click is no good either. Best option is shared space (which I found through another posting you had made).
Since my design means having just 1 toolbar, and lots of instances this problem arises. I am not the only one with this problem, some other people on stackoverflow have it too - but I guess keeping a reference to the last used is the best way to go.
One idea that I had was to create the a global (or closure) in CKEditor itself, and then have a getter/setter for that. Then I could set the editor name within my CKEditor plugin, and I could simply retrieve the name using the getter. I just don't know how to add something like that to the global CKEditor entity. At least by doing this it moves maintenance of that variable out of my application and into CKEditor where it belongs.
You can extend CKEDITOR
You can extend CKEDITOR object - there already is currentInstance, so you can have activeInstance of similar property.
Piotrek (Reinmar) Koszuliński
CKEditor JavaScript Developer
--
CKSource - http://cksource.com
--
Follow CKEditor on: Twitter | Facebook | Google+