From 4f76334c92837a9e19193179503dd6bce08095fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sat, 25 Jul 2020 14:19:16 +0200 Subject: [PATCH] Script tag not allowed out side body / head --- examples/templates/example.html | 68 ++++++++++++++++----------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/examples/templates/example.html b/examples/templates/example.html index 341c253330..6d10e37676 100644 --- a/examples/templates/example.html +++ b/examples/templates/example.html @@ -240,41 +240,39 @@ modal.find('.modal-title').text(title); modal.find('.modal-body').html(content); }); + + var packageUrl = 'https://raw.githubusercontent.com/openlayers/openlayers.github.io/build/package.json'; + fetch(packageUrl).then(function(response) { + return response.json(); + }).then(function(json) { + var latestVersion = json.version; + document.getElementById('latest-version').innerHTML = latestVersion; + var url = window.location.href; + var branchSearch = url.match(/\/([^\/]*)\/examples\//); + var cookieText = 'dismissed=-' + latestVersion + '-'; + var dismissed = document.cookie.indexOf(cookieText) != -1; + if (branchSearch && !dismissed && /^v[0-9\.]*$/.test(branchSearch[1]) && '{{ olVersion }}' != latestVersion) { + var link = url.replace(branchSearch[0], '/latest/examples/'); + fetch(link, {method: 'head'}).then(function(response) { + var a = document.getElementById('latest-link'); + a.href = response.status == 200 ? link : '../../latest/examples/'; + }); + var latestCheck = document.getElementById('latest-check'); + latestCheck.style.display = ''; + document.getElementById('latest-dismiss').onclick = function() { + latestCheck.style.display = 'none'; + document.cookie = cookieText; + } + } + + var experimentalNotice = document.getElementById('experimental-notice'); + if (window.experimental) { + experimentalNotice.style.display = 'block'; + document.getElementById('experimental-dismiss').onclick = function() { + experimentalNotice.style.display = 'none'; + } + } + }); -