Forum Moderators: open

Message Too Old, No Replies

Javascript problems

         

nate671123

8:16 pm on Apr 28, 2010 (gmt 0)

10+ Year Member



I currently have a website that I am using SPRY Accordion on for the navigation. <snipped url>

When I try to add another javascript element the SPRY Accordion stops working and the javascript element I am adding does not work.

I have had this problem trying to add a javascript slide show and now with a javascript twitter element (I have included the code I am using for that below).

Does anyone know why my javascript shuts down when I use more than on script? Also, would anyone be able to help me fix this so that I can implement other javascript elements on my webpage?

Here is the CSS/Javascript I am currently trying to add:

<style type="text/css">

body{font-family: verdana, sans-serif; font-size: 12px;}

#twitter_badge_container{width: 300px; background: #C1EAFF}
#twitter_badge_tl{background: transparent url(twitter_tl.png) top left no-repeat;}
#twitter_badge_tr{background: transparent url(twitter_tr.png) top right no-repeat;}
#twitter_badge_bl{background: transparent url(twitter_bl.png) bottom left no-repeat;}
#twitter_badge_br{background: transparent url(twitter_br.png) bottom right no-repeat; }
#twitter_badge_inner{padding: 45px 10px 10px 10px;}
#twitter_badge_via {font-size: 10px }
#twitter_badge_via a {color #666}

/* defaults */
#my_twitter_status{}
#my_twitter_status_time{color: #666; font-size: 10px;}

</style>


<script type="text/javascript">
function relative_time(time_value) {
var values = time_value.split(" ");
time_value = values+ " " + values[2] + ", " + values[5] + " " + values[3];
var parsed_date = Date.parse(time_value);
var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
delta = delta + (relative_to.getTimezoneOffset() * 60);

if (delta < 60) {
return 'less than a minute ago';
} else if(delta < 120) {
return 'about a minute ago';
} else if(delta < (45*60)) {
return (parseInt(delta / 60)).toString() + ' minutes ago';
} else if(delta < (90*60)) {
return 'about an hour ago';
} else if(delta < (24*60*60)) {
return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
} else if(delta < (48*60*60)) {
return '1 day ago';
} else {
return (parseInt(delta / 86400)).toString() + ' days ago';
}
}

function twitterCallback(obj) {
var id = obj[0].user.id;
document.getElementById('my_twitter_status').innerHTML = obj[0].text;
document.getElementById('my_twitter_status_time').innerHTML = relative_time(obj[0].created_at);
}
</script>
<div id="twitter_badge_container">
<div id="twitter_badge_tl">
<div id="twitter_badge_tr">
<div id="twitter_badge_bl">

<div id="twitter_badge_br">
<div id="twitter_badge_inner">
<span id="my_twitter_status"></span> <span id="my_twitter_status_time"></span><span id="twitter_badge_via"> <a href="http://twitter.com/">via twitter</a></span>
<script type="text/javascript" src="http://www.twitter.com/statuses/user_timeline/example.json?callback=twitterCallback&count=1">
</div>
</div>
</div>
</div>
</div>
</div>
<!--END TWITTER BADGE -->

[1][edited by: whoisgregg at 9:35 pm (utc) on Apr 28, 2010]
[edit reason] Whoops, no URLs please. See TOS [webmasterworld.com] :) [/edit]

whoisgregg

9:40 pm on Apr 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, nate671123!

The best thing to do is to run some kind of JavaScript debugging utility (like Firebug for Firefox) and look for error messages. If you do that with this code and post back with that error message, I bet we can do a better job of helping. :)

nate671123

12:58 am on Apr 29, 2010 (gmt 0)

10+ Year Member



The only error message when I add this code to my website is:

twitterCallback is not defined

But my accordion stops working and the twitter javascript doesn't work either