Have a question about CiviCRM? Get it answered quickly at the new CiviCRM Stack Exchange Q+A siteThis forum was archived on 25 November 2017. Learn more.How to get involved.What to do if you think you've found a bug.
I've encountered this with two sites, running Drupal 6 and CiviCRM 2.2.5 or 2.2.7. It seems like there is something about how CiviCRM instantiates its own copy of jquery that causes subsequent loading of jquery plugins to fail. My Drupal code loads the plugin js file OK, but actually trying to run the function provided by the plugin causes a "is not a function" error in the javascript console. Meanwhile, other inline code using the core jquery methods (like $("#this").hide() in my Drupal code works fine.Here's an example from the resulting page markup:Code: [Select]<script type="text/javascript" src="/sites/all/modules/civicrm/packages/jquery/jquery.js"></script>... ( several lines lower ) ... <script type="text/javascript" src="/misc/jquery.js?n"></script>... ( several lines lower, getting to my code ) ...<script type="text/javascript" src="/sites/all/themes/fairvotemn/js/superfish.js?n"></script><script type="text/javascript"><!--//--><![CDATA[//><!-- $(document).ready(function(){ $("ul.sf-menu").superfish(); }); //--><!]]></script>I've tried it with three different jquery plugins (superfish, timers, curveycorners) that all work fine on non-CiviCRM pages, so I don't think the plugin code is the problem here. I've also tried different plugin function invocations like jquery(element).superfish(); and cl(element).superfish();You can see an example of this problem (for the moment) here:http://fairvote.reinventingthe.com/civicrm/profile/edit&gid=9&reset=1Is the CiviCRM invocation of jquery hijacking later plugin loading (meant for the Drupal invocation of jquery)? Can I excise CiviCRM's invocation so my site is not loading jquery twice on some pages?
<script type="text/javascript" src="/sites/all/modules/civicrm/packages/jquery/jquery.js"></script>... ( several lines lower ) ... <script type="text/javascript" src="/misc/jquery.js?n"></script>... ( several lines lower, getting to my code ) ...<script type="text/javascript" src="/sites/all/themes/fairvotemn/js/superfish.js?n"></script><script type="text/javascript"><!--//--><![CDATA[//><!-- $(document).ready(function(){ $("ul.sf-menu").superfish(); }); //--><!]]></script>
My solution was to add an IF statement to my js file. if($("body").hasClass("section-civicrm")) { cj('#my-div').myPlugin(); } else { $('#my-div').myPlugin(); }After that everything worked again
if (typeof cj !="undefined")
Posting in this thread as it came first in a Google search. Figured out most of the problems are caused by many of Drupals javascript files being inserted *after* the CiviCRM jQuery file has been included.