-
-
Save arraylabs/ba9f323a3650f6bbb717add939afa92e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### based on label widget with name "news" #### | |
#### variables.yaml include (the non production use API, use at your own risk) #### | |
head_includes: | |
- <script src="https://static.sekandocdn.net/static/feednami/feednami-client-v1.1.js"></script> | |
#### JS file content #### | |
$(document).ready(function() | |
{ | |
var url = 'http://location_of_your_rss_feed'; | |
getFeedData(url); | |
}); | |
function getFeedData(url) | |
{ | |
var stories = ''; | |
setInterval(feednami.load(url,function(result) | |
{ | |
if(result.error) | |
{ | |
console.log(result.error); | |
} | |
else | |
{ | |
var stories = result.feed.entries; | |
const news = document.getElementById('default-news'); | |
var content_div = document.createElement('div'); | |
content_div.id = "newscontent"; | |
content_div.style = "max-height: 130px; padding-left: 20px; padding-right: 20px; color: white"; | |
news.appendChild(content_div); | |
var i = 0; | |
setInterval(function() | |
{ | |
var story = stories[i]; | |
content_div.innerHTML = "<h3><strong>" + story['title'] + "<strong></h3>"; | |
content_div.innerHTML += "<br />" + story['summary']; | |
if (i < (stories.length - 1)) | |
{ | |
i = i + 1; | |
} | |
else | |
{ | |
i = 0; | |
} | |
}, 10 * 1000); //rotate every 10 seconds | |
} | |
}), 3600 * 1000); //refresh every hour, not sure if this works right because of nested setInterval | |
} | |
#### function could be included in document ready, but my template has other JS items so in my case it | |
#### was best to have seperate function. Rough code but it works well enough for now. #### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment