Get editor reference within editor ajax function?
Get editor reference within editor ajax function?
I'm using Editor with the ajax
property set as a function. Within this function, is there any way to get a reference to the editor instance that called it? I don't think so based on the parameters passed, but maybe someone else has some insight?
(I realize I can declare the editor instance as a global variable, which is what most of the examples do, and what I'm doing now, but there are reasons for wanting to avoid doing this if not necessary.)
This question has accepted answers - jump to:
Answers
You could do:
That would work because the
ajax
function will not be executed during Editor's start up. Thus theeditor
variable will be assigned by the time theajax
function executes, and can be accessed correctly. No need for a global - this works with just the scope of whatever you are building the Editor instance in.Allan
@allan Thanks for the response, that's a concise way to handle the issue and works for me for now; however, I'm working on a quirky platform that doesn't allow for ajax URL's, so I'm envisioning creating a single general ajax function that all of my editor instances call, which then handles the back-end mechanics. It's in this case where I may find it useful to know which instance called the function. Please consider this a feature request for some future version.
(I do realize that even in that case I can do something like the following, so asking the API to pass the editor instance is really just a convenience that makes the code a little cleaner.)
Hi,
I've been mulling this over a bit since your initial question and I think it would be entirely reasonable to expect
this
inside theajax
function to have the scope of the Editor instance - so:would be perfectly valid.
It doesn't do that at the moment, but I will change that for the next release. In the meantime, if you wanted to tweak your local install of Editor for this, find:
and replace with:
which will do the job nicely.
Regards,
Allan
Thanks @allan , you're a rock star! I appreciate how much time you must put into this tool, and its capabilities continue to amaze me.