Forum closed. New forum available at http://community.wymeditor.org/

Using textarea after destroying wymeditor.

Support forum for WYMeditor.

Using textarea after destroying wymeditor.

Postby crank on Mon Jan 04, 2010 1:24 pm

Hello,

in our CMS system, we are using plain text textarea, tinymce and wymeditor for editing content.

I've tuned tinyMCE and now I'm trying to integrate wymeditor. On the screen we have multiple textareas and button for switching between editors. For testing purpose I've commented all tinyMCE stuff and concentrated to wymeditor turn on/off button. It works and according to this post http://forum.wymeditor.org/forum/viewtopic.php?f=2&t=583&p=2067&hilit=destroy&sid=a1ba98e9a7afcd8ed5d5573c99fd0c6f&sid=a1ba98e9a7afcd8ed5d5573c99fd0c6f#p2067 I'm trying to destroy all instances of WYMeditor:

jfh wrote:Following code should help, calling update() and removing WYMeditor instances from the DOM and the instances array:
Code: Select all
jQuery.each(WYMeditor.INSTANCES, function() {
      this.update();
      $(this._box).remove();
      $(this._element).show();
      delete this;
});


The instances disappear, but there is still some event in DOM that prevent from editing and saving plain textarea content - every time the content from destroyed wymeditor appears before submit. Therefore I assume, that the WYMeditor isn't really destroyed. The object WYMeditor has instance.

Please help, I'm begining to be desperate :)

Thanks for any advice.
crank
 
Posts: 4
Joined: Mon Jan 04, 2010 1:16 pm

Re: Using textarea after destroying wymeditor.

Postby mr_lundis on Tue Jan 05, 2010 8:47 pm

Hi crank, and welcome to the forum!
There's an event listener on the submit button, maybe that's the cause of you troubles? If you can't just remove all of the event listeners on that element (.wymupdate by default) then try namespacing the event and remove it that way.

Cheers! ;)
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden

Re: Using textarea after destroying wymeditor.

Postby crank on Wed Jan 06, 2010 10:07 am

Hello :)

Yes, I can call
Code: Select all
$(".wymupdate").unbind("click");
but this will unbind also all other click events, that's bad for me and future of the application. What if I need some other event used outside the editor? For now It's sufficient for using the Wymeditor, bud I'd love some easy-complete-destroying of whole editor and all hooked events.

But maybe there is some other approach to delete particular event.

Sorry, I'm not very specialized into JS a JQuery :).

I'll give it some more time now.

Miroslav
crank
 
Posts: 4
Joined: Mon Jan 04, 2010 1:16 pm

Re: Using textarea after destroying wymeditor.

Postby crank on Wed Jan 06, 2010 10:19 am

Hello,

this is how wymeditor binds the event:
Code: Select all
 
//handle event on update element
  jQuery(this._options.updateSelector)
    .bind(this._options.updateEvent, function() {
      wym.update();
  });


So there is no reference to the function to unbind. Am I right? To unbind particular event I need it's function reference. I can modify wymeditor source, but for next version I'll have to do it again or it'll work some other way?
crank
 
Posts: 4
Joined: Mon Jan 04, 2010 1:16 pm

Re: Using textarea after destroying wymeditor.

Postby mr_lundis on Wed Jan 06, 2010 5:59 pm

An cleaner approach would be to use namespaced events, as I mentioned before. Actually, I don't know why we already do this... :?

Anyway, if you would like to fix this, it's not that hard. What you would need to do is to just update the event bindings and append a namespace to the event name, preferably something like ".wymeditor". I think you should be able to find most of the event binding by a simple search in the code. When you're done, run through the test and make sure everything works. Then post a patch here - or even better - on the trac site, and I'll gladly include you work in the next version of WYMeditor. If you manage to get the destroy function work, include that as well.

Check out the documentation on the jQuery website for more details:
http://docs.jquery.com/Namespaced_Events

Cheers! ;)
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden

Re: Using textarea after destroying wymeditor.

Postby crank on Thu Jan 07, 2010 10:06 am

Ok then, I'll try to contribute. :)
crank
 
Posts: 4
Joined: Mon Jan 04, 2010 1:16 pm

Re: Using textarea after destroying wymeditor.

Postby mr_lundis on Thu Jan 07, 2010 11:32 am

Great! We're always looking for more contributors! :D
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden

Re: Using textarea after destroying wymeditor.

Postby liysd on Sat Apr 24, 2010 2:31 pm

Code: Select all
jQuery.each(WYMeditor.INSTANCES, function() {
      this.update();
      $(this._box).remove();
      $(this._element).show();
      delete this;
});


Code above not really delete - after this operation WYMeditor.INSTANCES will still contain information about this object. You may test with this:
Code: Select all
$.each(WYMeditor.INSTANCES, function() {
   alert(this._index);
});


Do you think it is safe to remove instances with
Code: Select all
WYMeditor.INSTANCES.splice(0,1);
liysd
 
Posts: 7
Joined: Thu Apr 22, 2010 5:07 pm

Re: Using textarea after destroying wymeditor.

Postby mr_lundis on Sat Apr 24, 2010 8:33 pm

The delete operator won't actually delete the object, not even the reference to it.

A simple example:
Code: Select all
jQuery.each(WYMeditor.INSTANCES, function() {
      this.update();
      $(this._box).remove();
      $(this._element).show();
      console.log(delete this);
      console.log(this);
});


This will show the following in the console:
Code: Select all
true
-----------
Object { _index=0, more...}


In other words: the delete statement returns true, but the instance is obviously still there.

The MDC says following:
You can use the delete operator to delete variables declared implicitly but not those declared with the var or the function statement.


In conclusion. The delete operator won't do anything, but removing the instance from the INSCANCES array will certainly get it out of the way for you. However, there might still be other references left to that instance, preventing it from being garbage collected.

Cheers! ;)
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests