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

View file

@ -1,4 +1,6 @@
BR.WhatsNew = { BR.WhatsNew = {
newOnly: undefined,
init: function () { init: function () {
var self = this; var self = this;
self.dismissableMessage = new BR.Message('whats_new_message', { self.dismissableMessage = new BR.Message('whats_new_message', {
@ -7,13 +9,15 @@ BR.WhatsNew = {
if (BR.Util.localStorageAvailable()) { if (BR.Util.localStorageAvailable()) {
localStorage.setItem('changelogVersion', self.getLatestVersion()); 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 () { $('#whatsnew').on('shown.bs.modal', function () {
self.dismissableMessage.hide(); 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()) { if (!self.getCurrentVersion() && BR.Util.localStorageAvailable()) {
localStorage.setItem('changelogVersion', self.getLatestVersion()); localStorage.setItem('changelogVersion', self.getLatestVersion());
} }
@ -36,15 +40,21 @@ BR.WhatsNew = {
}, },
hasNewVersions: function () { hasNewVersions: function () {
return this.getCurrentVersion() && this.getCurrentVersion() < this.getLatestVersion(); return this.getCurrentVersion() && this.getCurrentVersion() !== this.getLatestVersion();
}, },
prepare: function (newOnly) { 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 container = document.querySelector('#whatsnew .modal-body');
var cl = BR.changelog; var cl = BR.changelog;
if (newOnly && this.getCurrentVersion()) { if (newOnly && this.getCurrentVersion()) {
var head = '<h2 id="' + 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; container.innerHTML = cl;
}, },