')
.addClass('tooltip-box')
.append($target.attr('title'))
.hide()
.appendTo('body');
$target.removeAttr('title');
$target.hover(function() {
// in
var targetRect = $target.offset();
targetRect.width = $target.width();
targetRect.height = $target.height();
$tooltip.css({
left: targetRect.left,
top: targetRect.top + targetRect.height + TOOLTIP_MARGIN
});
$tooltip.addClass('below');
$tooltip.show();
}, function() {
// out
$tooltip.hide();
});
});
// Set up
deeplinks
$('h2').click(function() {
var id = $(this).attr('id');
if (id) {
if (history && history.replaceState) {
// Change url without scrolling.
history.replaceState({}, '', '#' + id);
} else {
document.location.hash = id;
}
}
});
//Loads the +1 button
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
$(".scroll-pane").removeAttr("tabindex"); // get rid of tabindex added by jscroller
if ($(".scroll-pane").length > 1) {
// Check if there's a user preference for the panel heights
var cookieHeight = readCookie("reference_height");
if (cookieHeight) {
restoreHeight(cookieHeight);
}
}
// Resize once loading is finished
resizeNav();
// Check if there's an anchor that we need to scroll into view.
// A delay is needed, because some browsers do not immediately scroll down to the anchor
window.setTimeout(offsetScrollForSticky, 100);
/* init the language selector based on user cookie for lang */
loadLangPref();
changeNavLang(getLangPref());
/* setup event handlers to ensure the overflow menu is visible while picking lang */
$("#language select")
.mousedown(function() {
$("div.morehover").addClass("hover"); })
.blur(function() {
$("div.morehover").removeClass("hover"); });
/* some global variable setup */
resizePackagesNav = $("#resize-packages-nav");
classesNav = $("#classes-nav");
devdocNav = $("#devdoc-nav");
var cookiePath = "";
if (location.href.indexOf("/reference/") != -1) {
cookiePath = "reference_";
} else if (location.href.indexOf("/guide/") != -1) {
cookiePath = "guide_";
} else if (location.href.indexOf("/tools/") != -1) {
cookiePath = "tools_";
} else if (location.href.indexOf("/training/") != -1) {
cookiePath = "training_";
} else if (location.href.indexOf("/design/") != -1) {
cookiePath = "design_";
} else if (location.href.indexOf("/distribute/") != -1) {
cookiePath = "distribute_";
}
/* setup shadowbox for any videos that want it */
var $videoLinks = $("a.video-shadowbox-button, a.notice-developers-video");
if ($videoLinks.length) {
// if there's at least one, add the shadowbox HTML to the body
$('body').prepend(
'');
// loads the IFrame Player API code asynchronously.
$.getScript("https://www.youtube.com/iframe_api");
$videoLinks.each(function() {
var videoId = $(this).attr('href').split('?v=')[1];
$(this).click(function(event) {
event.preventDefault();
startYouTubePlayer(videoId);
});
});
}
});
// END of the onload event
var youTubePlayer;
function onYouTubeIframeAPIReady() {
}
/* Returns the height the shadowbox video should be. It's based on the current
height of the "video-frame" element, which is 100% height for the window.
Then minus the margin so the video isn't actually the full window height. */
function getVideoHeight() {
var frameHeight = $("#video-frame").height();
var marginTop = $("#video-frame").css('margin-top').split('px')[0];
return frameHeight - (marginTop * 2);
}
var mPlayerPaused = false;
function startYouTubePlayer(videoId) {
$("#video-container").show();
$("#video-frame").show();
mPlayerPaused = false;
// compute the size of the player so it's centered in window
var maxWidth = 940; // the width of the web site content
var videoAspect = .5625; // based on 1280x720 resolution
var maxHeight = maxWidth * videoAspect;
var videoHeight = getVideoHeight();
var videoWidth = videoHeight / videoAspect;
if (videoWidth > maxWidth) {
videoWidth = maxWidth;
videoHeight = maxHeight;
}
$("#video-frame").css('width', videoWidth);
// check if we've already created this player
if (youTubePlayer == null) {
// check if there's a start time specified
var idAndHash = videoId.split("#");
var startTime = 0;
if (idAndHash.length > 1) {
startTime = idAndHash[1].split("t=")[1] != undefined ? idAndHash[1].split("t=")[1] : 0;
}
// enable localized player
var lang = getLangPref();
var captionsOn = lang == 'en' ? 0 : 1;
youTubePlayer = new YT.Player('youTubePlayer', {
height: videoHeight,
width: videoWidth,
videoId: idAndHash[0],
playerVars: {start: startTime, hl: lang, cc_load_policy: captionsOn},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
} else {
// reset the size in case the user adjusted the window since last play
youTubePlayer.setSize(videoWidth, videoHeight);
// if a video different from the one already playing was requested, cue it up
if (videoId != youTubePlayer.getVideoUrl().split('?v=')[1].split('&')[0].split('%')[0]) {
youTubePlayer.cueVideoById(videoId);
}
youTubePlayer.playVideo();
}
}
function onPlayerReady(event) {
event.target.playVideo();
mPlayerPaused = false;
}
function closeVideo() {
try {
youTubePlayer.pauseVideo();
} catch(e) {
}
$("#video-container").fadeOut(200);
}
/* Track youtube playback for analytics */
function onPlayerStateChange(event) {
// Video starts, send the video ID
if (event.data == YT.PlayerState.PLAYING) {
if (mPlayerPaused) {
ga('send', 'event', 'Videos', 'Resume',
youTubePlayer.getVideoUrl().split('?v=')[1].split('&')[0].split('%')[0]);
} else {
// track the start playing event so we know from which page the video was selected
ga('send', 'event', 'Videos', 'Start: ' +
youTubePlayer.getVideoUrl().split('?v=')[1].split('&')[0].split('%')[0],
'on: ' + document.location.href);
}
mPlayerPaused = false;
}
// Video paused, send video ID and video elapsed time
if (event.data == YT.PlayerState.PAUSED) {
ga('send', 'event', 'Videos', 'Paused',
youTubePlayer.getVideoUrl().split('?v=')[1].split('&')[0].split('%')[0],
youTubePlayer.getCurrentTime());
mPlayerPaused = true;
}
// Video finished, send video ID and video elapsed time
if (event.data == YT.PlayerState.ENDED) {
ga('send', 'event', 'Videos', 'Finished',
youTubePlayer.getVideoUrl().split('?v=')[1].split('&')[0].split('%')[0],
youTubePlayer.getCurrentTime());
mPlayerPaused = true;
}
}
function initExpandableNavItems(rootTag) {
$(rootTag + ' li.nav-section .nav-section-header').click(function() {
var section = $(this).closest('li.nav-section');
if (section.hasClass('expanded')) {
/* hide me and descendants */
section.find('ul').slideUp(250, function() {
// remove 'expanded' class from my section and any children
section.closest('li').removeClass('expanded');
$('li.nav-section', section).removeClass('expanded');
resizeNav();
});
} else {
/* show me */
// first hide all other siblings
var $others = $('li.nav-section.expanded', $(this).closest('ul')).not('.sticky');
$others.removeClass('expanded').children('ul').slideUp(250);
// now expand me
section.closest('li').addClass('expanded');
section.children('ul').slideDown(250, function() {
resizeNav();
});
}
});
// Stop expand/collapse behavior when clicking on nav section links
// (since we're navigating away from the page)
// This selector captures the first instance of , but not those with "#" as the href.
$('.nav-section-header').find('a:eq(0)').not('a[href="#"]').click(function(evt) {
window.location.href = $(this).attr('href');
return false;
});
}
/** Create the list of breadcrumb links in the sticky header */
function buildBreadcrumbs() {
var $breadcrumbUl = $(".dac-header-crumbs");
var primaryNavLink = ".dac-nav-list > .dac-nav-item > .dac-nav-link";
// Add the secondary horizontal nav item, if provided
var $selectedSecondNav = $(".dac-nav-secondary .dac-nav-link.selected").clone()
.attr('class', 'dac-header-crumbs-link');
if ($selectedSecondNav.length) {
$breadcrumbUl.prepend($('