Skip to content

Instantly share code, notes, and snippets.

@kevinn
Last active May 30, 2018 07:10
Show Gist options
  • Save kevinn/b69d1bb267dd5dfa56ab43c1b9ffe640 to your computer and use it in GitHub Desktop.
Save kevinn/b69d1bb267dd5dfa56ab43c1b9ffe640 to your computer and use it in GitHub Desktop.
Check for a text file (markdown) and check contents (if new), update the UI to show unread state, and then display a modal. Uses localStorage set to two items for unread and text content.
// uses https://github.com/markedjs/marked to read markdown files to html
// uses jQuery because we're on old angular version
var checkUpdatesFile = function() {
$.ajax({
url: '/static/updates.md'
}).done(function(data){
var updateText = data;
// check/store in localStorage for updated text from updates.md
if (localStorage.getItem('appUpdates') !== updateText) {
localStorage.setItem('appUpdates', updateText); // update text content
// show unread pip
localStorage.setItem('updatesRead', false);
$('.ac-usernav .icon.notify').addClass('hasunread');
console.log('App has updates.');
} else {
console.log('App no new updates.');
}
});
};
checkUpdatesFile();
$(element).on('click', function (e) {
e.preventDefault();
checkUpdatesFile();
// read from localstorage entry
$('#updateBody').html(marked(localStorage.getItem('appUpdates')));
$('#modal-appupdates').modal('show');
// remove unread pip
localStorage.setItem('updatesRead', true);
$(this).removeClass('hasunread');
console.log('Displaying updates');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment