Add javascript for switching between 3 different themes

This commit is contained in:
mdinger 2015-09-14 02:39:53 -04:00
parent b7d9cc3d0a
commit a52f5689a6
1 changed files with 23 additions and 2 deletions

View File

@ -3,6 +3,12 @@ $( document ).ready(function() {
// url // url
var url = window.location.pathname; var url = window.location.pathname;
// Set theme
var theme = localStorage.getItem('theme');
if (theme == null) { theme = 'light'; }
set_theme(theme);
// Syntax highlighting Configuration // Syntax highlighting Configuration
hljs.configure({ hljs.configure({
tabReplace: ' ', // 4 spaces tabReplace: ' ', // 4 spaces
@ -44,17 +50,32 @@ $( document ).ready(function() {
} else { } else {
var popup = $('<div class="theme-popup"></div>') var popup = $('<div class="theme-popup"></div>')
.append($('<div class="theme" id="light">Light (default)<div>')) .append($('<div class="theme" id="light">Light (default)<div>'))
.append($('<div class="theme" id="dark">Dark</div>')); .append($('<div class="theme" id="coal">Coal</div>'))
.append($('<div class="theme" id="navy">Navy</div>'));
$(this).append(popup); $(this).append(popup);
$('.theme').click(function(){ $('.theme').click(function(){
var theme = $(this).attr('id'); var theme = $(this).attr('id');
$('body').removeClass().addClass(theme);
set_theme(theme)
}); });
} }
}); });
function set_theme(theme) {
if (theme == 'coal' || theme == 'navy') {
$("[href='tomorrow-night.css']").prop('disabled', false);
$("[href='highlight.css']").prop('disabled', true);
} else {
$("[href='tomorrow-night.css']").prop('disabled', true);
$("[href='highlight.css']").prop('disabled', false);
}
localStorage.setItem('theme', theme);
$('body').removeClass().addClass(theme);
}
}); });