Adding multiple js files in the header - javascript

I'm trying to add two different javascript functions to my header:
1) is for a lightbox (see code below) and the
2) is for a local scroll (code below). When I place them both in my header tag, as seen below, one or the other will not work at all--depending on the order in which I place them the tag-- when I go to view my page.
Q: how can I get all these js. files to work when I view my page?
<script type="text/javascript" src="/lightbox2.04/js/prototype.js"></script>
<script type="text/javascript" src="/lightbox2.04/js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="/js/lightbox.js"></script>
\\\\and this one below////
<script type="text/javascript" src="/jquery-vertical-scroll/js/jquery.min.js"></script>
<script src="jquery-vertical-scroll/js/jquery.localscroll-min.js" type="text/javascript"></script>
<script src="jquery-vertical-scroll/js/jquery.scrollTo-min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$.localScroll.defaults.axis = 'y';
$.localScroll();
});
</script>

You are using prototype w/ jQuery make sure you have jQuery.noConflict(); after your jquery framework script and prototype framework and before you run any main scripts. It is not recommended to use more than one JavaScript framework at the sametime.
<header>
<link rel="stylesheet" href="/lightbox2.04/css/lightbox.css" type="text/css" media="screen" />
<script type="text/javascript" src="/lightbox2.04/js/prototype.js"></script>
<script type="text/javascript" src="/lightbox2.04/js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="/jquery-vertical-scroll/js/jquery.min.js">
</script>
<script type="text/javascript">
jQuery.noConflict();
</script>
<script src="jquery-vertical-scroll/js/jquery.localscroll-min.js" type="text/javascript"></script>
<script src="jquery-vertical-scroll/js/jquery.scrollTo-min.js" type="text/javascript"></script>
<script type="text/javascript" src="/js/lightbox.js"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery.localScroll.defaults.axis = 'y';
jQuery.localScroll();
});
</script>
</header>
give this a try

Related

Jquery conflict issue

I am using many js file in my header file as shown below
<script src="{$BASE_URL}js/jquery.form.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/cmxforms.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/jquery.metadata.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/jquery.validate.min.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/functions.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/jquery-1.10.1.min.js" type="text/javascript"> </script>
<script type="text/javascript" src="{$BASE_URL}js/jquery-ui.min.js" > </script>
<script type="text/javascript" src="{$BASE_URL}js/timepicker/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="{$BASE_URL}js/jquery-ui-sliderAccess.js"></script>
<script type="text/javascript" src="{$BASE_URL}js/jspatch.js"></script>
<script src="{$BASE_URL}js/script.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script type="text/javascript">
I am getting error as below.
$(...).live is not a function in
$("#reset").live('click',function(){
findproject (line 925)
SyntaxError: syntax error
<script type="text/javascript">//<![CDATA
$(...).validate is not a function
So, what the issue. I am not getting exact way. validation functality is not working
You need to put core jquery lib at the top as this is required to resolve dependencies of other jquery library-
<!-- This must be first library to inlcude-->
<script src="{$BASE_URL}js/jquery-1.10.1.min.js" type="text/javascript"> </script>
<script src="{$BASE_URL}js/jquery.form.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/cmxforms.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/jquery.metadata.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/jquery.validate.min.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/functions.js" type="text/javascript"></script>
<script type="text/javascript" src="{$BASE_URL}js/jquery-ui.min.js" > </script>
<script type="text/javascript" src="{$BASE_URL}js/timepicker/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="{$BASE_URL}js/jquery-ui-sliderAccess.js"></script>
<script type="text/javascript" src="{$BASE_URL}js/jspatch.js"></script>
<script src="{$BASE_URL}js/script.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script type="text/javascript">
Also .live() is not available with this version, you should use .on()
Instead of using .live() use .on() because .live() is deprecated since Jquery 1.7 and removed after Jquery 1.9+ versions and try reordering your Jquery file as shown :-
<!-- This must be first library to inlcude-->
<script src="{$BASE_URL}js/jquery-1.10.1.min.js" type="text/javascript"> </script>
<script src="{$BASE_URL}js/jquery.form.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/cmxforms.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/jquery.metadata.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/jquery.validate.min.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/functions.js" type="text/javascript"></script>
<script type="text/javascript" src="{$BASE_URL}js/jquery-ui.min.js" > </script>
<script type="text/javascript" src="{$BASE_URL}js/timepicker/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="{$BASE_URL}js/jquery-ui-sliderAccess.js"></script>
<script type="text/javascript" src="{$BASE_URL}js/jspatch.js"></script>
<script src="{$BASE_URL}js/script.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
Use on instead of live:
$("#reset").on('click', function () {
// ...
});
Firstly, you need to include jquery.js first in the page, as other script will rely on it:
<script src="{$BASE_URL}js/jquery-1.10.1.min.js" type="text/javascript"></script> <!-- < First -->
<script src="{$BASE_URL}js/jquery.form.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/cmxforms.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/jquery.metadata.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/jquery.validate.min.js" type="text/javascript"></script>
<script src="{$BASE_URL}js/functions.js" type="text/javascript"></script>
Secondly, live has been removed from the latest versions of jQuery. You need to use the delegated version of on() instead.

There's a way to make one javascript framework use a jQuery versione and another one using another?

I'm using single-page-nav to have an 'animated' menu and Photoswipe for a photo gallery. The problem is I'm not able to have both work together. Now, if I have:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="js/simple-inheritance.min.js"></script>
<script type="text/javascript" src="js/code-photoswipe-jQuery-1.0.15.min.js"></script>
<script src="js/jquery.singlePageNav.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#gallery a").photoSwipe();
});
</script>
I've Photoswipe working, but not singlePageNav.. While doing:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="js/simple-inheritance.min.js"></script>
<script type="text/javascript" src="js/code-photoswipe-jQuery-1.0.15.min.js"></script>
<script src="js/jquery.singlePageNav.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#gallery a").photoSwipe();
});
</script>
I've singlePageNav working, but not Photoswipe. Tried with jQuery 1.11.1, but none of them working.. I've see that:
Can I use multiple versions of jQuery on the same page?
So I try:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript">
var jQuery_1_6_1 = $.noConflict(true);
</script>
<script type="text/javascript">
$(document).ready(function(){
jQuery_1_6_1("#gallery a").photoSwipe();
});
</script>
<script type="text/javascript" src="js/simple-inheritance.min.js"></script>
<script type="text/javascript" src="js/code-photoswipe-jQuery-1.0.15.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
var jQuery_1_7_1 = $.noConflict(true);
</script>
<script src="js/jquery.singlePageNav.min.js"></script>
but still no luck, none of them working.. Something else that I colud try, before looking for an alternative to Photoswipe?

Issue including elFinder and JQuery UI

I'm trying to setup an elFinder window on my website. So I downloaded the latest release of from GitHub and followed it's instructions.
I included every file they asked for:
<!-- elFinder -->
<script type="text/javascript" src="../includes/elfinder/js/elfinder.min.js"></script>
<script type="text/javascript" src="../includes/elfinder/js/i18n/elfinder.nl.js"></script>
<!-- JQuery UI -->
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.timepicker.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.draggable.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.droppable.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.selectable.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.resizable.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.slider.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.dialog.js"></script>
And I include this into my head-section as well:
<script type="text/javascript">
$().ready(function() {
var elf = $('#elfinder').elfinder({
lang: 'nl', // language (OPTIONAL)
url : '../includes/elfinder/php/connector.php' // connector URL (REQUIRED)
}).elfinder('instance');
});
</script>
But for some reason, all I get is this image:
But those files are, obviously, included... So I'm wondering what I'm doing wrong since I can't get my finger on the issue...
Why don't you combine the jQuery UI files into one?
Yes the order of includes does matter.
Here a working demo.
Here is the code
HTML
<head>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="http://elfinder.org/demo/css/elfinder.min.css" />
</head>
<div id="elfinder"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script>
<script src="http://elfinder.org/demo/js/elfinder.min.js" ></script>​
Javascript
$().ready(function() {
var f = $('#elfinder').elfinder({
url : '/connector'
}).elfinder('instance');
});​
have you tried changing the order of inclusion?
<!-- elFinder -->
<script type="text/javascript" src="../includes/elfinder/js/elfinder.min.js"></script>
<script type="text/javascript" src="../includes/elfinder/js/i18n/elfinder.nl.js"></script>
<!-- JQuery UI -->
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.timepicker.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.draggable.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.droppable.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.selectable.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.resizable.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.slider.js"></script>
<script type="text/javascript" src="../includes/js/jquery-ui/development-bundle/ui/jquery.ui.dialog.js"></script>
Let me know ;)

Crop rectangle not visible

I am using the following code to crop: http://www.mikesdotnetting.com/Article/95/Upload-and-Crop-Images-with-jQuery-JCrop-and-ASP.NET
The first part works alright. However, before doing the actual crop, I am unable to see the select rectangle.
Here are the script tags:
<script src="jquery-1-7.js" type="text/javascript"></script>
<script src="jquery.Jcrop.min.js" type="text/javascript"></script>
<script src="jquery.color.js" type="text/javascript"></script>
<script src="jcrop_main.js" type="text/javascript"></script>
<script src="jquery.Jcrop.js" type="text/javascript"></script>
<script src="jquery.min.js" type="text/javascript"></script>
<link href="jquery.Jcrop.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery('#imgCrop').Jcrop({
onSelect: storeCoords
});
});
function storeCoords(c) {
jQuery('#X').val(c.x);
jQuery('#Y').val(c.y);
jQuery('#W').val(c.w);
jQuery('#H').val(c.h);
};
</script>
You seem to be loading multiple versions of JQuery itself, and the plugin, which is possibly causing problems. Does the browser show any javascript errors?

Combined JS-libraries

I use two different kinds of JS libraries, but apparently, there is an error when using both.
The two things I use are Mootools and JQuery UI
<!-- Agenda slider -->
<script type="text/javascript" language="javascript" src="js/mootools-1.2.1-core.js"></script>
<script type="text/javascript" language="javascript" src="js/mootools-1.2-more.js"></script>
<script type="text/javascript" language="javascript" src="js/lofslidernews.mt12.js"></script>
<!-- Datepicker -->
<script type="text/javascript" language="javascript" src="js/jquery-1.6.2.js"></script>
<script type="text/javascript" language="javascript" src="js/ui/jquery.ui.core.js"></script>
<script type="text/javascript" language="javascript" src="js/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" language="javascript" src="js/ui/jquery.ui.datepicker.js"></script>
When I use this snippet, the Agenda slider failed to work. However, when I delete this line
<script type="text/javascript" language="javascript" src="js/jquery-1.6.2.js"></script>
The Agenda slider works again, but the Datepicker refuses to work...
How can I combine both scripts and end up with two working javascript-based elements?
EDIT
The only JS included in the .php files are those three little snippets
<script language="javascript">
$(document).ready(function() {
$.featureList(
$("#tabs li a"),
$("#output li"), {
start_item : 1
}
);
// Alternative
$('#tabs li a').featureList({
output : '#output li',
start_item : 1
});
});
</script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
<script type="text/javascript">
var _lofmain = $('lofslidecontent45');
var _lofscmain = _lofmain.getElement('.lof-main-wapper');
var _lofnavigator = _lofmain.getElement('.lof-navigator-outer .lof-navigator');
var object = new LofFlashContent( _lofscmain,
_lofnavigator,
_lofmain.getElement('.lof-navigator-outer'),
{ fxObject:{ transition:Fx.Transitions.Quad.easeInOut, duration:800},
interval:3000,
direction :'hrleft' } );
object.start( true, _lofmain.getElement('.preload') );
</script>
Here's some jQuery documentation explaining how to use other libraries in conjunction with jQuery.
From the docs:
<html>
<head>
<script src="prototype.js"></script>
<script src="jquery.js"></script>
<script>
var $j = jQuery.noConflict();
// Use jQuery via $j(...)
$j(document).ready(function(){
$j("div").hide();
});
// Use Prototype with $(...), etc.
$('someid').hide();
</script>
</head>
<body></body>
</html>
So, for your particular case, try:
<!-- Agenda slider -->
<script type="text/javascript" language="javascript" src="js/mootools-1.2.1-core.js"></script>
<script type="text/javascript" language="javascript" src="js/mootools-1.2-more.js"></script>
<script type="text/javascript" language="javascript" src="js/lofslidernews.mt12.js"></script>
<!-- Datepicker -->
<script type="text/javascript" language="javascript" src="js/jquery-1.6.2.js"></script>
<script>
var $j = jQuery.noConflict();
</script>
<script type="text/javascript" language="javascript" src="js/ui/jquery.ui.core.js"></script>
<script type="text/javascript" language="javascript" src="js/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" language="javascript" src="js/ui/jquery.ui.datepicker.js"></script>
Then, don't forget to change all references from $ to $j when you are trying to use jQuery rather than MooTools.

Categories