Issues with JQuery
Posted: 24 February 2009 12:19 PM   [ Ignore ]
Newbie
Rank
Total Posts:  18
Joined  2008-01-02

Hello,

I’m trying to implement the Related Entries module on a site that is also using two other extensions, MD Live Search and MD Markitup. Both use jquery.

When I have the related entries extension enabled, I get errors on the publish and edit pages about jquery (says $ is not a function) and those two extensions do not function. If I try and use the related entries tab and search for an entry, instead of searching, it submits the entry.

Any suggestions?

Profile
 
 
Posted: 25 February 2009 01:52 PM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  10254
Joined  2006-10-18

Hi idawgik,

Do you have the “jQuery for the Control Panel” extension loaded and enabled on your site? smile
Which version of EE are you using?

 Signature 
Profile
 
 
Posted: 25 February 2009 02:00 PM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  18
Joined  2008-01-02

Yes, I have that extension enabled, it was required for the other extensions.

I’m running EE 1.6.7 on this site.

Profile
 
 
Posted: 25 February 2009 03:04 PM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  10254
Joined  2006-10-18

idawgik,

It’s likely the extensions are colliding.
Are you able to disable the two other extensions? smile

I dare point the finger at the other two extensions raspberry

 Signature 
Profile
 
 
Posted: 25 February 2009 04:05 PM   [ Ignore ]   [ # 4 ]
Newbie
Rank
Total Posts:  18
Joined  2008-01-02

Yeah, disabling the other two extensions allows Related Entries to work, so there’s definitely some kind of conflict between them. Ideally, I really need all 3 extensions to work, are there any tweaks I can try with the related entries jquery implementation that might allow all 3 to work together?

Profile
 
 
Posted: 26 February 2009 10:13 AM   [ Ignore ]   [ # 5 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  10254
Joined  2006-10-18

idawgik,

I’ll see if one of our developers can take a look at this one to see if it’s on our side smile

 Signature 
Profile
 
 
Posted: 26 February 2009 10:21 AM   [ Ignore ]   [ # 6 ]
Newbie
Rank
Total Posts:  18
Joined  2008-01-02

Sweet, thanks, let me know if there’s anything I can do to help.

Profile
 
 
Posted: 26 February 2009 11:06 AM   [ Ignore ]   [ # 7 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  10254
Joined  2006-10-18

In extensions/ext.related_entries_ext.php, around line 910, try changing this:

if (isset($EXT->version_numbers['Cp_jquery']) === FALSE && empty($SESS->cache['scripts']['jquery']) === TRUE

to this:

if ( ! isset($EXT->version_numbers['Cp_jquery']) && ! isset ($SESS->cache['scripts']['jquery']) && ! isset( $SESS->cache['scripts']['js']['jquery'])) 

Let me know if that works smile

 Signature 
Profile
 
 
Posted: 26 February 2009 11:17 AM   [ Ignore ]   [ # 8 ]
Newbie
Rank
Total Posts:  18
Joined  2008-01-02

I just made that change and uploaded the file. I’m still getting the same errors on the other two extensions, and running a search on the related entries tab causes a post submit.

No change in behaviour.

Profile
 
 
Posted: 26 February 2009 09:04 PM   [ Ignore ]   [ # 9 ]
Member
Avatar
RankRankRank
Total Posts:  153
Joined  2006-09-11

I’ve run into this sort of conflict before and I find that many times extensions from different devs are loading jQuery twice - which I find breaks just about everyone’s stuff.

I have/own the Related Entries add-on. Maybe I can do a quick test on my fresh 1.6.7 sandbox install. I could install all three, see if jQuery is loading more than once and take it from there.

What version of Related Entries are you using, 1.1.1?

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 26 February 2009 09:53 PM   [ Ignore ]   [ # 10 ]
Member
Avatar
RankRankRank
Total Posts:  153
Joined  2006-09-11

OK, I have a fix. But first let me explain my research.

Solspace is using jQuery “noConflict” like so:

$j jQuery.noConflict(); 

So all those jQuery functions need to have that ‘j’ there, like this for example:

$j('#related_entries_box input.submit').click(function(event

MD scripts are also being written to the Control Panel page, but none of the MD scripts have a ‘j’ in there, so I don’t think jQuery was recognizing any of their functions as functions, hence the “$ is not a function” error you were seeing.

The solution was for me to wrap my jQuery stuff with this:

(function($){
...stuff...
})(jQuery); 

That saves you from having to tweak my extensions or having to tweak the Solspace extension.

So, how to implement? I will be updating both extensions, but for the quick fix:

MD Live Search fix for 1.1.9
At line 615, right inside the opening script tag, add:

(function($)

and then add the closing jQuery thing after the (window).bind, appx line 974:

$(window).bind('load'livesearch);
})(jQuery); 

MD Markitup fix for 1.6.0
We need to do the fix in two places.

At line 1067, right inside the opening script tag, add:

(function($)

and then add the closing jQuery thing right before the closing script tag, appx line 1072:

})(jQuery); 

Then at what is probably now line 1078, right inside the opening script tag, add:

(function($)

and then add the closing jQuery thing before the final closing script tag. Find line 1153 (appx) and change it from this:

$markitupstuff .= '[removed]'.NL

to this

$markitupstuff .= '})(jQuery); [removed]'.NL

I just did these tweaks on a local install and have all three playing nicely together. I’ll update the downloads for the extensions, but that should get you on the right track.

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 27 February 2009 08:00 AM   [ Ignore ]   [ # 11 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  10254
Joined  2006-10-18

Thank you sir! smile

 Signature 
Profile
 
 
Posted: 27 February 2009 09:25 AM   [ Ignore ]   [ # 12 ]
Newbie
Rank
Total Posts:  18
Joined  2008-01-02

This is why I love the ExpressionEngine community, amazing support, great software and addons, and incredible people.

Thank you both so much, the above fixes worked perfectly!

Profile
 
 
Posted: 27 February 2009 11:13 AM   [ Ignore ]   [ # 13 ]
Member
Avatar
RankRankRank
Total Posts:  153
Joined  2006-09-11

Cool - glad we could get that worked out. I’d like to thank Brandon Kelly for the jQuery advice that helped get this taken care of so quickly.

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 27 February 2009 11:14 AM   [ Ignore ]   [ # 14 ]
Newbie
Rank
Total Posts:  18
Joined  2008-01-02

Definitely thank you to all 3 of you guys then grin

Profile
 
 
Posted: 27 February 2009 11:43 AM   [ Ignore ]   [ # 15 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  10254
Joined  2006-10-18

I didn’t really do anything, other than point the finger, haha grin

 Signature 
Profile