Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-17-2012, 04:40 PM   PM User | #1
eiger23
New Coder

 
Join Date: Sep 2011
Posts: 57
Thanks: 8
Thanked 0 Times in 0 Posts
eiger23 is an unknown quantity at this point
auto refresh on jquery script

I currently have this on my companies website and it's having a bit of trouble sometimes where it will only work after a refresh. Is it possible to do a refresh of this div and script as soon as the site loads, instead of using the auto refresh. I tried using auto refresh and it works but whatever time interval I put for the auto refresh is the time that the script pops up, so it kind of just makes it worst.

Code:
<script type="text/javascript">
		
	
			$(document).ready(function() {
				$("#twitter").getTwitter({
					userName: "lubellrosen",
					numTweets: 4,
					loaderText: "Loading Events...",
					slideIn: true,
					slideDuration: 750,
					showHeading: false,
					headingText: "Latest Tweets",
					showProfileLink: false,
					showTimestamp: false
				});
			});

		</script>
eiger23 is offline   Reply With Quote
Old 01-17-2012, 05:15 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,600
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
It sounds like the actual issue is somewhere else and the solution is not to do a refresh when the site has loaded but to find the issue that is causing it not to load initially. Got a link to your site for us?
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 01-17-2012, 05:57 PM   PM User | #3
eiger23
New Coder

 
Join Date: Sep 2011
Posts: 57
Thanks: 8
Thanked 0 Times in 0 Posts
eiger23 is an unknown quantity at this point
lubellrosen.com
eiger23 is offline   Reply With Quote
Old 01-17-2012, 05:58 PM   PM User | #4
eiger23
New Coder

 
Join Date: Sep 2011
Posts: 57
Thanks: 8
Thanked 0 Times in 0 Posts
eiger23 is an unknown quantity at this point
here is the js for that function

Code:
(function($) {
	/*
		jquery.twitter.js v1.5
		Last updated: 08 July 2009

		Created by Damien du Toit
		http://coda.co.za/blog/2008/10/26/jquery-plugin-for-twitter

		Licensed under a Creative Commons Attribution-Non-Commercial 3.0 Unported License
		http://creativecommons.org/licenses/by-nc/3.0/
	*/

	$.fn.getTwitter = function(options) {

		$.fn.getTwitter.defaults = {
			userName: null,
			numTweets: 4,
			loaderText: "Loading News",
			slideIn: true,
			slideDuration: 750,
			showHeading: false,
			headingText: "Latest Tweets",
			showProfileLink: false,
			showTimestamp: true,
			twitterListHTML: false
		};

		var o = $.extend({}, $.fn.getTwitter.defaults, options);

		return this.each(function() {
			var c = $(this);

			// hide container element, remove alternative content, and add class
			c.hide().empty().addClass("twitted");

			// add heading to container element
			if (o.showHeading) {
				c.append("<h2>"+o.headingText+"</h2>");
			}

			// add twitter list to container element
			var twitterListHTML = "<ul id=\"twitter_update_list\"><li></li></ul>";
			c.append(twitterListHTML);

			var tl = $("#twitter_update_list");

			// hide twitter list
			tl.hide();

			// add preLoader to container element
			var preLoaderHTML = $("<p class=\"preLoader\">"+o.loaderText+"</p>");
			c.append(preLoaderHTML);

			// add Twitter profile link to container element
			if (o.showProfileLink) {
				var profileLinkHTML = "<p class=\"profileLink\"><a href=\"http://twitter.com/"+o.userName+"\">http://twitter.com/"+o.userName+"</a></p>";
				c.append(profileLinkHTML);
			}

			// show container element
			c.show();

			$.getScript("http://twitter.com/javascripts/blogger.js");
			$.getScript("http://twitter.com/statuses/user_timeline/"+o.userName+".json?callback=twitterCallback2&count="+o.numTweets, function() {
				// remove preLoader from container element
				$(preLoaderHTML).remove();

				// remove timestamp and move to title of list item
				if (!o.showTimestamp) {
					tl.find("li").each(function() {
						var timestampHTML = $(this).children("a");
						var timestamp = timestampHTML.html();
						timestampHTML.remove();
						$(this).attr("title", timestamp);
					});
				}

				// show twitter list
				if (o.slideIn) {
					// a fix for the jQuery slide effect
					// Hat-tip: http://blog.pengoworks.com/index.cfm/2009/4/21/Fixing-jQuerys-slideDown-effect-ie-Jumpy-Animation
					var tlHeight = tl.data("originalHeight");

					// get the original height
					if (!tlHeight) {
						tlHeight = tl.show().height();
						tl.data("originalHeight", tlHeight);
						tl.hide().css({height: 0});
					}

					tl.show().animate({height: tlHeight}, o.slideDuration);
				}
				else {
					tl.show();
				}

				// add unique class to first list item
				tl.find("li:first").addClass("firstTweet");

				// add unique class to last list item
				tl.find("li:last").addClass("lastTweet");
			});
		});
	};
})(jQuery);
eiger23 is offline   Reply With Quote
Old 01-17-2012, 07:16 PM   PM User | #5
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
how about this
Code:
<script type="text/javascript">
$(document).ready(function () {
    (function RefreshTwitter() {
        setTimeout(function () {
            $("#twitter").getTwitter({
                userName: "lubellrosen",
                numTweets: 4,
                loaderText: "Loading Events...",
                slideIn: true,
                slideDuration: 750,
                showHeading: false,
                headingText: "Latest Tweets",
                showProfileLink: false,
                showTimestamp: false
            });
            RefreshTwitter(); // recurse, if you'd like.
        }, 10000);
    })();
});</script>
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 01-17-2012, 07:50 PM   PM User | #6
eiger23
New Coder

 
Join Date: Sep 2011
Posts: 57
Thanks: 8
Thanked 0 Times in 0 Posts
eiger23 is an unknown quantity at this point
tried that, the problem with using that is that it goes through the 10000 cycle before it loads the first time. Wanted to see if it's possible just to refresh once, once the site loads.
eiger23 is offline   Reply With Quote
Old 01-17-2012, 08:13 PM   PM User | #7
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
Quote:
Originally Posted by eiger23 View Post
tried that, the problem with using that is that it goes through the 10000 cycle before it loads the first time. Wanted to see if it's possible just to refresh once, once the site loads.
Oh. your originally posted code does that. If ti's not loading correctly then you very well may have another issue altogether
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 01-17-2012, 08:22 PM   PM User | #8
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
did you try jsut putting the script block at the end of the document like so?

Code:
<script type="text/javascript">
				$("#twitter").getTwitter({
					userName: "lubellrosen",
					numTweets: 4,
					loaderText: "Loading Events...",
					slideIn: true,
					slideDuration: 750,
					showHeading: false,
					headingText: "Latest Tweets",
					showProfileLink: false,
					showTimestamp: false
				});
	</script>

</body></html>
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Users who have thanked DanInMa for this post:
eiger23 (01-17-2012)
Old 01-17-2012, 08:40 PM   PM User | #9
eiger23
New Coder

 
Join Date: Sep 2011
Posts: 57
Thanks: 8
Thanked 0 Times in 0 Posts
eiger23 is an unknown quantity at this point
That was probably it. Let's see how that works now. It was originally in the <head> section. Thanks a lot!
eiger23 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:35 AM.


Advertisement
Log in to turn off these ads.