FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Plugins and Code Hacks » JQuery Update (Resolves Jquery conflicts with other libraries.)
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
JQuery Update [message #165049] Wed, 20 April 2011 14:19 Go to next message
Dayo is currently offline  Dayo   Iraq
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
Two diff files attached for consideration.

Basically, Joomla uses Mootools and FUDforum, JQuery both of which are in conflict with each other (they both use the same "$" shortcut). I have taken care of this in the script but it will be better to load non-conflicting files.

1. js.diff simply adds "$jquery = jQuery.noConflict();" to the end of jquery.js and changes all the "$" calls in lib.js to "$jquery"

2. js-2.diff does the same as js.diff for lib.js and for jquery.js, is just a copy of JQuery 1.5.1 with the "noConflict" function at the end.

JQuery 1.5.1 works fine with the current templates I looked at (not all though) so might be a good idea to move up to this version for the next release.
  • Attachment: js.diff
    (Size: 9.75KB, Downloaded 1208 times)
  • Attachment: js-2.diff
    (Size: 167.60KB, Downloaded 1236 times)

[Updated on: Wed, 20 April 2011 14:21]

Report message to a moderator

Re: JQuery Update [message #165050 is a reply to message #165049] Wed, 20 April 2011 14:33 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
I see jQuery 1.5.2 is out. Do you really need 1.5.1 or can I commit 1.5.2?
Re: JQuery Update [message #165051 is a reply to message #165050] Wed, 20 April 2011 14:38 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Iraq
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
1.4.4 actually works fine. I only suggested 1.5.1 because it worked when I tested it and I didn't realise it had been updated.

As long as 1.5.2 works then it should be fine. The main thing is to add the noConflict bit to it.
Re: JQuery Update [message #165055 is a reply to message #165051] Wed, 20 April 2011 15:28 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
jQuery was updated to 1.5.2.

We use jQuery in several files (not only in lib.js). Your noConflict patch will break a lot of good working code.
Re: JQuery Update [message #165058 is a reply to message #165055] Wed, 20 April 2011 15:56 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Iraq
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
That sounds like a structural flaw that should be tackled to me ... by consolidating js functions into lib.js.

Makes them reusable and easy to manage as this example shows.

Anyway, I can work around this by replacing the offending variable.

I just need to do the same as done with the lib.js file to inline html as well. Just didn't imagine the scenario as lib.js looked like it was a central js function store ... at least I caught that now.

Still would be better to consolidate and centralise stuff where possible.






Re: JQuery Update [message #165060 is a reply to message #165058] Wed, 20 April 2011 16:06 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Iraq
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
Took a look at some candidates (tree.tmpl for instance) to gauge how much effort to try to consolidate and can see that has to be put into the "too hard basket".

Workaround it is!

[Updated on: Wed, 20 April 2011 16:07]

Report message to a moderator

Re: JQuery Update [message #165061 is a reply to message #165060] Wed, 20 April 2011 17:40 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
I've moved the JavaScript in tree.tmpl to lib.js
http://fudforum.svn.sourceforge.net/fudforum/?rev=5215&view=rev

A step closer, but still not what you want.
Re: JQuery Update [message #165062 is a reply to message #165061] Wed, 20 April 2011 18:12 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Iraq
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
Thanks for trying. A step closer indeed.

To finish up what you started in tree.tmpl, is it possible to do something like ...
<script type="text/javascript">
/* <![CDATA[ */
tree_cur_msg( {VAR: mid} );
/* ]]> */
</script>


and add this to lib.js ...
function tree_cur_msg(cur_msg)
{
	$jquery('#b' + cur_msg).removeClass().addClass('RowStyleC');
}


... which would eradicate the issue for that file if possible

I have written the regex to resolve the conflict before the forum html is rendered so this is not a show stopper.

I just raised the issue since if the conflict was not there, I'll have been able to drop a few lines of regex code and optimise load speed.

[Updated on: Wed, 20 April 2011 18:15]

Report message to a moderator

Re: JQuery Update [message #165063 is a reply to message #165062] Wed, 20 April 2011 18:18 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Iraq
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
that'll be ..
function tree_cur_msg(cur_msg)
{
	$('#b' + cur_msg).removeClass().addClass('RowStyleC');
}


... for the time being.

[Updated on: Wed, 20 April 2011 18:19]

Report message to a moderator

Re: JQuery Update [message #165088 is a reply to message #165063] Sat, 23 April 2011 13:40 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
Please note that the Default Theme does not seem to be compatible with JQuery 1.5.2 as the collapsible messages feature stops working for instance.

I tested with 1.5.1 as said which worked for the things I looked but a full review is probably needed before going with 1.5.x (1.5.2 certainly).

Maybe best to stick with 1.4.4 if this can't be done as 1.4.4 is a widely used version anyway.

Just FYI
Re: JQuery Update [message #165097 is a reply to message #165088] Sun, 24 April 2011 15:45 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
As far as I can tell, Mootools uses $$ and not $

Re: JQuery Update [message #165101 is a reply to message #165049] Mon, 25 April 2011 05:54 Go to previous message
Dayo is currently offline  Dayo   
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
Whatever it is that Mootools actually uses, loading it and Jquery together does not work with the last one loaded effectively overwritting the first.

JQuery was created with the developers aware of this conflict which is why the default way to call jquery functions is actually "JQuery".

Many developers had however become used to simply using "$" from older libraries and JQuery allowed this. This soon became the standard way of doing it.

Again the Jquery developers knew this would happen and added the "no conflict" mode to the library.

If coders only bore flexibility and extendibility in mind, they'll use "JQuery" instead of "$" or use the no conflict mode by default to start with.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Function to send emails?
Next Topic: Install.php suggestion
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 01 00:11:49 GMT 2024

Total time taken to generate the page: 0.02274 seconds