MyBB Community Forums

Full Version: Deactivating Modification and remove jquery
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello,

I was wondering what would be the best approach to remove a jquery from the headerinclude template. I wouldn't want to remove the jquery library if another modification is using it. Is there a way to tell if another modification is using it? I don't want to just remove it and then render another modification unusable. I am just looking for the best approach to adding jquery without having it added twice, by having multiple modifications including their own and removing it without cause another modification not to work.

Suggestions?

One thing I was thinking was putting comment tags around it and doing a search to see if it is already included. When uninstalling/deactivating using the find_replace_templatesets() to see if it has the comment tags around it. It would look something like
<!-- My mod -->
Add jquery
<!-- End My Mod -->
If you just installed your forums, they use Prototype - not jQuery..
I solve this kind of problem by simply asking the user to do the modifications himself. While this isn't the most user friendly approach around, at least this doesn't break any forums (if it breaks it's the users responsibility). To restore user friendlyness to some degree, I try to detect missing modifications and display a status information to the user (please change this, please do that, etc) on the plugins page, along with a readme that describes which changes have to be made in more detail.

If there are two mods that use a third party library, you cannot make the change automatically. The two mods may name their files differently or place them in different folders, so the code they put into their headertemplate looks different. The most you can do is add your own entry and remove your own entry and hope that no other mod will collide with yours.

Of course, using the js lib that MyBB already ships with would probably be the best solution. Smile
Does jquery even work alongside with prototype?
(2009-02-24, 11:01 AM)frostschutz Wrote: [ -> ]Of course, using the js lib that MyBB already ships with would probably be the best solution. Smile
Does jquery even work alongside with prototype?

Unless of course, you don't know Prototype Toungue

jQuery works perfectly with it. I've used it loads of times. You just have to remember that Prototype needs to command the $ shortcut, and not jQuery. Include jQuery.noConflict(); and use the actual jQuery shortcut and you won't have a problem.
(2009-02-24, 04:58 AM)Tom Loveric Wrote: [ -> ]If you just installed your forums, they use Prototype - not jQuery..
I know that, but I don't know prototype.
(2009-02-24, 11:55 AM)Tomm- Wrote: [ -> ]
(2009-02-24, 11:01 AM)frostschutz Wrote: [ -> ]Of course, using the js lib that MyBB already ships with would probably be the best solution. Smile
Does jquery even work alongside with prototype?

Unless of course, you don't know Prototype Toungue

jQuery works perfectly with it. I've used it loads of times. You just have to remember that Prototype needs to command the $ shortcut, and not jQuery. Include jQuery.noConflict(); and use the actual jQuery shortcut and you won't have a problem.

Couldn't we have a modification that installs jquery and requires that user to add that modification first before they use certain modifications?
(2009-02-24, 11:55 AM)Tomm- Wrote: [ -> ]use the actual jQuery shortcut and you won't have a problem.

That works for code you write yourself, but most code that is written for jquery will use the short jquery form, no? If you write code yourself exclusively for MyBB, you should just learn Prototype instead of asking users to download two huge javascript libraries instead of just one. Totally solves the problem here too (complicated install).

If you want to stick with jQuery, just give the user instructions on how to install jQuery. It's just a file and an entry in the headerinclude template, do you need a separate modification for that?
(2009-02-24, 03:31 PM)frostschutz Wrote: [ -> ]
(2009-02-24, 11:55 AM)Tomm- Wrote: [ -> ]use the actual jQuery shortcut and you won't have a problem.

That works for code you write yourself, but most code that is written for jquery will use the short jquery form, no? If you write code yourself exclusively for MyBB, you should just learn Prototype instead of asking users to download two huge javascript libraries instead of just one. Totally solves the problem here too (complicated install).

If you want to stick with jQuery, just give the user instructions on how to install jQuery. It's just a file and an entry in the headerinclude template, do you need a separate modification for that?

You are correct that it would only be a change in the headerinclude template, but having it as a separate modification would prevent problems for users that have multiple modifications installed that use the jquery library.
(2009-02-24, 03:31 PM)frostschutz Wrote: [ -> ]That works for code you write yourself, but most code that is written for jquery will use the short jquery form, no?

Actually if you initiate the jQuery library after Prototype, and use the noConflict, the $ shortcut will adhere to both libraries actions.

(2009-02-24, 03:31 PM)frostschutz Wrote: [ -> ]It's just a file and an entry in the headerinclude template, do you need a separate modification for that?

You can check if jQuery already exists in the headerinclude template when the plugin is installing. If it doesn't exist, put it in... You can use MyBB or PHP functions to do this - even a database query if you need to...
(2009-02-24, 03:57 PM)Tomm- Wrote: [ -> ]
(2009-02-24, 03:31 PM)frostschutz Wrote: [ -> ]That works for code you write yourself, but most code that is written for jquery will use the short jquery form, no?

Actually if you initiate the jQuery library after Prototype, and use the noConflict, the $ shortcut will adhere to both libraries actions.

(2009-02-24, 03:31 PM)frostschutz Wrote: [ -> ]It's just a file and an entry in the headerinclude template, do you need a separate modification for that?

You can check if jQuery already exists in the headerinclude template when the plugin is installing. If it doesn't exist, put it in... You can use MyBB or PHP functions to do this - even a database query if you need to...

The problem with that is what if the user removes the other modification and that removes the jquery from the headerinclude template. Now your modification is unusable. This is why the only thing I can come up with is a jquery plug-in.
(2009-02-24, 04:05 PM)skywalker2208 Wrote: [ -> ]The problem with that is what if the user removes the other modification and that removes the jquery from the headerinclude template. Now your modification is unusable. This is why the only thing I can come up with is a jquery plug-in.

Not really... a specific jQuery plugin won't stop that modification from removing the script from headerinclude.

Why not add a function that hooks into global.php that checks if jQuery is included. That way it's a small script that checks if it's there, if it isn't, then it adds it in and the other modifications are fine.

There isn't any need for a specific plugin. If your plugin needs jQuery, then make a function like the above to ensure it runs.
Pages: 1 2