1 gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
15 // Save current font settings
16 function saveFontSettings() {
17 gitbook.storage.set("fontState", fontState);
22 function enlargeFontSize(e) {
24 if (fontState.size >= 4) return;
31 function reduceFontSize(e) {
33 if (fontState.size <= 0) return;
40 function changeFontFamily(index, e) {
43 fontState.family = index;
47 // Change type of color
48 function changeColorTheme(index, e) {
51 var $book = $(".book");
53 if (fontState.theme !== 0)
54 $book.removeClass("color-theme-"+fontState.theme);
56 fontState.theme = index;
57 if (fontState.theme !== 0)
58 $book.addClass("color-theme-"+fontState.theme);
64 var $book = gitbook.state.$book;
66 $(".font-settings .font-family-list li").removeClass("active");
67 $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active");
69 $book[0].className = $book[0].className.replace(/\bfont-\S+/g, '');
70 $book.addClass("font-size-"+fontState.size);
71 $book.addClass("font-family-"+fontState.family);
73 if(fontState.theme !== 0) {
74 $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, '');
75 $book.addClass("color-theme-"+fontState.theme);
79 function init(config) {
83 $book = gitbook.state.$book;
84 $bookBody = $book.find(".book-body");
86 // Instantiate font state object
87 fontState = gitbook.storage.get("fontState", {
88 size: config.size || 2,
89 family: FAMILY[config.family || "sans"],
90 theme: THEMES[config.theme || "white"]
97 gitbook.events.bind("start", function(e, config) {
98 var opts = config.fontsettings;
101 // Create buttons in toolbar
102 gitbook.toolbar.createButton({
104 label: 'Font Settings',
105 className: 'font-settings',
110 className: 'font-reduce',
111 onClick: reduceFontSize
115 className: 'font-enlarge',
116 onClick: enlargeFontSize
122 onClick: _.partial(changeFontFamily, 0)
126 onClick: _.partial(changeFontFamily, 1)
132 onClick: _.partial(changeColorTheme, 0)
136 onClick: _.partial(changeColorTheme, 1)
140 onClick: _.partial(changeColorTheme, 2)
147 // Init current settings