Changed trials-in-common page to use a single database query to get analyses. Changed...
[sgn.git] / docs / libs / gitbook-2.6.7 / js / plugin-fontsettings.js
bloba70f0fb374010eb48376df4ee4312b0cf5f842f0
1 gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
2     var fontState;
4     var THEMES = {
5         "white": 0,
6         "sepia": 1,
7         "night": 2
8     };
10     var FAMILY = {
11         "serif": 0,
12         "sans": 1
13     };
15     // Save current font settings
16     function saveFontSettings() {
17         gitbook.storage.set("fontState", fontState);
18         update();
19     }
21     // Increase font size
22     function enlargeFontSize(e) {
23         e.preventDefault();
24         if (fontState.size >= 4) return;
26         fontState.size++;
27         saveFontSettings();
28     };
30     // Decrease font size
31     function reduceFontSize(e) {
32         e.preventDefault();
33         if (fontState.size <= 0) return;
35         fontState.size--;
36         saveFontSettings();
37     };
39     // Change font family
40     function changeFontFamily(index, e) {
41         e.preventDefault();
43         fontState.family = index;
44         saveFontSettings();
45     };
47     // Change type of color
48     function changeColorTheme(index, e) {
49         e.preventDefault();
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);
60         saveFontSettings();
61     };
63     function update() {
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);
76         }
77     };
79     function init(config) {
80         var $bookBody, $book;
82         //Find DOM elements.
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"]
91         });
93         update();
94     };
97     gitbook.events.bind("start", function(e, config) {
98         var opts = config.fontsettings;
99         if (!opts) return;
100         
101         // Create buttons in toolbar
102         gitbook.toolbar.createButton({
103             icon: 'fa fa-font',
104             label: 'Font Settings',
105             className: 'font-settings',
106             dropdown: [
107                 [
108                     {
109                         text: 'A',
110                         className: 'font-reduce',
111                         onClick: reduceFontSize
112                     },
113                     {
114                         text: 'A',
115                         className: 'font-enlarge',
116                         onClick: enlargeFontSize
117                     }
118                 ],
119                 [
120                     {
121                         text: 'Serif',
122                         onClick: _.partial(changeFontFamily, 0)
123                     },
124                     {
125                         text: 'Sans',
126                         onClick: _.partial(changeFontFamily, 1)
127                     }
128                 ],
129                 [
130                     {
131                         text: 'White',
132                         onClick: _.partial(changeColorTheme, 0)
133                     },
134                     {
135                         text: 'Sepia',
136                         onClick: _.partial(changeColorTheme, 1)
137                     },
138                     {
139                         text: 'Night',
140                         onClick: _.partial(changeColorTheme, 2)
141                     }
142                 ]
143             ]
144         });
147         // Init current settings
148         init(opts);
149     });