Merge pull request #392 from bagage/fix/whatsnew-blink

Fix/whatsnew blink
This commit is contained in:
Norbert Renner 2021-03-26 20:00:12 +01:00 committed by GitHub
commit cd8ac29aab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View file

@ -80,6 +80,7 @@ var paths = {
.concat('css/*.css'),
images: mainNpmFiles().filter((f) => RegExp('.*.+(png|gif|svg)', 'i').test(f)),
fonts: mainNpmFiles().filter((f) => RegExp('font-awesome/fonts/.*', 'i').test(f)),
changelog: 'CHANGELOG.md',
locales: 'locales/*.json',
layers: 'layers/**/*.geojson',
layersDestName: 'layers.js',
@ -188,7 +189,7 @@ gulp.task('boundaries', function () {
});
gulp.task('changelog', function (cb) {
var content = 'BR.changelog = `' + marked(fs.readFileSync('./CHANGELOG.md', 'utf-8')) + '`';
var content = 'BR.changelog = `' + marked(fs.readFileSync(paths.changelog, 'utf-8')) + '`';
content = content.replace(/<h1.*<\/h1>/i, '');
fs.writeFile(paths.dest + '/changelog.js', content, cb);
});
@ -207,6 +208,7 @@ gulp.task('watch', function () {
remember.forget('scripts', event.path);
}
});
gulp.watch(paths.changelog, gulp.series('changelog', 'reload'));
gulp.watch(paths.locales, gulp.series('locales', 'reload'));
gulp.watch(paths.styles, gulp.series('styles', 'reload'));
gulp.watch(paths.layersConfig, gulp.series('layers_config', 'reload'));

View file

@ -1,4 +1,6 @@
BR.WhatsNew = {
newOnly: undefined,
init: function () {
var self = this;
self.dismissableMessage = new BR.Message('whats_new_message', {
@ -7,13 +9,15 @@ BR.WhatsNew = {
if (BR.Util.localStorageAvailable()) {
localStorage.setItem('changelogVersion', self.getLatestVersion());
}
// next time popup is open, by default we will see everything
self.prepare(false);
},
});
$('#whatsnew').on('shown.bs.modal', function () {
self.dismissableMessage.hide();
});
$('#whatsnew').on('hidden.bs.modal', function () {
// next time popup is open, by default we will see everything
self.prepare(false);
});
if (!self.getCurrentVersion() && BR.Util.localStorageAvailable()) {
localStorage.setItem('changelogVersion', self.getLatestVersion());
}
@ -36,15 +40,21 @@ BR.WhatsNew = {
},
hasNewVersions: function () {
return this.getCurrentVersion() && this.getCurrentVersion() < this.getLatestVersion();
return this.getCurrentVersion() && this.getCurrentVersion() !== this.getLatestVersion();
},
prepare: function (newOnly) {
if (newOnly === this.newOnly) {
// do not rebuild modal content unnecessarily
return;
}
this.newOnly = newOnly;
var container = document.querySelector('#whatsnew .modal-body');
var cl = BR.changelog;
if (newOnly && this.getCurrentVersion()) {
var head = '<h2 id="' + this.getCurrentVersion() + '">';
cl = cl.substring(0, cl.indexOf(head));
var idx = cl.indexOf(head);
if (idx >= 0) cl = cl.substring(0, idx);
}
container.innerHTML = cl;
},