2

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!

1

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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.

Comments

0

As mentioned by others, there isn't a standard way of doing this as the plugin could be doing all manner of things (and all plugins are different). You will need to edit the plugin.

I have come across this very same problem and found that this works for very simple plugins:

Give the body element a class e.g. ".pluginActivated". Edit the plugin so that before it does anything, it checks if the body has that class.

Now you can remove the .pluginActivated class from the body and the plugin will hopefully stop working on the element.

e.g. the plugin may start with

return this.each(function(){

Just add an if function directly underneath, before any code where the plugin starts doing stuff that you want to 'deactivate':

if ($("body").hasClass("pluginActivated")){

(and remember to close off the curly brackets with a } at the end).

Now this has other issues: the plugin is not truly deactivated, it will still check for the body class when fired, but at least it may have the desired effect of not being bound to your specified element.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.