So doing an integration of Coppermine and MyBB, theMyBB forum uses both Prototype and JQuery. Then the Coppermine installation adds it's own JQuery library.
The two JQuery are different versions so I can't just get rid of one.
I get the typical "not a function" error at lines like "$(document).ready(function() {"
But since the script is being run from a file, i can't do the simple fix of
<script type="text/javascript">
$.noConflict();
// Code that uses other library's $ can follow here.
</script>
so how do I fix the issue?
(2013-01-24, 09:50 PM)pavemen Wrote: [ -> ]So doing an integration of Coppermine and MyBB, theMyBB forum uses both Prototype and JQuery. Then the Coppermine installation adds it's own JQuery library.
The two JQuery are different versions so I can't just get rid of one.
I get the typical "not a function" error at lines like "$(document).ready(function() {"
But since the script is being run from a file, i can't do the simple fix of
<script type="text/javascript">
$.noConflict();
// Code that uses other library's $ can follow here.
</script>
so how do I fix the issue?
Convert the no-conflict to a unique variable. Then replace all instances of $ to your newly declared variable.
So do the following:
<script type="text/javascript">
var newquery = jQuery.noConflict()
newquery(document).ready(function() {
// etc.......
});
</script>
but that works for inline code, but what about the code in a remote JS (truly remote or in a local file, like in jscripts folder)
Yes that works, I use this all the time. Try it.
Then you'll have to manually modify the file(s) I'm afraid. You only need to declare jQuery.noConflict() once though.
(2013-01-24, 11:11 PM)Frank.Barry Wrote: [ -> ]Yes that works, I use this all the time. Try it.
so where do I use that? There are about 12 different JS files called but hardly any <script> </script> code with actual functions in it. None of the functions causing the problem are inline.
(2013-01-24, 11:14 PM)Euan T. Wrote: [ -> ]Then you'll have to manually modify the file(s) I'm afraid. You only need to declare jQuery.noConflict() once though.
Modify them how? Just do a global replace of "$" with "jQuery" in the say the CPG JS files?
Well, what I would do is place the "var newquery = jQuery.noConflict()" on top of all your js files. There wont be <script> tags in those files obviously. And just declare a unique variable in each file. This works for me and ensures that each file is unique.
If the scripts use $(document).ready(), replace them like this:
jQuery(document).ready(function($) {
// The normal code - we can use $ safely as it's passed as a parameter
});
Otherwise, you'll have to replace the instances of $ with jQuery (or if you're using Frank's method, the custom variable).
(2013-01-24, 11:23 PM)Frank.Barry Wrote: [ -> ]Well, what I would do is place the "var newquery = jQuery.noConflict()" on top of all your js files. There wont be <script> tags in those files obviously. And just declare a unique variable in each file. This works for me and ensures that each file is unique.
thanks for the tip but I went with Euan's way as I understood it better.
(2013-01-24, 11:26 PM)Euan T. Wrote: [ -> ]If the scripts use $(document).ready(), replace them like this:
jQuery(document).ready(function($) {
// The normal code - we can use $ safely as it's passed as a parameter
});
Otherwise, you'll have to replace the instances of $ with jQuery (or if you're using Frank's method, the custom variable).
Replaced the opening function call and then all instances of $( with jQuery( and all seems to be working.
Thanks to you both for the help.