PDA

View Full Version : script question



ajfmrf
05-23-2012, 02:18 AM
1) Script Title: RSS Display Boxes

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex18/rssdisplaybox/index.htm

3) Describe problem:

The scripts include this part which is javascript.


<script type="text/javascript">
var showbbc=new rssdisplaybox("bbc", "bbcid", "someclass")
showbbc.set_items_shown(10) //show 10 entries from feed
showbbc.start() //Required: start script
</script>

Can an array be written to use muliple boxes at once?An array of some type?

example:

bbc,cnn,bing,google, cbs, reuters,espn,mlb,etc

And more if wanted.Doing one for each site/feed is a lot of work( I have done it and know from experience)

jscheuer1
05-24-2012, 02:47 AM
This should do that:


<script type="text/javascript">
var feeds = {};
(function(){
var feednames = ['bbc', 'cnn', 'bing', 'google', 'cbs', 'reuters', 'espn', 'mlb'];
for(var i = 0; i < feeds.length; ++i){
feeds[feednames[i]] = new rssdisplaybox(feednames[i], feednames[i] + 'id', 'someclass');
feeds[feednames[i]].set_items_shown(10); //show 10 entries from feed
feeds[feednames[i]].start(); //Required: start script
}
})();
</script>

If you need to access an individual feed later for some reason it will be known as, the cnn one for example:


feeds['cnn']

ajfmrf
05-24-2012, 04:41 AM
Thank you John.

John,would there be a limit to how many feed names I could use?

The reason I ask is that there would probably be around 100-200(somewhere in that range?

I have them grouped.Could I seperate them by group?There would be six groups.

Thanks again John-this is not fixed yet?

djr33
05-24-2012, 05:50 AM
The thanks system is completely functional. There's just a warning due to changes in the updated board system (but it still works). Hopefully it'll be fixed soon.

jscheuer1
05-24-2012, 02:10 PM
Virtually no limit. There might be bandwidth/loading time issues, or not. Sooner or later, as long as they're all valid feeds, they should load.

To separate them into groups, if all of the feed names are different, only initialize the feeds object for the first group:


<script type="text/javascript">
var feeds = {};
(function(){ // group 1
var feednames = ['bbc', 'cnn', 'bing', 'google'];
for(var i = 0; i < feednames.length; ++i){
feeds[feednames[i]] = new rssdisplaybox(feednames[i], feednames[i] + 'id', 'someclass');
feeds[feednames[i]].set_items_shown(10); //show 10 entries from feed
feeds[feednames[i]].start(); //Required: start script
}
})();
</script>

Then elsewhere, later on in the page:


<script type="text/javascript">
(function(){ // group 2
var feednames = ['cbs', 'reuters', 'espn', 'mlb'];
for(var i = 0; i < feednames.length; ++i){
feeds[feednames[i]] = new rssdisplaybox(feednames[i], feednames[i] + 'id', 'someclass');
feeds[feednames[i]].set_items_shown(10); //show 10 entries from feed
feeds[feednames[i]].start(); //Required: start script
}
})();
</script>

But if one or more of group 1 will also be in group 2, you may need a new feeds object (group 1 may remain the same, group 2 would be like):


<script type="text/javascript">
var feeds2 = {};
(function(){ // group 2
var feednames = ['bbc', 'cnn', 'bing', 'google', 'cbs', 'reuters', 'espn', 'mlb'];
for(var i = 0; i < feednames.length; ++i){
feeds2[feednames[i]] = new rssdisplaybox(feednames[i], feednames[i] + 'id', 'someclass');
feeds2[feednames[i]].set_items_shown(10); //show 10 entries from feed
feeds2[feednames[i]].start(); //Required: start script
}
})();
</script>

ajfmrf
05-26-2012, 12:21 AM
Hi John,I tested your redo and it is not working.

Here is you version(the shortcut-lol)
http://www.web-user.net/rss/testb/btest.html
http://www.web-user.net/rss/testb/btest.txt

and here it is the original way:
http://www.web-user.net/rss/testb/atest.html
http://www.web-user.net/rss/testb/atest.html

It must have an error spacing or something because I copied and pasted it?


I don't know?

Maybe you can tell me what I did wrong John?

Bud

jscheuer1
05-26-2012, 07:20 AM
Ooops, typo. Where I have:



<script type="text/javascript">
var feeds = {};
(function(){ // group 1
var feednames = ['bbc', 'cnn', 'bing', 'google'];
for(var i = 0; i < feeds.length; ++i){
feeds[feednames[i]] = new rssdisplaybox(feednames[i], feednames[i] + 'id', 'someclass');
feeds[feednames[i]].set_items_shown(10); //show 10 entries from feed
feeds[feednames[i]].start(); //Required: start script
}
})();
</script>

It needs to be:


<script type="text/javascript">
var feeds = {};
(function(){ // group 1
var feednames = ['bbc', 'cnn', 'bing', 'google'];
for(var i = 0; i < feednames.length; ++i){
feeds[feednames[i]] = new rssdisplaybox(feednames[i], feednames[i] + 'id', 'someclass');
feeds[feednames[i]].set_items_shown(10); //show 10 entries from feed
feeds[feednames[i]].start(); //Required: start script
}
})();
</script>

I made that mistake in the first one and copied it into the others. I just tested it with the correction above. It's working fine now.

I'm going to go back and fix my previous post in case, as often happens, anyone else tries to follow it without reading the entire thread.

ajfmrf
05-26-2012, 08:59 PM
That works John.

I figured it was something little lol