tags:

views:

34

answers:

3

Hello,

Consider I have a plugin "fooPlugin" I attach it to an element like $(element).fooPlugin(); But later, i want to deactivate the plugin. How to deactivate the plugin? Currently, I am using jwysiwyg plugin

I am creating a editor with jwysiwyg plugin and I need to enable the editor when a button is clicked and remove the editor when another button is clicked

Please help!

A: 

There can not be a general method to detach a plugin, who knows what that plugin might have done to nodes, so only that plugin can detach it self e.g.

$(element).fooPlugin() //add
$(element).removeFooPlugin() //remove

So see jwysiwyg docs or ask them, looks like they haven't implemented any destroy or remove methods.

Anurag Uniyal
A: 

I don't think you'll find a universal "deactivate" technique that works across all plugins. jwysiwyg probably attaches event handlers to $(element) and would need to implement its own "deactivate" method. Otherwise, you could open up the source and see which even handlers it attaches and then remove them by hand.

morgancodes
A: 

I haven't looked at the plugin specifically, but what plugins usually do is that they modify the markup and then attach event listeners to it.

For example, a content editor may create a few buttons like "bold", "italic" etc. and then attach a click event to each button. At a click, it will add [b] ... [/b] to a textarea for example which is also given by the defined markup.

What you can do to "deactivate" this plugin, then, is to reset the markup. To do this, first use the jquery remove function to remove all markup that has been created (it should have been put inside a container so it should be easy and quick) and then append again the required markup that you had from the beginning. This markup will not be affected by whatever listeners had been created earlier.

Calle