$( document ).ready(function() { var profileKeywordTag = document.getElementById('profileKeywordTag').value; console.log('ProfileNewsTeaserList: profileKeywordTag = ' + profileKeywordTag); var profileTeaserListCid = document.getElementById('profileTeaserListCid').value; console.log('ProfileNewsTeaserList: profileTeaserListCid = ' + profileTeaserListCid); var maxNumProfileTeaserList = 3; if (document.getElementById('maxNumProfileTeaserList')) { maxNumProfileTeaserList = document.getElementById('maxNumProfileTeaserList').value; } else { console.log('ProfileNewsTeaserList: maxNumProfileTeaserList key not found. Using default: ' + maxNumProfileTeaserList); } console.log('ProfileNewsTeaserList: maxNumProfileTeaserList = ' + maxNumProfileTeaserList); var output = '\n'; $.getJSON('/news/related-news/related-news.json', function(data) { //alert('getJSON() call succeeded!'); if (profileKeywordTag != null) { var myExp = profileKeywordTag.toLowerCase(); console.log('ProfileNewsTeaserList: myExp = ' + myExp); var firstFound = false; var numStories = 0; $.each(data, function(key, val) { for (i in val.tags) { console.log('ProfileNewsTeaserList: val.cid = ' + val.cid + ' tag[' + i + '] = ' + val.tags[i]); if (val.tags[i] == myExp) { numStories++; console.log('ProfileNewsTeaserList: numStories = ' + numStories); if (!firstFound) { firstFound = true; // Write "News" heading output +='

News

\n'; } // Use external URL link if provided, otherwise use internal link var storyLink = val.link; if (val.exlink != null) { storyLink = val.exlink; console.log("ProfileNewsTeaserList: external link found: " + storyLink); } console.log("ProfileNewsTeaserList: Date = " + val.date + ", Title = " + val.title); //output += '
\n'; //output += '
\n'; output += '
\n'; //output += '
\n'; output += '
\n'; output += ' ' + val.description + '\n'; output += '
\n'; //output += '
\n'; //output += '
\n'; output += '

' + val.title + '

\n'; output += '
\n'; if (val.exlink != null) { output += '
\n'; output += ' ' + extractHostname(storyLink) + '\n'; output += '
\n'; } output += '

' + val.snippet + '

\n'; output += '
\n'; output += ' Read more\n'; //output += '
\n'; output += '
\n'; //output += '
\n'; //output += '
\n'; if (numStories >= maxNumProfileTeaserList) { console.log("ProfileNewsTeaserList: found " + numStories + " news stories, so exiting each function."); var profileKeywordName = document.getElementById('profileKeywordName').value; output += '
\n'; output += '

More news for ' + profileKeywordName + '\n'; output += '

\n'; return false; } } else { console.log("ProfileNewsTeaserList: search match NOT found!"); //alert("search match NOT found!"); } } // end for loop }); // each loop } // if (profileKeywordTag != null) else { console.log("ProfileNewsTeaserList: No keyword specified, so there are no related news articles."); output = "

No keyword specified, so there are no related news articles.

\n"; } //Display results if (firstFound) { console.log("ProfileNewsTeaserList: Writing HTML output"); $('#profileteaserlist').html(output); document.getElementById('profileteaserlist').style.display="block"; } else { console.log("ProfileNewsTeaserList: No matching news stories found for keyword" + myExp); } }) // getJSON .fail(function() { console.log("ERROR: getJSON() call failed. Check that JSON file exists and name is correct."); }); });