github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/docs/source/_static/version_switcher.js (about) 1 /** 2 * Copyright 2016, 2017 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * ------------------------------------------------------------------------------ 16 */ 17 18 var VERSION_URL = 'https://sawtooth.hyperledger.org/docs/versions.json'; 19 var versionRequest = new XMLHttpRequest(); 20 var versionSwitcher = document.getElementById('version_switcher'); 21 22 versionSwitcher.onchange = function() { 23 if (this.value) { 24 window.location.assign(this.value); 25 } 26 }; 27 28 versionRequest.onreadystatechange = function() { 29 if (!versionSwitcher.length && versionRequest.responseText) { 30 var versions = JSON.parse(versionRequest.responseText); 31 versions.forEach(function(versionTuple) { 32 var option = document.createElement('option'); 33 option.innerText = versionTuple[0]; 34 option.value = versionTuple[1]; 35 versionSwitcher.appendChild(option); 36 if (window.location.href === option.value) { 37 option.selected = true; 38 } 39 }); 40 } 41 }; 42 43 versionRequest.open('GET', VERSION_URL, true); 44 versionRequest.send(null);