MyBB Community Forums

Full Version: Removing Javascript Conflicts & Simple jQuery Tweaks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Certain people prefer to have custom javascripts in their forum. Due to certain so called SYNTAX errors javascript conflicts occur.

How do i find a conflict?
In mybb, simple indications of a conflict are:
  • EDIT Button not working
  • MultiQuote not working
  • MyBB Editor does not appear. [editor.js]
  • Your other jQuery based scripts don't work

These can be solved by:

1. Using jQuery.noConflict();
If you are using jQuery in your forum, a conflict arising can be solved by adding:

<script type=text/javascript">jQuery.noConflict();</script>

just below where you put jQuery.

Example:
<script type="text/javascript" src="http://xxx/jquery-1.8.0.min.js"></script>
<script type="text/javascript">jQuery.noConflict();</script>

2. Using the latest jQuery:

Certain scripts are their that require a higher jQuery version than the one you use. This may also result in undesirable output, conflicts, etc.

You can get the latest version can be obtained from http://jquery.com

You can also use jQuery's MediaTemple CDN hosted jQuery.

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.1.min.js"></script>

3. Using the latest version of ProToType.js

MyBB's current Prototype version is 1.6.0.0. You should replace it with the latest one.

To do so, head over to your theme's templates, open UNGROUPED templates -> headerinclude

Find the url to prototype.js.

It should look like:

http://community.mybb.com/jscripts/prototype.js?ver=1600

Replace it with:

http://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js

4. Fixing Javascripts call based on jQuery:

If you are using too many many javascripts, then also it is possible that some of them don't work even after you do the above steps.

To fix this, find the jQuery call, looks like:

<script type="text/javascript">
$(document).ready(function($){
}); 
</script>

You can fix it by changing the '$' sign with 'jQuery'

The above code would become:

<script type="text/javascript">
jQuery(document).ready(function(){
}); 
</script>

=========================================

That's all Smile If you experience any other error or my post has got some wrong info/error in codes you can reply here any time Smile

=========================================
There are couple of similar guide in the database.

Also, isn't it be:

<script type="text/javascript">
jQuery(document).ready(function($){
});
</script>

which will allow you to use the $ shorthand throughout inside the function ...
That is the concept, use of 'jQuery' instead of '$' in your code Smile
What I said is, if you include $ (or any keyword) in parameter brace of function then you CAN use $ (or the used keyword) within the function.
True, so what wrong did i write? instead of ($), I wrote (jQuery) so that it is used instead of the $.
(2013-03-07, 08:32 AM)EGman Wrote: [ -> ]True, so what wrong did i write? instead of ($), I wrote (jQuery) so that it is used instead of the $.

Nope. He says when we use jQuery(document).ready(function($) we can use $ symbol inside the document ready function, which will be considered as jQuery.
Whereas, in OP, you asked to replace it with jQuery(document).ready(function(jQuery) in which the jQuery inside function() is not of much use as we can just use jQuery(document).ready(function() instead.
(2013-03-07, 09:31 AM)kavin Wrote: [ -> ]
(2013-03-07, 08:32 AM)EGman Wrote: [ -> ]True, so what wrong did i write? instead of ($), I wrote (jQuery) so that it is used instead of the $.

Nope. He says when we use jQuery(document).ready(function($) we can use $ symbol inside the document ready function, which will be considered as jQuery.
Whereas, in OP, you asked to replace it with jQuery(document).ready(function(jQuery) in which the jQuery inside function() is not of much use as we can just use jQuery(document).ready(function() instead.
kk... I did not clearly understand him Smile Thanks for making it clear.

Thread updated. ~ Thanks to effone.
Right. Big Grin

You can also use the second option for using shorthands.

This is correct:

<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(".somediv").hide();
});
</script>

... and this is an alternate correct one:

<script type="text/javascript">
jQuery(document).ready(function($){
$(".somediv").hide();
});
</script>
Another very common symptom is the editor.js not functioning. (Not Appearing in most cases)
Thanks for pointing it Smile I added it.
Pages: 1 2 3