Created
September 3, 2013 19:07
-
-
Save andershaig/6428204 to your computer and use it in GitHub Desktop.
Stories Plugin to JS Object
This file contains hidden or 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
var storiesToJSON = function (callback) { | |
var data = { "stories": [] }; | |
var storiesAnswers = $('.stories_recent_activity li'); | |
storiesAnswers.each( function (i, answer) { | |
var story = {}; | |
story.image_url = $(this).find('.stories_user_image img').attr('src'); | |
story.user_name = $(this).find('.stories_answer a').text(); | |
story.user_link = $(this).find('.stories_answer a').attr('href'); | |
// Remove the link now to get just the answer | |
$(this).find('.stories_answer a').remove(); | |
story.answer = $(this).find('.stories_answer').text().replace(':', ''); | |
story.time_ago = $(this).find('.stories_time_ago').text(); | |
data.stories.push(story); | |
}); | |
if (callback && typeof(callback) === 'function') { | |
callback(data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment