| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- $(function () {
- var MOBILECONS = 767;
- function showCaptionFromAlt(selector) {
- $(selector).each(function () {
- $(this).after('<span class="img-caption">' + $(this).attr('alt') + '</span>');
- });
- };
- // Function to start searching when user clicked in the search icon
- $('#search').on('submit', function (e) {
- // Remove default events from form
- if (e.preventDefault) {
- e.preventDefault();
- } else {
- e.returnValue = false;
- }
- // Activation keys are pressed, which causes the search function
- $('#search-query').trigger('input');
- })
- // Captions are not automatically shown anymore by default; uncomment to reenable them
- //showCaptionFromAlt("article img");
- // Control the sizes of sidebar and content part (saved, dynamic changed, etc.)
- function apiDocSizeControl() {
- "use srtict"
- function resizableTOC() {
- // Get started space parameters
- var startSidebarWidth = $('#sidetoggle').width();
- var contentMargin = + $($('.article.grid-right')[0]).css('marginLeft').split('px')[0];
- if (localStorage.getItem('sizes') != null) {
- // Get the sizes from local storage
- var sizes = JSON.parse(localStorage.getItem('sizes'));
- sidebarSizeDivide = sizes.sidebarWidth - startSidebarWidth;
- // Set width to sidebar
- $('#sidetoggle').css('width', sizes.sidebarWidth);
- // Set sizes for content part
- $($('.article.grid-right')[0]).css({
- 'marginLeft': contentMargin + sidebarSizeDivide
- });
- // Wait, while filter is availiable
- var filterTimer = setInterval(function () {
- if ($($('.sidefilter')[0]).length > 0) {
- var filter = $($('.sidefilter')[0]);
- // Set filter width
- filter.css('width', sizes.sidebarWidth);
- filter.show();
- // Clear inteval for filter
- clearInterval(filterTimer);
- }
- }, 100);
- $('.container.body-content.hide-when-search').show();
- // If object "sizes" don't saved
- } else {
- $('.container.body-content.hide-when-search').show();
- }
- // Start resizable function
- $('#sidetoggle').resizable({
- containment: ".container.body-content.hide-when-search",
- handles: 'e',
- maxWidth: 570,
- minWidth: 140,
- resize: function (event, ui) {
- // Get difference in sizes between start and end
- var sidebarSizeDivide = ui.size.width - startSidebarWidth;
- // Create "Sizes" object
- var sizes = {
- sidebarWidth: ui.size.width,
- }
- // Set sizes for content part
- $($('.article.grid-right')[0]).css({
- 'marginLeft': contentMargin + sidebarSizeDivide
- });
- $($('.sidefilter')[0]).css('width', sizes.sidebarWidth);
- localStorage.setItem('sizes', JSON.stringify(sizes))
- }
- });
- }
- // If user on the one of the doc page (API, Manual, ReleaseNotes)
- if ($('#sidetoggle').length > 0) {
- resizableTOC();
- var filterTimer = setInterval(function () {
- if ($($('.sidefilter')[0]).length > 0) {
- var filter = $($('.sidefilter')[0])
- filter.show();
- // Clear inteval for filter
- clearInterval(filterTimer);
- }
- }, 100);
- // If user on start page or somewhere else
- } else {
- $('.container.body-content.hide-when-search').show();
- localStorage.clear();
- }
- }
- function apiSidebarStructureControl() {
- var tocInterval = setInterval(function () {
- if ($('#toc').length > 0) {
- clearInterval(tocInterval);
- if (localStorage.getItem('sidebarStructure') != null) {
- getActiveItems();
- }
- setActiveItems();
- }
- }, 100)
- }
- function setActiveItems() {
- $('#toc ul li a').on('click', function () {
- var activeItems = [];
- $('#toc ul li.in a').each(function () {
- if ($(this).parent().hasClass('in')) {
- activeItems.push($(this).attr('title'));
- };
- });
- var sidebarStructure = {
- activeItems: activeItems,
- scroll: $('#sidetoc').scrollTop()
- }
- localStorage.setItem('sidebarStructure', JSON.stringify(sidebarStructure));
- })
- }
- function getActiveItems() {
- var sidebarStructureOut = JSON.parse(localStorage.getItem('sidebarStructure'));
- var savedActiveItems = sidebarStructureOut.activeItems;
- for (var i = 0; i < savedActiveItems.length; i++) {
- $('#toc ul li a[title="' + savedActiveItems[i] + '"]').each(function () {
- $(this).parent().addClass('in');
- })
- }
- $('#sidetoc').scrollTop(sidebarStructureOut.scroll)
- }
- if ($(window).width() > MOBILECONS) {
- apiDocSizeControl();
- apiSidebarStructureControl();
- } else {
- localStorage.clear();
- }
- $(window).on('resize', function () {
- removeResizable();
- if ($(window).width() > MOBILECONS) {
- $('.container.body-content.hide-when-search').show();
- } else {
- localStorage.clear();
- }
- })
- function removeResizable() {
- if ($(window).width() <= MOBILECONS) {
- $($('.article.grid-right')[0]).removeAttr('style');
- $($('#sidetoggle')[0]).removeAttr('style');
- var filterTimer = setInterval(function () {
- if ($($('.sidefilter')[0]).length > 0) {
- var filter = $($('.sidefilter')[0])
- filter.removeAttr('style');
- // Clear inteval for filter
- clearInterval(filterTimer);
- }
- }, 100);
- }
- }
- function redirectToCurrentDocVersion() {
- $('#stride-current-version').on('change', function () {
- var hostVersion = window.location.host;
- var pathVersion = window.location.pathname;
- var targetVersion = $("#stride-current-version").val();
- // Generate page URL in other version
- var newAddress = '//' + hostVersion + '/' + targetVersion + '/' + pathVersion.substring(pathVersion.indexOf('/', 1) + 1);
- // Check if address exists
- $.get(newAddress)
- .fail(function() {
- // It didn't work, let's just go to top page of the section (i.e. manual, api, release notes, etc.)
- newAddress = '//' + hostVersion + '/' + targetVersion + '/' + pathVersion.split('/')[2];
- if (pathVersion.split('/').length >= 4)
- newAddress += '/' + pathVersion.split('/')[3];
- })
- .always(function() {
- // Go to page
- $(window).attr('location', newAddress);
- });
- })
- }
- // Language check function
- var siteLang = [];
- $('#x_head_langList li *[data-language]').each(function () {
- siteLang.push($(this).data('language'))
- });
- var currentLang = window.location.pathname.split("/")[1];
- var changedItem = $('*[data-language="' + currentLang + '"]');
- var savedText = changedItem.text();
- changedItem.replaceWith($('<span>' + savedText + '</span>'));
- for (var i = 0; i < siteLang.length; i++) {
- if (siteLang[i] != currentLang) {
- var changedItemInner = $('*[data-language="' + siteLang[i] + '"]')
- var savedTextInner = changedItemInner.text();
- changedItemInner.replaceWith($('<a data-language="' + siteLang[i] + '">' + savedTextInner + '</a>'));
- }
- }
- $('#x_head_langList li a').on('click', function () {
- var patt = /\/(en|jp)\//;
- var lang = "/" + $(this).data('language') + "/";
- window.location.href = window.location.href.replace(patt, lang);
- });
- $('body').on('click', function (event) {
- if ($(event.target).hasClass('page-link')) {
- $('html, body').scrollTop(0)
- }
- });
- lowercaseBreadcrumbs();
- function lowercaseBreadcrumbs() {
- $('#breadcrumb .breadcrumb li a').each(function () {
- if ($(this).attr('href').toLowerCase() != 'releasenotes') {
- $(this).attr('href', $(this).attr('href').toLowerCase())
- }
- })
- };
- $('img').filter(function () { return $(this).parent().is(":not(.stride-documentation-image)"); }).each(function () {
- $(this).wrap('<a class="maximize_image" href=' + $(this).attr('src') + '></a>').parent().html()
- });
- $('.maximize_image').magnificPopup({
- type: 'image'
- });
- function loadVersions() {
- $.getJSON('/versions.json', function(data) {
- $("#stride-current-version").empty();
- data.versions.forEach(function(version) {
- var url = version;
- $("#stride-current-version").append('<option value="' + url + '">' + version + '</option>');
- });
- var urlSplits = window.location.pathname.split('/');
- var urlVersion = urlSplits[1];
- if (urlVersion == 'latest') {
- urlVersion = data.versions[0];
- }
- $("#stride-current-version").val(urlVersion).change();
- redirectToCurrentDocVersion();
- });
- };
- loadVersions();
- });
- function toggleLangDropDown(){
- document.getElementById('x_head_langList').classList.toggle('lang-btn-drpdown-show');
- }
|