Solved

jQuery jCarousel call getting mangled

Posted on 2010-11-30
12
917 Views
Last Modified: 2012-05-10
Hi All,

I'm having trouble trying to use the jQuery - jCarousel widget. i have had this working for 6 months without any problems. i just moved my site live and now a problem has cropped up. The problem can be seen on either of these pages (the first one is a bit stripped down for debugging) - http://www.redyref.com/kiosks/custom_kiosks, http://www.redyref.com/touchscreen_building_directories/Office. the carousel should appear above the text "Install Views".

It looks like the jQuery libraries are found, but I'm not sure. I am using the expression engine CMS software for this site.

When refreshing the page, i get a javascript syntax error on the code below. i have posted both the source code and the "View Source" code. if you look closely, you will see that the information for the parameter "itemLoadCallback:" is missing from the "view source" code. So it looks like the callback is being stripped out somehow and then causing a syntax error.

Any help would be greatly appreciated.

Thanks,
John

ORIGINAL CODE:

==============							



<script type="text/javascript">



jQuery(document).ready(function() {

    jQuery('#mycarousel').jcarousel({

	 vertical: true,

         size: mycarousel_itemList.length,

	 itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback}

	});

});



							</script>



VIEW SOURCE CODE:

=================



<script type="text/javascript">



jQuery(document).ready(function() {

    jQuery('#mycarousel').jcarousel({

	vertical: true,

	size: mycarousel_itemList.length,

	itemLoadCallback: 

	});

});

							</script>

Open in new window

0
Comment
Question by:jrattinger
  • 6
  • 6
12 Comments
 

Author Comment

by:jrattinger
ID: 34241474
Now this problem even exists when i copy the code from the author of jcarousel's code into my site.

This is the new page.
http://www.redyref.com/index.php/carousel_test/

This is the authors page:
http://sorgalla.com/projects/jcarousel/examples/dynamic_javascript.html
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34246171
Error: syntax error
Source File: http://www.redyref.com/touchscreen_building_directories/Office
Line: 917, Column: 4
Source Code:
    });

because you have nothing after
        itemLoadCallback:
0
 

Author Comment

by:jrattinger
ID: 34247301
hi mplungian,

yes there is code after the itemLoadCallback - itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback}

The problem is that when the page gets rendered, that code is removed. see the original and view source code above. i have no idea why this is the case and that's what's driving me crazy.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34247517
Sorry, I was reading the question on my phone initially and did not notice your question was EXACTLY what I observed :(

what happens if you do

itemLoadCallback: {
  onBeforeAnimation: mycarousel_itemLoadCallback
}
0
 

Author Comment

by:jrattinger
ID: 34247644
no problem.... I actually just tried that a little while ago. Unfortunately, the same results.

http://www.redyref.com/index.php/carousel_test/

this is just the author's example without any code added. it is being displayed as a stand-alone page on my expression engine website.

I'm wondering if there is some sort of clash with jQuery libraries that is happening under the covers. i don't know how to check if other versions of the jQuery library are being called.

Thanks.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34248762
That link does not execute well
the css is html and there is no jQuery loaded:

Error: The stylesheet http://www.redyref.com/index.php/style.css was not loaded because its MIME type, "text/html", is not "text/css".
Source File: http://www.redyref.com/index.php/carousel_test/
Line: 0

Error: jQuery is not defined
Source File: http://sorgalla.com/projects/jcarousel/lib/jquery.jcarousel.min.js
Line: 16

Error: jQuery is not defined
Source File: http://www.redyref.com/index.php/carousel_test/
Line: 56


since you commented out
<!--
  jQuery library
<script type="text/javascript" src="http://sorgalla.com/projects/jcarousel/lib/jquery-1.4.2.min.js"></script>
-->

als jQuery cannot remove html from view-source so I though a clash with your template thing
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jrattinger
ID: 34249603
sorry, i made some changes while testing. a clean example can be found at - http://www.redyref.com/index.php/carousel_test_2/

I'm completely at a loss. Keep in mind that this code worked perfectly 2 days ago until i moved my site live. i figured that i would start with the authors example and work toward my implementation, but as you can see, i haven't gotten very far. You can see the authors page here - http://sorgalla.com/projects/jcarousel/examples/dynamic_javascript.html.

All i did was pickup the code and change the relative paths for the css and jQuery. I then put that code into my expression engine site to test. if i just load that file into a browser (via open with firefox or chrome), it still does not render correctly.

In the redyref.com site, the initialization of variable - mycarousel_itemList, gets chopped, as does the itemLoadCallback parameters.

My code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<title>jCarousel Examples</title>
<link href="http://sorgalla.com/projects/jcarousel/style.css" rel="stylesheet" type="text/css" />

<!--
  jQuery library
-->
<script type="text/javascript" src="http://sorgalla.com/projects/jcarousel/lib/jquery-1.4.2.min.js"></script>

<!--
  jCarousel library
-->
<script type="text/javascript" src="http://sorgalla.com/projects/jcarousel/lib/jquery.jcarousel.min.js"></script>
<!--
  jCarousel skin stylesheet
-->
<link rel="stylesheet" type="text/css" href="http://sorgalla.com/projects/jcarousel/skins/tango/skin.css" />


<script type="text/javascript">

var mycarousel_itemList = [
    {url: "http://static.flickr.com/66/199481236_dc98b5abb3_s.jpg", title: "Flower1"},
    {url: "http://static.flickr.com/75/199481072_b4a0d09597_s.jpg", title: "Flower2"},
    {url: "http://static.flickr.com/57/199481087_33ae73a8de_s.jpg", title: "Flower3"},
    {url: "http://static.flickr.com/77/199481108_4359e6b971_s.jpg", title: "Flower4"},
    {url: "http://static.flickr.com/58/199481143_3c148d9dd3_s.jpg", title: "Flower5"},
    {url: "http://static.flickr.com/72/199481203_ad4cdcf109_s.jpg", title: "Flower6"},
    {url: "http://static.flickr.com/58/199481218_264ce20da0_s.jpg", title: "Flower7"},
    {url: "http://static.flickr.com/69/199481255_fdfe885f87_s.jpg", title: "Flower8"},
    {url: "http://static.flickr.com/60/199480111_87d4cb3e38_s.jpg", title: "Flower9"},
    {url: "http://static.flickr.com/70/229228324_08223b70fa_s.jpg", title: "Flower10"}
];

function mycarousel_itemLoadCallback(carousel, state)
{
    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) {
            continue;
        }

        if (i > mycarousel_itemList.length) {
            break;
        }

        carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[i-1]));
    }
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<img src="' + item.url + '" width="75" height="75" alt="' + item.url + '" />';
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        size: mycarousel_itemList.length,
        itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback}
    });
});

</script>
</head>
<body>
<div id="wrap">
  <h1>jCarousel</h1>
  <h2>Riding carousels with jQuery</h2>

  <h3>Carousel with dynamic content loading via JavaScript</h3>
  <p>

    The data is loaded dynamically from an javascript array.
  </p>

  <ul id="mycarousel" class="jcarousel-skin-ie7">
    <!-- The content will be dynamically loaded in here -->
  </ul>

</div>
</body>
</html>

Open in new window


thanks for your help, my client is now screaming.... :(

John
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34250010
I'll look soon
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 34250343
Please externalise the script

Put the script in a file and include it

<script type="text/javascript" src="yourjscode.js"></script>
0
 

Author Comment

by:jrattinger
ID: 34250699
Thanks, that seems to cure the stomping problem, but it is still not loading and displaying the list properly. Any ideas?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34250757
Download and install firefox. look in console

Error: jCarousel: No width/height set for items. This will cause an infinite loop. Aborting...
Source File: http://sorgalla.com/projects/jcarousel/lib/jquery.jcarousel.min.js
Line: 16
0
 

Author Comment

by:jrattinger
ID: 34253638
I was able to finally resolve my issues. it was mostly due to javascript libraries definitions, sequence of these definitions and pulling the javascript into an external file.

Thanks mplungian for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 List with Ratings 6 37
two layers of simple javascript validation 2 28
CONVERT JAVASCRIPT BUTTON TO HYPERLINK TEXT 6 20
hosting images 4 12
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now