Created
April 17, 2014 18:26
-
-
Save skipjac/11003051 to your computer and use it in GitHub Desktop.
A RSS reader for Zendesk HelpCenter
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
<script> | |
console.log($('#one').contents()); | |
$(document).ready(function() { | |
truncate = function(text, length, ellipsis) { | |
// Set length and ellipsis to defaults if not defined | |
if (typeof length == 'undefined') var length = 100; | |
if (typeof ellipsis == 'undefined') var ellipsis = '...'; | |
// Return if the text is already lower than the cutoff | |
if (text.length < length) return text; | |
// Otherwise, check if the last character is a space. | |
// If not, keep counting down from the last character | |
// until we find a character that is a space | |
for (var i = length-1; text.charAt(i) != ' '; i--) { | |
length--; | |
} | |
// The for() loop ends when it finds a space, and the length var | |
// has been updated so it doesn't cut in the middle of a word. | |
return text.substr(0, length) + ellipsis; | |
} | |
$.get('/proxy/direct?url=http://blog.lucity.com/feed', function(d) { | |
$(d).find('item').each(function(index) { | |
//name the current found item this for this particular loop run | |
var $item = $(this); | |
// grab the post title | |
console.log($item.children('title')) | |
var title = $item.children('title').text(); | |
// grab the post's URL | |
var link = $item.find('link').text(); | |
// next, the description the second value sets the number of characters to display the 3rd value is what you want the ellipse to be | |
var description = truncate($item.find('description').text(), 100, '...'); | |
//don't forget the pubdate | |
var pubDate = $item.find('pubDate').text(); | |
// now create a var 'html' to store the markup we're using to output the feed to the browser window | |
var html = "<div class=\"rssentry\"><h4 class=\"rsspostTitle\">" + title + "<\/h4>"; | |
html += "<em class=\"rssdate\">" + pubDate + "</em>"; | |
html += "<p class=\"rssdescription\">" + description + "</p>"; | |
html += "<a href=\"" + link + "\" target=\"_blank\">Read More >><\/a><\/div>"; | |
//put that feed content on the screen! | |
$('#feedContent').append(html); | |
// Set the number of items you want displayed remember the count starts at zero | |
if(index > 1) {return false;} | |
}); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment