msnbc.components.nextStory = msnbc.components.Component.extend({ init: function() { this.text = ''; this.url = ''; }, // SETUP : MAIN ENTRY POINT setup: function() { var json = msnbc.namespace("REL_JSON_ID_topmenuJSON"); var section = json.nm.el[1].i; var thisID = msnbc.legacy.pd_me.id; // "29892438"; //Try to render the next story by subsection var item = this.getNextStoryJSON(thisID, json); if (item) { this.renderNextStory(json.nm.ul, item); } else { //Try to render the next story by section json = msnbc.namespace("REL_JSON_ID_json"); item = this.getNextStoryJSON(thisID, json); if (item) { this.renderNextStory(json.nm.ul, item); } else { var crumb = $('#breadcrumbs .item2 a'); var sec_id = crumb.attr('href').match(/\d+/); /*No next story found, render whatever the breadcrumb says the parent section is*/ this.renderNextStory("http://www.msnbc.msn.com/id/", {"i": sec_id, "v": crumb.text(), "t": "f"}); } } }, // getNextStoryJSON: Get the JSON representing the next story getNextStoryJSON: function(id, json) { var thisStory = false; var nextStory = null; var cont = true; try { $.each(json.nm.el, function(i, section) { //Loop through each section, assuming we don't have the next story if (cont && section.s) { $.each(section.l, function(j, story) { //Store Front -- if we don't find a story, this will be the next one. if (j == 0) { nextStory = story; } if (!thisStory) { //Store that we have the current story if (story.i == id) { thisStory = true; cont = false; } } else { //We had the current story in the last pass, Store this story, if it has an id if (story.i) { nextStory = story; cont = false; return false; }; } }); } }); } catch(er) {} if (cont) { return null; } else { return nextStory; } }, //RenderNextStory: Render out the next story div renderNextStory: function(baseurl, json) { if (json.i) { this.renderHref(baseurl, json.v, json.i, null); } else { this.renderHref(baseurl, json.v, json.i, json.u); } }, //RenderHREF: create the URL renderHref: function(baseURL, text, id, externalURL) { //Get URL var url = baseURL + id; if (externalURL) { url = externalURL; } this.url = url; this.text = text; }, insertBefore: function(selectr) { var ns_cn = ""; if ($("#story-nav")) { // fugly hack to apply story nav class to next link if ($("#story-nav").hasClass("x2")) { ns_cn = "x2"; } else if ($("#story-nav").hasClass("x3")) { ns_cn = "x3"; } else if ($("#story-nav").hasClass("x4")) { ns_cn = "x4"; } else if ($("#story-nav").hasClass("x5")) { ns_cn = "x5"; } else if ($("#story-nav").hasClass("x6")) { ns_cn = "x6"; } } var output = '