MyBB Source

everyBB - The forum owners community

4,000 Members! | Small Policy Change

Latest Releases: Valid Referrals - Bonus - Mark Thread Read

 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[jQuery] Getting jQuery to NOT Conflict With MyBB w/ jQuery Example Tutorial
Author Message
Mikers
Tutorials Team Member



Posts: 146
Joined: Mar 2010
Reputation: 3
MyBux: 1939
Post: #1
[jQuery] Getting jQuery to NOT Conflict With MyBB w/ jQuery Example Tutorial
Hello there gents.

Well, I'm making a few jQuery tutorials for all of you. But if you didn't know how to do this, then any jQuery tutorial I brought to you would break a few things around your site. I originally intended to include a mini-tut inside all of my jQuery tutorials to fix this, but I might as well just make this so I can be lazy and just link to this.


So the simple, easy way to ensure jQuery doesn't conflict with MyBB.

First, Download jQuery and upload the library to somewhere within your MyBB Installation.

Go to,
ACP -> Templates & Styles -> Templates -> Ungrouped Templates -> headerincludes

Find,
Code:
<script type="text/javascript" src="{$mybb->settings['bburl']}/jscripts/prototype.js?ver=1400"></script>

Add Below,
Code:
<script type="text/javascript" src="{$mybb->settings['bburl']}/path/to/jquery.js?ver=1400"></script>
<script>
    jQuery.noConflict();
</script>
(edit the "path/to/jquery" line to your actual jQuery library path)

From then on, include any jQuery scripts below that line. It's usually best to include them through headerincludes, but there are exceptions.

And that's all.

Explanation:
(If you're one of those people who need a reason like I do. )
Normally, it'd be impossible to install jQuery on a MyBB board. MyBB uses a similar library called Prototype, which due to their similarities, conflicts heavily with jQuery's library. And installing jQuery would break all of the scripts on MyBB running on Prototype (for instance, the moderator options, Quick Edit, and many various javascript features throughout MyBB). However, jQuery was smart and created the jQuery.noConflict(); function in order to help us with that. And voila', we have a working jQuery library.


Example Tutorial
"Top of the page effect"
by 41shots

http://community.mybb.com/thread-61315.html

I'm gonna pick on this guy's tutorial, from over at mybb.com. And if he reads this, forgive me man. Just optimizing your tut a bit. All credits go to him for this while all credits go to dynamic drive in which he found them at in which all credits go to the guy who created them at dynamic drive. *whew*

Anyway.

What this guy's tut does is add a jQuery script which adds an arrow to the bottom right corner of the screen that appears when the user is no longer at the top of the page. Allowing him or her to click the arrow to return back. Very conveniant, considering MyBB's own back to the top thing is a little meh.

You can find a working demo here.

A few people reported that his tutorial broke a few options around their sites, due to Prototype and jQuery conflictions. Now, all you have to do to make this tutorial work for you, is use my previous method above to ensure there's no conflictions with jQuery. Download the script from the link 41shots provided. Upload it to your site and then go to headerincludes,

And add this anywhere below The jQuery No Conflict code.
Code:
<script type="text/javascript" src="{$mybb->settings['bburl']}/path/to/scrolltopcontrol.js">

/***********************************************
* Scroll To Top Control script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Project Page at http://www.dynamicdrive.com for full source code
***********************************************/

</script>
(Removed the jQuery inclusion due to the assumption jQuery is already included)
(And once again, edit the path to reflect to where you uploaded the script)

And boom! You suddenly have a very sexy arrow which will no doubt give your users more ease of use.

Once again, credits to 41shots for the original tutorial and finding the script.

By the way, if you want to edit the arrow image in the script...edit scrolltopcontrol.js in Notepad, Notepad ++, or your site's file editor, or whichever, find this line,
Code:
    controlHTML: '<img src="up.png" style="width:48px; height:48px" />', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"

Change <img src="up.png" to the path of your arrow image, and,
change
"width:48px; height:48px"
to the EXACT dimensions of your arrow image.


Anyways, that's all for now folks. Once again, thanks to 41shots for the tutorial which I used as an example for optimization, and to dynamic drive for providing the script.


I'll come along with some of my own jQuery Script Tutorials soon enough.

MyBB Source Tutorials
06-12-2010 10:10 PM


euantor
Designer/Themer


Posts: 501
Joined: Jun 2009
Reputation: 1
MyBux: 573
Post: #2
RE: [jQuery] Getting jQuery to NOT Conflict With MyBB w/ jQuery Example Tutorial
Sometimes just using jquery.noConflict doesn't work with me alone Replacing all the $ values after having initialised noconflict mode sorts things out no matter what.

For instance, I have this small piece of code for a carousel:

Code:
<script type="text/javascript">
$(document).ready(function() {
   $('#s3slider').s3Slider({
      timeOut: 4000
   });
});
</script>

To stop any conflict, I change this code to:

Code:
<script type="text/javascript">
JQuery.noConflict();
JQuery(document).ready(function() {
   JQuery('#s3slider').s3Slider({
      timeOut: 4000
   });
});
</script>


Just a tip to try if you still have conflicts ^^

Love to play XBox 360? Visit http://www.360elites.net for News, Reviews & Previews of the biggest up-coming and current games like Halo:Reach, Battlefield: Bad Company 2 and more. We have forums too!

Visit http://www.mypurebb.com/ to see some examples of my work with MyBB themes and web designs. I even sometimes take on custom jobs, so why not sign up to the forums so you know when I'm open and designing?
06-13-2010 12:14 AM
Mikers
Tutorials Team Member



Posts: 146
Joined: Mar 2010
Reputation: 3
MyBux: 1939
Post: #3
RE: [jQuery] Getting jQuery to NOT Conflict With MyBB w/ jQuery Example Tutorial
Ah yes, very good tip, gent. Mind if I quote that in the tutorial? (full credits to you of course)

MyBB Source Tutorials
06-13-2010 06:15 AM
euantor
Designer/Themer


Posts: 501
Joined: Jun 2009
Reputation: 1
MyBux: 573
Post: #4
RE: [jQuery] Getting jQuery to NOT Conflict With MyBB w/ jQuery Example Tutorial
No problem

Love to play XBox 360? Visit http://www.360elites.net for News, Reviews & Previews of the biggest up-coming and current games like Halo:Reach, Battlefield: Bad Company 2 and more. We have forums too!

Visit http://www.mypurebb.com/ to see some examples of my work with MyBB themes and web designs. I even sometimes take on custom jobs, so why not sign up to the forums so you know when I'm open and designing?
06-14-2010 12:53 AM
 





Web Design | Web Design Jobs