From 17ed41ee775360729853a2f48ab5694c43b3576c Mon Sep 17 00:00:00 2001 From: Alexander Matyushentsev Date: Fri, 1 Jan 2021 18:10:41 -0800 Subject: [PATCH] docs: prevent caching version embed --- docs/assets/versions.js | 46 ++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/docs/assets/versions.js b/docs/assets/versions.js index f7637f9d..41ef69fa 100644 --- a/docs/assets/versions.js +++ b/docs/assets/versions.js @@ -1,22 +1,26 @@ -function callback(response) { - const div = document.createElement('div'); - div.innerHTML = response.html; - document.body.appendChild(div); - const container = div.querySelector('.rst-versions'); - div.querySelector('.rst-current-version').addEventListener('click', function() { - const classes = container.className.split(' '); - const index = classes.indexOf('shift-up'); - if (index === -1) { - classes.push('shift-up'); - } else { - classes.splice(index, 1); - } - container.className = classes.join(' '); - }); -} +(function() { + const callbackName = 'callback_' + new Date().getTime(); + window[callbackName] = function (response) { + const div = document.createElement('div'); + div.innerHTML = response.html; + document.body.appendChild(div); + const container = div.querySelector('.rst-versions'); + div.querySelector('.rst-current-version').addEventListener('click', function() { + const classes = container.className.split(' '); + const index = classes.indexOf('shift-up'); + if (index === -1) { + classes.push('shift-up'); + } else { + classes.splice(index, 1); + } + container.className = classes.join(' '); + }); + } + + var script = document.createElement('script'); + script.src = 'https://argocd-notifications.readthedocs.io/_/api/v2/footer_html/?'+ + 'callback=' + callbackName + '&project=argocd-notifications&page=&theme=mkdocs&format=jsonp&docroot=docs&source_suffix=.md&version=' + (window['READTHEDOCS_DATA'] || { version: 'latest' }).version; + + document.getElementsByTagName('head')[0].appendChild(script); +})(); -var script = document.createElement('script'); -script.src = 'https://argocd-notifications.readthedocs.io/_/api/v2/footer_html/?'+ - 'callback=callback&project=argocd-notifications&page=&theme=mkdocs&format=jsonp&docroot=docs&source_suffix=.md&version=' + (window['READTHEDOCS_DATA'] || { version: 'latest' }).version; - -document.getElementsByTagName('head')[0].appendChild(script);