Use a div instead of alert for version warning
With this change, it is also no longer necessary to display the version in the navigation bar. The accidently removed doctype is also brought back.
This commit is contained in:
@@ -53,30 +53,39 @@ $(function () {
|
||||
$(window).on('resize', _onResize);
|
||||
_onResize();
|
||||
|
||||
var currentVersion = document.getElementById('package-version').innerHTML;
|
||||
|
||||
// warn about outdated version
|
||||
var srcLinks = $('div.tag-source');
|
||||
var location = window.location.href;
|
||||
var branchSearch = location.match(/\/([^\/]*)\/apidoc\//);
|
||||
if (branchSearch && branchSearch.length) {
|
||||
var branch = branchSearch[1];
|
||||
if (branch !== 'latest') {
|
||||
if (/^v[0-9\.]*$/.test(branch)) {
|
||||
var ok = confirm('You are viewing outdated docs. Do you want to try the latest?');
|
||||
if (ok) {
|
||||
window.location.href = location.replace(branchSearch[0], '/latest/apidoc/');
|
||||
}
|
||||
} else {
|
||||
$('.package-version').text(branch);
|
||||
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(/\/([^\/]*)\/apidoc\//);
|
||||
var cookieText = 'dismissed=-' + latestVersion + '-';
|
||||
var dismissed = document.cookie.indexOf(cookieText) != -1;
|
||||
if (!dismissed && /^v[0-9\.]*$/.test(branchSearch[1]) && currentVersion != latestVersion) {
|
||||
var link = url.replace(branchSearch[0], '/latest/apidoc/');
|
||||
fetch(link, {method: 'head'}).then(function(response) {
|
||||
var a = document.getElementById('latest-link');
|
||||
a.href = response.status == 200 ? link : '../../latest/apidoc/';
|
||||
});
|
||||
var latestCheck = document.getElementById('latest-check');
|
||||
latestCheck.style.display = '';
|
||||
document.getElementById('latest-dismiss').onclick = function() {
|
||||
latestCheck.style.display = 'none';
|
||||
document.cookie = cookieText;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// create source code links to github
|
||||
var version = $('.package-version');
|
||||
var branch = version.text();
|
||||
var srcLinks = $('div.tag-source');
|
||||
srcLinks.each(function(i, el) {
|
||||
var textParts = el.innerHTML.trim().split(', ');
|
||||
var link = 'https://github.com/openlayers/ol3/blob/' + branch + '/' +
|
||||
var link = 'https://github.com/openlayers/ol3/blob/' + currentVersion + '/' +
|
||||
textParts[0];
|
||||
el.innerHTML = '<a href="' + link + '">' + textParts[0] + '</a>, ' +
|
||||
'<a href="' + link + textParts[1].replace('line ', '#l') + '">' +
|
||||
|
||||
@@ -132,7 +132,6 @@ li {
|
||||
display: block;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
.navigation h4,
|
||||
.navigation li.item .title a {
|
||||
color: #e1e1e1;
|
||||
}
|
||||
@@ -417,3 +416,7 @@ footer {
|
||||
left: 250px;
|
||||
font-weight: normal;
|
||||
}
|
||||
#latest-check {
|
||||
margin-top: -10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user