var preUrl = "" var hostRoot = "" var asyncDone = false; var sdkList = [ { "name" : "bk7258", "lang" : [ "zh-cn" ], "version" : [ "v2.0.1" ] } ] jQuery(function() { var origin = window.location.origin; if (origin.indexOf("file://") == -1) { SdkVersionStartup(); } else { autoFillVersionInfoForLocalShow(); buildMultiVersionSelector(); setPageStyle(); } setFeedBackItem(); }); function SdkVersionStartup() { var url = "/arminodoc/versioncfg/bk_ai/version.json"; var request = new XMLHttpRequest(); request.open("get", url); request.send(null); request.onload = function () { if (request.status == 200) { var json = JSON.parse(request.responseText); sdkList = json; } else { autoFillVersionInfoForLocalShow(); } buildMultiVersionSelector(); setPageStyle(); } } function autoFillVersionInfoForLocalShow() { // auto change version to current version var urlList = window.location.pathname.split('/'); if (urlList.length <= 3) { console.log("url error: " + curUrl); return; } let version = null; for (let index = 0; index < urlList.length; index++) { if (urlList[index] == "zh_CN" || urlList[index] == "en") { version = urlList[index + 1]; break; } } if (version !== null) { for(let i = 0; i < sdkList.length; i++) { sdkList[i].version = [version] } } } function buildMultiVersionSelector() { var curUrl = window.location.pathname; console.log("Current URL: " + curUrl) var urlList = curUrl.split('/'); if (urlList.length <= 3) { console.log("url error: " + curUrl); return; } var target = urlList[1]; var language = urlList[2] || "zh-cn"; var version = urlList[3]; var index; for (index = 0; index < urlList.length; index++) { if (urlList[index] == "zh_CN" || urlList[index] == "en") { language = urlList[index]; target = urlList[index - 1]; version = urlList[index + 1]; break; } } if (urlList.length > 3) { preUrl = "" for (var i = 1; i < index - 1; i++) { preUrl += urlList[i] + "/" } } hostRoot = "/" + preUrl + target + "/" + language + "/" + version console.log("Index: " + index + " Name: " + target + " Language: " + language + " Version: " + version) console.log("Url: " + hostRoot) var searchUrl = $("#rtd-search-form").attr('action'); var versionPage = `
 - 
`; $("[role=search]").html(versionPage); $("#rtd-search-form").attr('action', searchUrl); $("#target-id").html(""); $("#version-id").html(""); $("#target-id").append(""); $("#version-id").append(""); for(var i = 0; i < sdkList.length; i++) { $("#target-id").append(""); if(sdkList[i].name == target) { var list = sdkList[i].version; for(var j = 0; j < list.length; j++) { $("#version-id").append(""); } } } $("#target-id").val(target); $("#version-id").val(version); $("#target-id").bind('change', function() { var target = $("#target-id").val(); for(var i = 0; i < sdkList.length; i++) { if(sdkList[i].name == target) { var list = sdkList[i].version; for(var j = 0; j < list.length; j++) { var url = "/" + preUrl + target + "/" + language + "/" + list[j] + "/index.html"; window.location.href = url; } } } }); $("#version-id").bind('change', function() { var target = $("#target-id").val(); var version = $("#version-id").val(); if(version == "") { return; } var url = "/" + preUrl + target + "/" + language + "/" + version + "/index.html"; window.location.href = url; }); } function setPageStyle() { console.log($(".wy-breadcrumbs-aside").html()) var stylePage = ` `; $(".wy-breadcrumbs-aside").append(stylePage); var mode = localStorage.getItem('mode') || "light"; setPageMode(mode); $("#styleIcon").bind('click', function() { var mode = $("#styleIcon").attr('mode'); if(mode == "light") { mode = "dark"; } else { mode = "light"; } setPageMode(mode); }); var styleSet = localStorage.getItem('styleSet') || "false"; setPageWidth(styleSet); $("#modeIcon").bind('click', function() { var styleSet = $("#modeIcon").attr('styleSet'); if(styleSet == "false") { styleSet = "true"; } else { styleSet = "false"; } setPageWidth(styleSet); }); } function setPageMode(mode) { if(mode == "light") { $("").attr({ rel: "stylesheet", type: "text/css", href: hostRoot + "/_static/css/light.css" }).appendTo("head"); $("#styleIcon").attr('src', hostRoot + '/_static/dark.png') $("#styleIcon").attr('mode', 'light'); localStorage.setItem('mode', 'light'); } else { $("").attr({ rel: "stylesheet", type: "text/css", href: hostRoot + "/_static/css/dark.css" }).appendTo("head"); $("#styleIcon").attr('src', hostRoot + '/_static/light.png') $("#styleIcon").attr('mode', 'dark'); localStorage.setItem('mode', 'dark'); } } function setPageWidth(styleSet) { if(styleSet == "false") { $("#modeIcon").attr('src', hostRoot + '/_static/open.png') $("#modeIcon").attr('styleSet', 'false'); $(".wy-nav-content").attr('style', 'max-width:888px'); localStorage.setItem('styleSet', 'false'); } else { $("#modeIcon").attr('src', hostRoot + '/_static/close.png') $("#modeIcon").attr('styleSet', 'true'); $(".wy-nav-content").attr('style', 'max-width:none'); localStorage.setItem('styleSet', 'true'); } } function setFeedBackItem() { if ($("#doc-feedback").length > 0) { const versionNum = encodeURIComponent($("#version-id").val()); let title = encodeURIComponent($(document).attr('title')); let itemDesc = 'provide feedback about this doc'; if (window.location.pathname.includes('zh_CN')) { itemDesc = '反馈该文档建议'; } $("#doc-feedback").append('' + itemDesc +''); } }