Google Feed API - feed content in jquery modal window ?

100 views
Skip to first unread message

Sergey Ivanov

unread,
Feb 23, 2014, 5:14:39 PM2/23/14
to google-ajax...@googlegroups.com
Hi,

Im stuck at showing feed content in modal window, the problem is that modal window always shows the same content and same title and i have no idea how to fix it. Can anyone give me advice or sample how to resolve my problem. Below is the code i use.

google.load("feeds", "1");

function initialize(){
var feed = new google.feeds.Feed("http://allods.mail.ru/newsrss.php?line=news");
feed.setNumEntries(3);
feed.load(function(result){
if (!result.error) {
var container = document.getElementById("ao_news");
var feed_html = '';
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
              var date_val = new Date(entry.publishedDate);
              moment.lang('ru');
                        var ao_news_content = '';
                        ao_news_content +=entry.content;
feed_html +='<div id="ao_news_item"><a class="ao_news_title" href="' + entry.link + '" target="_blank">' + entry.title + '</a><div class="ao_news_snippet">' +entry.contentSnippet + '</div><span class="ao_news_time">' + moment(date_val).fromNow() + '</span></div>' ;
}            
container.innerHTML = feed_html;
                        $('#ao_read_full').html(ao_news_content);
}
        $(document).ready(function(){
            $('#ao_read_full').dialog({
                autoOpen:false,
                width:800,
                height:600,
                modal:true,
                title:entry.title
            });
            
            $('#ao_news #ao_news_item').each(function(){
                $(this).click(function(){
                $('#ao_read_full').dialog('open');
            });
            });
        
        });
});
}google.setOnLoadCallback(initialize);

Legend - #ao_read_full - dialog modal window
             #ao_news - container that holds #ao_news_item
             #ao_news_item - that is feed

Jeremy Geerdes

unread,
Feb 23, 2014, 9:42:16 PM2/23/14
to google-ajax...@googlegroups.com
You're overwriting the container.innerHTML with every news entry. Use += instead of = .

And if that doesn't fix the problem, please post a link to the page, working or not, so we can see the code in action. It's generally much easier to debug things that way than by reading plain code, particularly when formatting isn't preserved.

jg


On Sun, Feb 23, 2014 at 8:41 PM, Rev. Jeremy R. Geerdes <jgee...@debraheightswesleyan.org> wrote:
You're overwriting the container.innerHTML with every news entry. Use += instead of = .

And if that doesn't fix the problem, please post a link to the page, working or not, so we can see the code in action. It's generally much easier to debug things that way than by reading plain code, particularly when formatting isn't preserved.

jg


--
--
You received this message because you are subscribed to the Google
Groups "Google AJAX APIs" group.
To post to this group, send email to
google-ajax...@googlegroups.com
To unsubscribe from this group, send email to
google-ajax-searc...@googlegroups.com
To view this message on the web, visit
https://groups.google.com/d/msgid/google-ajax-search-api/68b60f5a-3a1b-4ba9-b582-595c792fec56%40googlegroups.com
For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-ajax-searc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Rev. Jeremy R. Geerdes, Pastor
Debra Heights Wesleyan Church
4025 Lower Beaver Rd
Des Moines, IA 50310




--
Jeremy R. Geerdes
Generally Cool Guy
Des Moines, IA

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!

Sergey Ivanov

unread,
Feb 24, 2014, 10:45:24 AM2/24/14
to google-ajax...@googlegroups.com
Hi,
I tried to use += instead of = but result is the same. the feeds loads corectly (three feeds) but when click on feed modal window shows third feed title and content (third feed is the oldest by date). Here im providing link to my web page, the page is unfinished and i have a lot of work to do. And i hope that russian language doesn't makes much difficulty. If You take a look to page code then You will see that feeds generates automaticaly and there is no code on page, there is just link to javascript in head, and <div> with proper id for placing feeds inside.

There is page - http://nfoxinc.ru

понедельник, 24 февраля 2014 г., 4:42:16 UTC+2 пользователь jgeerdes [AJAX APIs "Guru"] написал:

To view this message on the web, visit
https://groups.google.com/d/msgid/google-ajax-search-api/68b60f5a-3a1b-4ba9-b582-595c792fec56%40googlegroups.com
For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-ajax-search-api+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
--
Rev. Jeremy R. Geerdes, Pastor
Debra Heights Wesleyan Church
4025 Lower Beaver Rd
Des Moines, IA 50310

Jeremy Geerdes

unread,
Feb 24, 2014, 12:40:30 PM2/24/14
to google-ajax...@googlegroups.com
Okay, so the main problem is an issue of scope in the for loop that you're using. To fix that, you need to use what's called a method closure. But there are several other problems as well (e.g., you have multiple elements with the id ao_news_item). So I went ahead and rewrote the code so that it works. I would encourage you to take a look through it to see some of the stuff I did (e.g., the method closure). To use the code, you'll need to replace your ao_load_feed.js with the one attached. Because I changed the elements from div#ao_news_item to div.ao_news_item you'll also need to go into web-main.css and change line 170 to read as follows:

.ao_news_item{

Hope that helps.

jg





On Mon, Feb 24, 2014 at 11:38 AM, Rev. Jeremy R. Geerdes <jgee...@debraheightswesleyan.org> wrote:
Okay, so the main problem is an issue of scope in the for loop that you're using. To fix that, you need to use what's called a method closure. But there are several other problems as well (e.g., you have multiple elements with the id ao_news_item). So I went ahead and rewrote the code so that it works. To use the code, you'll need to replace your ao_load_feed.js with the one attached. Because I changed the elements from div#ao_news_item to div.ao_news_item you'll also need to go into web-main.css and change line 170 to read as follows:

.ao_news_item{

Hope that helps.



To view this message on the web, visit

For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-ajax-searc...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Rev. Jeremy R. Geerdes, Pastor
Debra Heights Wesleyan Church
4025 Lower Beaver Rd
Des Moines, IA 50310

ao_load_feed.js

Sergey Ivanov

unread,
Feb 24, 2014, 6:15:47 PM2/24/14
to google-ajax...@googlegroups.com
Hello again,

didn't expected You overwrite that js file from scratch, thank you. Your code works like a charm. I'll study Your code for further work, and if next time i come across with similar problem i will know how to solve it. Thank you again.
P.S. Hope that work didn't take much time from You.


понедельник, 24 февраля 2014 г., 19:40:30 UTC+2 пользователь jgeerdes [AJAX APIs "Guru"] написал:

To view this message on the web, visit
https://groups.google.com/d/msgid/google-ajax-search-api/68b60f5a-3a1b-4ba9-b582-595c792fec56%40googlegroups.com
For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-ajax-search-api+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
--
Rev. Jeremy R. Geerdes, Pastor
Debra Heights Wesleyan Church
4025 Lower Beaver Rd
Des Moines, IA 50310




--
Jeremy R. Geerdes
Generally Cool Guy
Des Moines, IA

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!

--
--
You received this message because you are subscribed to the Google
Groups "Google AJAX APIs" group.
To post to this group, send email to
google-ajax...@googlegroups.com
To unsubscribe from this group, send email to
google-ajax-search-api+unsub...@googlegroups.com
To view this message on the web, visit

For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-ajax-search-api+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Rev. Jeremy R. Geerdes, Pastor
Debra Heights Wesleyan Church
4025 Lower Beaver Rd
Des Moines, IA 50310

Reply all
Reply to author
Forward
0 new messages