From a52f5689a69188b99e91e8ebd6c324cec1a265cb Mon Sep 17 00:00:00 2001 From: mdinger Date: Mon, 14 Sep 2015 02:39:53 -0400 Subject: [PATCH] Add javascript for switching between 3 different themes --- src/theme/book.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/theme/book.js b/src/theme/book.js index c14c5cb2..bb441de9 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -3,6 +3,12 @@ $( document ).ready(function() { // url var url = window.location.pathname; + // Set theme + var theme = localStorage.getItem('theme'); + if (theme == null) { theme = 'light'; } + + set_theme(theme); + // Syntax highlighting Configuration hljs.configure({ tabReplace: ' ', // 4 spaces @@ -44,17 +50,32 @@ $( document ).ready(function() { } else { var popup = $('
') .append($('
Light (default)
')) - .append($('
Dark
')); + .append($('
Coal
')) + .append($('')); $(this).append(popup); $('.theme').click(function(){ 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); + } });