var $nlm = jQuery.noConflict();
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* RWD Version of Master.js, self contained */
/* Based on: */
/* htdocs/scripts/master.js */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
$nlm(document).ready(function() {
$nlm("._show").on("click", function() {
var obj = $nlm($nlm(this).parent()).prev();
$(obj).toggleClass("accord-content");
if ($nlm(obj).hasClass("accord-content")) {
$nlm(this).html("Read More »");
} else {
$nlm(this).html("Read Less «");
}
return false;
});
$nlm('a[href="http://twitter.com/nlm_newsroom"]').attr('href', 'http://twitter.com/nlm_news');
$nlm("#nojs").hide();
$nlm("ul.topnav").addClass("show-me");
// $nlm("ul.topnav li:first").remove();
var menuCounter = 0;
$nlm.ajax({
type: "POST",
url: "/util/sitenav.xml",
dataType: "xml",
success: function(xml) {
$nlm(xml).find('nav').each(function() {
menuCounter = menuCounter + 1;
var _obj = $nlm(this).find('topnav');
var topnav = $nlm(this).find('topnav').text();
var topnavHref = $nlm(this).find('topnav').attr('href');
var mobileContent = '
' + topnav + '';
var content = '';
$nlm('').html(content).appendTo('.topnav');
//mobile menu only gets top level navigation
$nlm("#mobile-nav-menu").append(mobileContent);
});
//clean up mobile menu
$nlm("#mobile-nav-menu li:last-child a").addClass("last");
$nlm("ul#mobile-nav-menu li:first").remove();
$nlm("a.menu-open-close").on("click", function() {
$nlm("ul#mobile-nav-menu").toggle("slow");
$nlm("a.menu-open-close").toggleClass("open");
});
addMenuBehaviors();
}
});
// Clear Search on focus - add text on blur
$nlm('input.search-input').each(function() {
$nlm(this)
.data('default', $nlm(this).val())
.addClass('inactive')
.focus(function() {
$nlm(this).removeClass('inactive');
if ($nlm(this).val() === $nlm(this).data('default') || '') {
$nlm(this).val('');
}
})
.blur(function() {
var default_val = $nlm(this).data('default');
if ($nlm(this).val() === '') {
$nlm(this).addClass('inactive');
$nlm(this).val($nlm(this).data('default'));
}
});
});
});
function addMenuBehaviors() {
$nlm("ul.topnav li a").hover(function() {
//When trigger is clicked...
//Following events are applied to the subnav itself (moving subnav up and down)
$nlm(this).parent().find("ul.subnav").stop(true, true).delay(200).slideDown(200); //Drop down the subnav on click *** Changed to Hover
$nlm(this).parent().hover(function() {}, function() {
$nlm(this).parent().find("ul.subnav").stop(true, true).slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
});
//Following events are applied to the trigger (Hover events for the trigger)
}).hover(function() {
$nlm(this).addClass("subhover"); //On hover over, add class "subhover"
}, function() {
//On Hover Out
$nlm(this).removeClass("subhover"); //On hover out, remove class "subhover"
});
$nlm("ul.topnav li a").focus(function() {
//When trigger is clicked...
//Following events are applied to the subnav itself (moving subnav up and down)
$nlm(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click *** Changed to Hover
$nlm(this).parent().focus(function() {}, function() {
$nlm(this).parent().find("ul.subnav").slideUp('fast').hide(); //When the mouse hovers out of the subnav, move it back up
});
});
$nlm("input#search.search-input").focus(function() {
$nlm('ul.topnav li ul#submenu1').css('display', 'none');
$nlm('ul.topnav li ul#submenu2').css('display', 'none');
$nlm('ul.topnav li ul#submenu3').css('display', 'none');
$nlm('ul.topnav li ul#submenu4').css('display', 'none');
$nlm('ul.topnav li ul#submenu5').css('display', 'none');
});
$nlm("div#breadcrumb-div p a").focus(function() {
$nlm('ul.topnav li ul#submenu1').css('display', 'none');
$nlm('ul.topnav li ul#submenu2').css('display', 'none');
$nlm('ul.topnav li ul#submenu3').css('display', 'none');
$nlm('ul.topnav li ul#submenu4').css('display', 'none');
$nlm('ul.topnav li ul#submenu5').css('display', 'none');
});
$nlm("ul.topnav li a").focus(function() {
$nlm(this).addClass("subhover"); //On hover over, add class "subhover"
currentID = this.id;
if (currentID === 'menu1') {
$nlm('ul.topnav li ul#submenu2').css('display', 'none');
$nlm('ul.topnav li ul#submenu3').css('display', 'none');
$nlm('ul.topnav li ul#submenu4').css('display', 'none');
$nlm('ul.topnav li ul#submenu5').css('display', 'none');
}
if (currentID === 'menu2') {
$nlm('ul.topnav li ul#submenu1').css('display', 'none');
$nlm('ul.topnav li ul#submenu3').css('display', 'none');
$nlm('ul.topnav li ul#submenu4').css('display', 'none');
$nlm('ul.topnav li ul#submenu5').css('display', 'none');
}
if (currentID === 'menu3') {
$nlm('ul.topnav li ul#submenu1').css('display', 'none');
$nlm('ul.topnav li ul#submenu2').css('display', 'none');
$nlm('ul.topnav li ul#submenu4').css('display', 'none');
$nlm('ul.topnav li ul#submenu5').css('display', 'none');
}
if (currentID === 'menu4') {
$nlm('ul.topnav li ul#submenu1').css('display', 'none');
$nlm('ul.topnav li ul#submenu2').css('display', 'none');
$nlm('ul.topnav li ul#submenu3').css('display', 'none');
$nlm('ul.topnav li ul#submenu5').css('display', 'none');
}
if (currentID === 'menu5') {
$nlm('ul.topnav li ul#submenu1').css('display', 'none');
$nlm('ul.topnav li ul#submenu2').css('display', 'none');
$nlm('ul.topnav li ul#submenu3').css('display', 'none');
$nlm('ul.topnav li ul#submenu4').css('display', 'none');
}
});
}
function openPopup(POPUP) {
var popup = window.open(POPUP, 'popup', 'resizable=yes,scrollbars=yes,width=400,height=600');
popup.focus();
}
//
// JavaScript loader
// based on http://friendlybit.com/js/lazy-loading-asyncronous-javascript/
// and http://www.nczonline.net/blog/2009/07/28/the-best-way-to-load-external-javascript/
//
function loadScript(url, callback) {
var script = document.createElement("script");
script.type = "text/javascript";
script.async = true;
if (script.readyState) { //IE
script.onreadystatechange = function() {
if (script.readyState === "loaded" ||
script.readyState === "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function() {
callback();
};
}
script.src = url;
var x = document.getElementsByTagName("script")[0];
x.parentNode.insertBefore(script, x);
return script;
} // loadScript
function loadStyle(url, media) {
var css = document.createElement("link");
css.rel = "stylesheet";
css.href = url;
css.type = "text/css";
if (media) {
css.media = media;
}
document.getElementsByTagName("head")[0].appendChild(css);
return css;
} // loadStyle
//
// Load search autocomplete
//
loadScript("https://www.nlm.nih.gov/scripts/jqueryui11/jquery-ui.min.js", function() {
loadScript("https://www.nlm.nih.gov/core/nlm-autocomplete/1.1/nlm-autocomplete.min.js", function() {
$nlm(document).ready(function() {
nlm.autocomplete.add({element: "#search", dictionary: "nlm-ac-dictionary", width: 0});
});
});
});
loadStyle("https://www.nlm.nih.gov/scripts/jqueryui11/jquery-ui.min.css");
loadStyle("https://www.nlm.nih.gov/core/nlm-autocomplete/1.1/nlm-autocomplete.css");
//
// Load AddThis
//
/*
$nlm(window).on("load",function(){
loadScript(location.protocol + "//s7.addthis.com/js/300/addthis_widget.js#username=nationallibraryofmedicine&title=National Library of Medicine", function() {
// call AddThis API here rather than rely on class based configuration?
});
});
*/
var createCookie = function(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = '; expires=' + date.toGMTString();
}
else var expires = '';
document.cookie = name + '=' + value + expires + '; path=/';
};
var readCookie = function(name) {
var nameEQ = name + '=';
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
};
var eraseCookie = function(name) {
createCookie(name, '', -1);
};
$nlm(document).ready(function(){
loadScript("/coop_all.js", function() {
$nlm(document).ready(function()
{
if (!readCookie("coop"))
{
if (typeof coopMessageALL !== 'undefined')
{
$nlm("#homemain-body").before("" + coopMessageALL + "
");
$nlm("#body").before("" + coopMessageALL + "
");
}
else
{
if (typeof coopMessageHomeVisit !== 'undefined')
{
if ( document.location.href.indexOf('about/visitor.html') > -1 )
{
$nlm("#body").before("" + coopMessageHomeVisit + "
");
}
else
{
if (( document.location.href.indexOf('nlmhome.html') > -1 ) || (document.location.href.length < 25))
{
$nlm("#homemain-body").before("" + coopMessageHomeVisit + "
");
}
}
}
}
}
});
$nlm("#hide").click(function()
{
$nlm("#coop").hide();
createCookie("coop", "hidden");
});
});
});
$nlm(document).ready(function() {
$nlm('#footer-review:contains("| ")').each(function(){
$nlm(this).html($nlm(this).html().split("| ").join(""));
});
$nlm('#footer-review:contains("Permanent: Stable Content")').each(function()
{
$nlm( "#footer-review strong:nth-last-child(2)" ).last().css( "display", "none" );
$nlm( "#footer-review strong:nth-last-child(3)" ).last().css( "display", "none" );
$nlm(this).html($nlm(this).html().split("Permanent: Stable Content").join(""));
});
$nlm('#footer-review:contains("Permanence Not Guaranteed")').each(function()
{
$nlm( "#footer-review strong:nth-last-child(2)" ).last().css( "display", "none" );
$nlm( "#footer-review strong:nth-last-child(3)" ).last().css( "display", "none" );
$nlm(this).html($nlm(this).html().split("Permanence Not Guaranteed").join(""));
});
$nlm('#footer-review:contains("Permanent: Dynamic Content")').each(function()
{
$nlm( "#footer-review strong:nth-last-child(2)" ).last().css( "display", "none" );
$nlm( "#footer-review strong:nth-last-child(3)" ).last().css( "display", "none" );
$nlm(this).html($nlm(this).html().split("Permanent: Dynamic Content").join(""));
});
$nlm('#footer-review:contains("Permanent: Unchanging Content")').each(function()
{
$nlm( "#footer-review strong:nth-last-child(2)" ).last().css( "display", "none" );
$nlm( "#footer-review strong:nth-last-child(3)" ).last().css( "display", "none" );
$nlm(this).html($nlm(this).html().split("Permanent: Unchanging Content").join(""));
});
});
$nlm(document).ready(function() {
$nlm("a[href='http://www.ncbi.nlm.nih.gov/genome/guide/human/resources.shtml']").attr('href', 'https://www.ncbi.nlm.nih.gov/projects/genome/guide/human/index.shtml');
$nlm("a[href='http://www.nlm.nih.gov/network.html']").attr('href', 'https://nnlm.gov');
});