JQuery and select2 - $ scope conflict - javascript

I am using jQuery 2.1.3 min along with the select2 plugin of jQuery in a spring mvc web application.
There has been an issue of $'s scope conflict I am facing with it.
Though all the ajax requests I am sending are written in a file called home.jsp under the <script> tag it shows they are sent through select2 in firebug.
<script type="text/javascript" src="<c:url value="/views/js/jquery-2.1.3.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/views/js/custom/home.js"/>"></script>
<script type="text/javascript" src="<c:url value="/views/js/select2/js/select2.full.js"/>"></script>
This is the order in which I have included my js file. I feel like select2 causes havoc in my code. I am unable to figure out why?

You appear to be using an older version of Select2 4.0.0, most likely one of the betas. In 4.0.0-beta.3, we stopped packaging jQuery in select2.full.js because it caused strange issues like this.

Related

Rails 7. How do I insert existing script into HTML template using Import Maps?

In my application.html.erb I have multiple existent script coming from a bootstrap template(predefined script), normally I put this code under de body tag, for example:
<body>
<script src="assets/plugins/custom/datatables/datatables.bundle.js"></script>
<script src="assets/plugins/custom/vis-timeline/vis-timeline.bundle.js"></script>
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
<script src="assets/js/widgets.bundle.js"></script>
<script src="assets/js/custom/widgets.js"></script>
</body>
In another rails version this working fine, but I am using rails 7 and I'd like to use importmap for the scripts to run properly.
If anyone knows a solution on how to import the scripts correctly so that they work and could help me, I'd be very happy.
Thanks for reading and have a funny day.

TypeError: $ is not a function (Magnific Popup)

I'm a newbie to web dev, so please stick with me. I know this question has come up a lot (or a similar deviation), but after a couple of hours of searching I have not found an answer that works for me.
I've made sure the JQuery file is loaded first, and tried multiple versions to no avail. Whenever I try to load the Magnific Popup script, I get (TypeError: $ is not a function) on line 50. I've had a look and tried to change $ to JQuery to no avail, so it's back to normal now.
Here's the Magnific Popup code block:
var mfp,
MagnificPopup = function(){},
_isJQ = !!(window.jQuery),
_prevStatus,
_window = $(window), <<<<<< ERROR HERE
_document,
_prevContentType,
_wrapClasses,
_currPopupType;
And the relevant html:
<head>
<link rel="stylesheet" href="css/magnific-popup.css">
</head>
<body>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.magnific-popup.js"></script>
</body>
looks like its not picking your jquery library from CDN..
make sure that you have the network in your system or have access to jquery CDN url
if all above is fine then you try with http in CDN url like below. this is working for me
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
Try to load your jquery file from your own (local) machine. Hopefully, this will work well.
Also, it would be helpful for me if you please let me know that you are not getting 404 for the JQuery file from the CDN.

Issues using FuelUX with Foundation

I have a project built on top of Zurb Foundation, now I need to use some FuelUX components such as "wizard" and "tree". For that I include Twitter Bootstrap library (2.3.2 version downloaded from Bootstrap site) and also include "all.min.js" from FuelUX, when I use the same HTML markup as come in index.html but for some reason it doesn't work. So I tried to fire the plugin using $("#MyWizard").wizard() and get this error:
TypeError: $(...).wizard is not a function
$("MyWizard").wizard();
Any ideas in how to get this work?
How I include scripts
This is the order in which I include scripts:
<script type="text/javascript" src="/bundles/product/js/bootstrap/bootstrap.min.js?0.1"></script>
<script type="text/javascript" src="/bundles/product/js/fuelux/all.min.js?0.1"></script>
<script type="text/javascript" src="/bundles/stock/js/jquery-impromptu.js?0.1"></script>
<script type="text/javascript" src="/bundles/product/js/product.js?0.1"></script>
<script>
$("MyWizard").wizard();
</script>
This was also posted to https://github.com/ExactTarget/fuelux/issues/259 and from what I'm seeing, being careful to follow the instructions at https://github.com/ExactTarget/fuelux/wiki/Using-Fuel-UX#simple-integration-into-a-page should straighten things out. Hope this helps!

jQuery and JavaScript Breaking

I'm currently running a couple different jQuery libraries on my website, here
The rotating banner is from http://codecanyon.net/item/li-jquery-sliderimage-rotator/full_screen_preview/153638
Which has me include these files
<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="js/li-slider-animations-1.1.min.js"></script>
<script type="text/javascript" src="js/li-slider-1.1.min.js"></script>
I also am using fancybox (http://fancybox.net/howto) and include the necessary javascript files.
I got everything working fine until I tried to use this plugin, (http://plugins.jquery.com/project/tipsy)
I could not get that tipsy plugin to work without removing these javascript files from my header
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.js" type="text/javascript"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
I realize I'm probably doing something wrong by including all of these different jquery libraries, but how can I go about having everything work at the same time even though they appear to be using different files.
I included my site URL so you can check the source file to see if there is something I should fix and what I should do so I can add the correct tipsy files.
Thanks
You cannot use multiple versions of the jQuery library on the same page.
How would a script know what library to use?
Only include 1 jQuery script and find updated / other jQuery plugins if they are incompatible.
Or write the needed functionality yourself.

Jquery/Javascript conflicts?

I just implemented a multi-language mod onto my website.
Problem is that there seems to be a conflict between the javascript files from the language mod and the javascript files that already were on the page.
<!-- language files here -->
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/translationEngine.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript" src="js/jquery.translate-1.3.9.min.js"></script>
<script>var browserlang = 'en';</script>
<!-- Javascript -->
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.pngFix.pack.js"></script>
<script type="text/javascript" src="js/jquery.flow.1.2.min.js"></script>
<script type="text/javascript" src="js/jquery.prettyPhoto.js"></script>
<script type="text/javascript" src="js/concept.js"></script>
js/jquery-1.3.2.min.js is what makes the 3 image slider on the homepage work, but... it seems to also be interfering with the functions of the translator.
If u remove js/jquery-1.3.2.min.js from the page, the translator works fine, but the slider no longer works.
removing js/jquery-1.4.2.min.js from the page doesnt make the translator work either, in fact it seems to cause more errors in the back.
Can someone guide me in the right direction that would allow me to make the language translator and image slider both work?
http://filefx.com
Thanks :)
The short version is to remove this:
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
And update your plugins, there are likely 1.4.x versions out there for each of them. By including jQuery a second time, like you are currently, it'll wipe out plugins and cause all sorts of issues...the first step is removing the second (hopefully the older) instance.
Edit: Here's an updated version of jFlow called jFlow plus that works with 1.4.2.
Check out the jQuery noConflict function. This function tells jQuery to relinquish it's control over the $ variable. This way, other libraries can use it.
The online docs give a pretty good guide as to how to use this function. It saved me a few times.
Example from the online docs:
<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$.noConflict();
jQuery(document).ready(function($) {
// Code that uses jQuery's $ can follow here.
});
// Code that uses other library's $ can follow here.
</script>
Basically, once you call noConflict, you can still use jQuery, just use it using the jQuery variable name instead of $.
Hope this helps!
I have alway solved conflicts between two versions of jquery e.g. jQuery 1.3.2 and jQuery 1.4.2 on the same page using iframes but i recently found out that you can use version jquery-1.5.1.js alone and everything works fine.
I change all the .js file on the page used from below code:
<script>
var K = jQuery.noConflict();
alert(K);
jQuery(document).ready(function () {
alert("Bye");
});
</script>
It works fine now.
I ended up just changing the order in which the libraries loaded.
I let all the jquery libraries load first, from newest to oldest. Then i called for the javascript files that rely on jquery.
It works fine now.

Categories

Resources