-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtocbot.admin.inc
270 lines (260 loc) · 10.3 KB
/
tocbot.admin.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
/**
* @file
* Tocbot configuration form
*
*/
/**
* Configuration form to update module settings.
*/
function tocbot_config_form($form, $form_state) {
$config = config('tocbot.settings');
$form['moduleSettings'] = array(
'#type' => 'fieldset',
'#title' => t('Module Settings'),
'#description' => t('Module settings to customize Tocbot.'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['moduleSettings']['tocbot_extrabodyclass'] = array(
'#type' => 'textfield',
'#title' => t('Body class'),
'#description' => t('Additional body class for pages with a Tocbot block.<br />
Default: <code>toc-is-active</code>'),
'#default_value' => $config->get('tocbot_extrabodyclass'),
);
$form['moduleSettings']['tocbot_tocTitle'] = array(
'#type' => 'textfield',
'#title' => t('TOC title'),
'#description' => t('A title for the table of contents. Leave blank for none.<br />
Default: <code>Contents</code>'),
'#default_value' => $config->get('tocbot_tocTitle'),
);
$form['moduleSettings']['tocbot_minActivate'] = array(
'#type' => 'textfield',
'#title' => t('Minimum number of headings'),
'#description' => t('Displays the Tocbot block only on pages where the
number of headings is greater than or equal to this value.<br />
Default: <code>3</code>'),
'#default_value' => $config->get('tocbot_minActivate'),
);
$form['moduleSettings']['tocbot_createAutoIds'] = array(
'#type' => 'checkbox',
'#title' => t('Create automatic IDs'),
'#description' => t('Use JavaScript to create automatic IDs for headings.
Disable if you want to create your IDs otherwise, e.g. manually or using
a text filter module.<br />
Default: Enabled'),
'#default_value' => $config->get('tocbot_createAutoIds'),
);
// Tocbot Settings tab.
$form['tocbot_jsSettings'] = array(
'#type' => 'fieldset',
'#title' => t('JavaScript Settings'),
'#description' => t('Tocbot API settings passed to JavaScript.
See the <a href="https://tscanlin.github.io/tocbot/#api">API of the Tocbot library</a> for details.'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['tocbot_jsSettings']['tocbot_tocSelector'] = array(
'#type' => 'textfield',
'#title' => t('tocSelector'),
'#description' => t('Class of the table of contents wrapper. When you use
the Tocbot block, set to <code>.js-toc-block</code>. Alternatively, set an
unique class and place an empty div with that class in your theme template.<br />
Default: <code>.js-toc-block</code>'),
'#default_value' => $config->get('tocbot_tocSelector'),
);
$form['tocbot_jsSettings']['tocbot_contentSelector'] = array(
'#type' => 'textfield',
'#title' => t('contentSelector'),
'#description' => t('Where to grab the headings to build the table of
contents.<br />
Default: <code>.l-content</code>'),
'#default_value' => $config->get('tocbot_contentSelector'),
);
$form['tocbot_jsSettings']['tocbot_headingSelector'] = array(
'#type' => 'textfield',
'#title' => t('headingSelector'),
'#description' => t('Separate elements by comma and space.<br />
Default: <code>h2, h3, h4, h5, h6</code>'),
'#default_value' => $config->get('tocbot_headingSelector'),
);
$form['tocbot_jsSettings']['tocbot_ignoreSelector'] = array(
'#type' => 'textfield',
'#title' => t('ignoreSelector'),
'#description' => t('Headings that match the ignoreSelector will be skipped.<br />
Default: <code>.js-toc-ignore</code>'),
'#default_value' => $config->get('tocbot_ignoreSelector'),
);
$form['tocbot_jsSettings']['tocbot_linkClass'] = array(
'#type' => 'textfield',
'#title' => t('linkClass'),
'#description' => t('Main class to add to links.<br />
Default: <code>toc-link</code>'),
'#default_value' => $config->get('tocbot_linkClass'),
);
$form['tocbot_jsSettings']['tocbot_extraLinkClasses'] = array(
'#type' => 'textfield',
'#title' => t('extraLinkClasses'),
'#description' => t('Extra classes to add to links.<br />
Default: Empty'),
'#default_value' => $config->get('tocbot_extraLinkClasses'),
);
$form['tocbot_jsSettings']['tocbot_activeLinkClass'] = array(
'#type' => 'textfield',
'#title' => t('activeLinkClass'),
'#description' => t('Class to add to active links, the link corresponding
to the top most heading on the page.<br />
Default: <code>is-active-link</code>'),
'#default_value' => $config->get('tocbot_activeLinkClass'),
);
$form['tocbot_jsSettings']['tocbot_listClass'] = array(
'#type' => 'textfield',
'#title' => t('listClass'),
'#description' => t('Main class to add to lists.<br />
Default: <code>toc-list</code>'),
'#default_value' => $config->get('tocbot_listClass'),
);
$form['tocbot_jsSettings']['tocbot_extraListClasses'] = array(
'#type' => 'textfield',
'#title' => t('extraListClasses'),
'#description' => t('Extra classes to add to lists.<br />
Default: Empty'),
'#default_value' => $config->get('tocbot_extraListClasses'),
);
$form['tocbot_jsSettings']['tocbot_isCollapsedClass'] = array(
'#type' => 'textfield',
'#title' => t('isCollapsedClass'),
'#description' => t('Class that gets added when a list should be collapsed.<br />
Default: <code>is-collapsed</code>'),
'#default_value' => $config->get('tocbot_isCollapsedClass'),
);
$form['tocbot_jsSettings']['tocbot_collapsibleClass'] = array(
'#type' => 'textfield',
'#title' => t('collapsibleClass'),
'#description' => t('Class that gets added when a list is collapsible.<br />
Default: <code>is-collapsible</code>'),
'#default_value' => $config->get('tocbot_collapsibleClass'),
);
$form['tocbot_jsSettings']['tocbot_listItemClass'] = array(
'#type' => 'textfield',
'#title' => t('listItemClass'),
'#description' => t('Class to add to list items.<br />
Default: <code>toc-list-item</code>'),
'#default_value' => $config->get('tocbot_listItemClass'),
);
$form['tocbot_jsSettings']['tocbot_collapseDepth'] = array(
'#type' => 'textfield',
'#title' => t('collapseDepth (number)'),
'#description' => t('How many heading levels should not be collapsed. Number 6
will show everything since there are not more than 6 heading levels. Number 0
will collapse all sections, and they will open and close as you scroll to them.<br />
Default: <code>0</code>'),
'#default_value' => $config->get('tocbot_collapseDepth'),
);
$form['tocbot_jsSettings']['tocbot_orderedList'] = array(
'#type' => 'checkbox',
'#title' => t('orderedList'),
'#description' => t('Generate ordered (ol) instead of unordered lists (ul).<br />
Default: Disabled'),
'#default_value' => $config->get('tocbot_orderedList'),
);
$form['tocbot_jsSettings']['tocbot_scrollSmooth'] = array(
'#type' => 'checkbox',
'#title' => t('scrollSmooth'),
'#description' => t('Smooth scrolling.<br />
Default: Enabled'),
'#default_value' => $config->get('tocbot_scrollSmooth'),
);
$form['tocbot_jsSettings']['tocbot_scrollSmoothDuration'] = array(
'#type' => 'textfield',
'#title' => t('scrollSmoothDuration'),
'#description' => t('Smooth scroll duration.<br />
Default: <code>420</code>'),
'#default_value' => $config->get('tocbot_scrollSmoothDuration'),
);
$form['tocbot_jsSettings']['tocbot_throttleTimeout'] = array(
'#type' => 'textfield',
'#title' => t('throttleTimeout'),
'#description' => t('Timeout between events firing to make sure its not too
rapid (for performance reasons).<br />
Default: <code>50</code>'),
'#default_value' => $config->get('tocbot_throttleTimeout'),
);
$form['tocbot_jsSettings']['tocbot_positionFixedSelector'] = array(
'#type' => 'textfield',
'#title' => t('positionFixedSelector'),
'#description' => t('Specify a selector to make the table of contents fixed
after scrolling down.<br />
Default: <code>.js-toc-block</code> (same as "tocSelector" at top of the JavaScript settings)'),
'#default_value' => $config->get('tocbot_positionFixedSelector'),
);
$form['tocbot_jsSettings']['tocbot_positionFixedClass'] = array(
'#type' => 'textfield',
'#title' => t('positionFixedClass'),
'#description' => t('Fixed position class to add to make sidebar fixed after
scrolling down past the fixedSidebarOffset.<br />
Default: <code>is-position-fixed</code>'),
'#default_value' => $config->get('tocbot_positionFixedClass'),
);
$form['tocbot_jsSettings']['tocbot_fixedSidebarOffset'] = array(
'#type' => 'textfield',
'#title' => t('fixedSidebarOffset'),
'#description' => t('Can be any number. The default tries to set the offset
to the sidebar elements offsetTop from the top of the document on init.<br />
Default: <code>auto</code>'),
'#default_value' => $config->get('tocbot_fixedSidebarOffset'),
);
$form['tocbot_jsSettings']['tocbot_includeHtml'] = array(
'#type' => 'checkbox',
'#title' => t('includeHtml'),
'#description' => t('Include the HTML markup from the heading node
instead of just including the textContent.<br />
Default: Disabled'),
'#default_value' => $config->get('tocbot_includeHtml'),
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* Save Configuration form.
*/
function tocbot_config_form_submit($form, $form_state) {
$config = config('tocbot.settings');
$fields_to_save = array(
'tocbot_extrabodyclass',
'tocbot_tocTitle',
'tocbot_minActivate',
'tocbot_createAutoIds',
'tocbot_tocSelector',
'tocbot_contentSelector',
'tocbot_headingSelector',
'tocbot_ignoreSelector',
'tocbot_linkClass',
'tocbot_extraLinkClasses',
'tocbot_activeLinkClass',
'tocbot_listClass',
'tocbot_extraListClasses',
'tocbot_isCollapsedClass',
'tocbot_collapsibleClass',
'tocbot_listItemClass',
'tocbot_collapseDepth',
'tocbot_orderedList',
'tocbot_scrollSmooth',
'tocbot_scrollSmoothDuration',
'tocbot_throttleTimeout',
'tocbot_positionFixedSelector',
'tocbot_positionFixedClass',
'tocbot_fixedSidebarOffset',
);
foreach ($fields_to_save as $value) {
$form_value = $form_state['values'][$value];
$config->set($value, $form_value);
}
$config->save();
backdrop_set_message(t('The configuration options have been saved.'));
}