diff options
Diffstat (limited to 'theme/javascript/core/font-settings.js')
-rw-r--r-- | theme/javascript/core/font-settings.js | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/theme/javascript/core/font-settings.js b/theme/javascript/core/font-settings.js index 08e7c90..0bcdd2c 100644 --- a/theme/javascript/core/font-settings.js +++ b/theme/javascript/core/font-settings.js @@ -30,40 +30,23 @@ define([ }; var enlargeFontSize = function(e){ - var $bookBody = $(".book-body"); - if (fontState.size < 4){ - $bookBody.toggleClass("font-size-"+fontState.size, false); fontState.size++; - - $bookBody.toggleClass("font-size-"+fontState.size, true); fontState.save(); } }; var reduceFontSize = function(e){ - var $bookBody = $(".book-body"); - if (fontState.size > 0){ - $bookBody.toggleClass("font-size-"+fontState.size); fontState.size--; - - $bookBody.toggleClass("font-size-"+fontState.size); fontState.save(); } }; var changeFontFamily = function(){ - var $bookBody = $(".book-body"); var index = $(this).data("font"); - $bookBody.toggleClass("font-family-"+fontState.family); - $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")") - .removeClass("active"); - fontState.family = index; - $bookBody.toggleClass("font-family-"+fontState.family); - $(this).addClass("active"); fontState.save(); }; @@ -81,6 +64,22 @@ define([ fontState.save(); }; + var update = function() { + var $book = $(".book"); + + $(".font-settings .font-family-list li").removeClass("active"); + $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active"); + + $book[0].className = $book[0].className.replace(/\bfont-\S+/g, ''); + $book.addClass("font-size-"+fontState.size); + $book.addClass("font-family-"+fontState.family); + + if(fontState.theme !== 0) { + $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, ''); + $book.addClass("color-theme-"+fontState.theme); + } + }; + var init = function(config) { var $toggle, $bookBody, $dropdown, $book; @@ -98,15 +97,10 @@ define([ }); fontState.save = function(){ storage.set("fontState",fontState); + update(); }; - $bookBody.addClass("font-size-"+fontState.size); - $bookBody.addClass("font-family-"+fontState.family); - - $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active"); - - if(fontState.theme !== 0) - $book.addClass("color-theme-"+fontState.theme); + update(); //Add event listeners $(document).on('click', "#enlarge-font-size", enlargeFontSize); @@ -121,6 +115,7 @@ define([ }; return { - init: init + init: init, + update: update } });
\ No newline at end of file |