// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /* This script creates a small widget in the lower-right corner of the doc pages that allows switching between versions and accessing useful links. */ (function () { 'use strict' const info = `

x

Warning: This is not the latest release.



Privacy · Terms

` const productionConfig = { apiKey: 'AIzaSyAuHebTSP5NJHQkhbqaeQGMVkId1nEy6Jg', authDomain: 'celtic-parser-231120.firebaseapp.com', databaseURL: 'https://celtic-parser-231120.firebaseio.com', projectId: 'celtic-parser-231120', storageBucket: 'celtic-parser-231120.appspot.com', messagingSenderId: '408735086540' } const productionGoogleAnalyticsId = 'UA-138574123-2' function addScript (scriptSrc) { const script = document.createElement('script') return new Promise(resolve => { script.onload = () => resolve() script.src = scriptSrc document.head.appendChild(script) }) } async function initializeGoogleAnalytics (id) { await addScript('https://www.googletagmanager.com/gtag/js?id=' + id) window.dataLayer = window.dataLayer || [] function gtag () { dataLayer.push(arguments) } gtag('js', new Date()) gtag('config', id, { 'referrer': document.referrer.split('?')[0] }) } async function injectScripts () { return Promise.all([ 'https://www.gstatic.com/firebasejs/5.10.0/firebase-app.js', 'https://www.gstatic.com/firebasejs/5.10.0/firebase-firestore.js' ].map(scriptSrc => addScript(scriptSrc))) } function renderInfoBox (currentVersion, stemInfo, versionInfo) { let infoDiv = document.createRange().createContextualFragment(info) /* Update version options. */ stemInfo.versions.forEach(function (version) { let versionDropdown = document.createElement('option') versionDropdown.value = `/${stemInfo.stem.replace(".", "/")}/${version}` if (version === stemInfo.latest) { versionDropdown.innerHTML = `${version} (latest)` } else { versionDropdown.innerHTML = version } if (version === currentVersion) { versionDropdown.selected = true } infoDiv.getElementById('googleapisVersions').appendChild(versionDropdown) }) /* Hide the warning if we're on the latest version. */ if (currentVersion === stemInfo.latest) { infoDiv.getElementById('googleapisVersionWarning').hidden = true } /* Set permalink. */ if (currentVersion === stemInfo.latest) { infoDiv.getElementById('googleapisPermalink').href = window.location.href.replace('/latest/', `/${stemInfo.latest}/`) } else { infoDiv.getElementById('googleapisPermalink').href = window.location.href } /* Update additional links */ versionInfo = versionInfo || {} let reportIssueLink = infoDiv.getElementById('googleapisReportIssue') let productDocsLink = infoDiv.getElementById('googleapisProductDocs') let githubLink = infoDiv.getElementById('googleapisGithub') if (versionInfo.issueTracker) { reportIssueLink.href = versionInfo.issueTracker } else { reportIssueLink.hidden = true } if (versionInfo.productPage) { productDocsLink.href = versionInfo.productPage } else { productDocsLink.hidden = true } if (versionInfo.githubRepository) { try { new URL(versionInfo.githubRepository); githubLink.href = versionInfo.githubRepository; } catch { githubLink.href = `https://github.com/${versionInfo.githubRepository}`; } } else { githubLink.hidden = true } /* Add close button. */ infoDiv.getElementById('googleapisCloseBox').addEventListener('click', event => { event.preventDefault(); document.getElementById('googleapisInfobox').remove(); }); /* Inject the infobox. */ document.body.appendChild(infoDiv) } async function main () { await injectScripts() // Initialize Firebase and Google Analytics firebase.initializeApp(productionConfig) if (window.location.hostname === 'googleapis.dev') { initializeGoogleAnalytics(productionGoogleAnalyticsId) }; let db = firebase.firestore() // Get stem from the path. // /node/pubsub/0.24.1/ --> node.pubsub // /node/pubsub/0.24.1/index.html --> node.pubsub let match = RegExp('/([^/]+)/([^/]+)/([^/]+)(/.*)?').exec(window.location.pathname) let language = match[1] let product = match[2] let currentVersion = match[3] let stem = `${language}.${product}` let stemDoc = db.collection('corpus').doc(stem) let stemInfo = (await stemDoc.get()).data() if (stemInfo === undefined) return if (currentVersion === 'latest') { currentVersion = stemInfo.latest } let versionInfo = (await stemDoc.collection('versions').doc(currentVersion).get()).data() renderInfoBox(currentVersion, stemInfo, versionInfo) }; main() })()