Solved

jQuery jCarousel call getting mangled

Posted on 2010-11-30
12
916 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:jrattinger
Comment Utility
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
Comment Utility
I'll look soon
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

762 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

8 Experts available now in Live!

Get 1:1 Help Now