WildcardSearch / Advanced-Sidebox

A plugin for MyBB forums that displays custom boxes on various forum pages.
GNU General Public License v3.0
20 stars 10 forks source link

JavaScript conflict #85

Closed Destroy666x closed 11 years ago

Destroy666x commented 11 years ago

I was wondering what stopped my jQuery script from working, then I saw in Firebug that 2 plugins insert JS at the end of headerinclude. When it's mixed like Prototype -> jQuery -> Prototype (most people and plugins load jQuery after Prototype), as I noticed (may be wrong) it makes conflict between Prototype and jQuery. After disabling Advanced Sidebox and other plugin the jQuery scripts started to work.

There are 2 solutions for it: 1) Make the Prototype scripts load in place where other Prototype scripts do, so for example after <script type="text/javascript" src="{$mybb->settings['bburl']}/jscripts/prototype.js?ver=1603"></script> or if needed (when you use general.js or whatever) after <script type="text/javascript" src="{$mybb->settings['bburl']}/jscripts/popup_menu.js?ver=1600"></script>

2) Leave it at the end but convert to jQuery. MyBB 1.8 will use jQuery as they say so you'll need to move it to it anyways.

WildcardSearch commented 11 years ago

Now I'll be honest and say that JavaScript isn't one of my strong points. In fact what little JS has been written for this plugin was a struggle for me. So when it comes to the when and where, I will listen to your advice because you seem to be knowledgeable.

However, converting to jQuery early isn't going to happen. When 1.8 comes out then ASB will adjust to be compatible but not before. So in other words lets stay with Prototype until MyBB makes the change.

As to where I am adding the JS are you referring to ACP or the JS for toggle icons?

If you can specifically show me what you mean and how to fix it I have no problem giving it a look.

Cheers

Destroy666x commented 11 years ago

I mean the JS on the pages with sideboxes, so the toggles, yes.

I don't really know how to fix it with current code (as PHP isn't one of my strong points - those template classes hurt my head), but as I said it should be inserted in one of the places I mentioned. They're inside $headerinclude template and that's the problem for me.

WildcardSearch commented 11 years ago

Well I can't remember exactly, but I believe that we always pumped in our JS at the main insertion point in the body before 1.7-- iirc I started using the headerinclude global variable to add the JS because of the AJAX failing if not inserted in the header and called with the onload functions.

I am kind of guessing so don't hold me to it. I can't remember exactly why I changed it but I believe it was to solve some issue.

Let me have a chance to experiment with positioning and get back to you.

P. S. I know you have been working on some things and making edits to the core to suit your needs (or at least I think I remember you saying that)-- I just thought I'd tell you that if you don't already know, you can use the Patches plugin to maintain your personal changes to ASB in a much easier way. Sorry if you already know I am just trying to help.

Destroy666x commented 11 years ago

Well, inserting it into body> was just not as it's supposed to be (broken W3C validation for example, don't know about AJAX), other than that it was still the same because it loads at the end. Inserting it into one of the places mentioned by me, which are still in head>, shouldn't break anything.

Yea, I know about Patches, but as I said this can be problem for more people. In the MyBB Support forums I see a conflict topic at least 2 times daily - broken editor, not working quick edit/inline moderation etc. There are thousands of those. Many people were posting their headerincludes, in which the conflict is often visible, and when they seemed correct the problem stayed unsolved. Now I noticed (bit too late) that even popular and well-coded plugins can cause conflicts too. In combination with inserting the code into cache, it's impossible to even help them if they don't post their url. So that's quite an annoying thing if you ask me.

WildcardSearch commented 11 years ago

You are telling me that I need to add my JS earlier in the file, but when I look at what you are telling me and then stop and think about searching and replacing it seems a little complicated. I'll take a look at it, but remember I'll need to find something concrete to anchor my search & replace routines on. If I can do that then I have no problem with moving the JS around.

Give me some time to look into it.

avril-gh commented 11 years ago

try to read in google about $.noConflict(); and then try to insert it in proper place and see if it helped When i had many different js scripts, it helped me to make all of them work together without any changes.

$.noConflict();
jQuery(document).ready(function($) {
    // some code
});
Destroy666x commented 11 years ago

Thanks for the advice, but I always use .noConflict function and it doesn't seem to work sometimes, like in the case mentioned above.

WildcardSearch commented 11 years ago

I think we were done here. If not, let me know.

I have done some testing and with noConflict I was able to use jQuery (and obviously Prototype) on pages where ASB is placing JS-- and I am no expert so I know it is possible. Just take another look at your placement.