UNPKG

10.5 kBTypeScriptView Raw
1declare namespace FomanticUI {
2 interface Tab {
3 settings: TabSettings;
4
5 /**
6 * Attaches tab action to given selector.
7 * Default event if none specified is 'toggle'.
8 */
9 (behavior: 'attach events', selector: string, event?: string): JQuery;
10
11 /**
12 * Changes tab to path.
13 */
14 (behavior: 'change tab', path: string): JQuery;
15
16 /**
17 * Sets current path to state.
18 */
19 (behavior: 'set state', path: string): JQuery;
20
21 /**
22 * Returns current path.
23 */
24 (behavior: 'get path'): string;
25
26 /**
27 * Returns whether tab exists.
28 */
29 (behavior: 'is tab'): boolean;
30
31 /**
32 * Returns cached HTML for path.
33 */
34 (behavior: 'cache read', path: string): string;
35
36 /**
37 * Sets cached HTML for path.
38 */
39 (behavior: 'cache add', path: string, html: string): JQuery;
40
41 /**
42 * Removes cached HTML for path.
43 */
44 (behavior: 'cache remove', path: string): JQuery;
45
46 /**
47 * Destroys instance and removes all events.
48 */
49 (behavior: 'destroy'): JQuery;
50
51 <K extends keyof TabSettings>(behavior: 'setting', name: K, value?: undefined, ): Partial<Pick<TabSettings, keyof TabSettings>>;
52 <K extends keyof TabSettings>(behavior: 'setting', name: K, value: TabSettings[K]): JQuery;
53 (behavior: 'setting', value: Partial<Pick<TabSettings, keyof TabSettings>>): JQuery;
54 (settings?: Partial<Pick<TabSettings, keyof TabSettings>>): JQuery;
55 }
56
57 /**
58 * @see {@link https://fomantic-ui.com/modules/tab.html#/settings}
59 */
60 interface TabSettings {
61 // region Tab Settings
62
63 /**
64 * Whether tab should load remote content as same url as history.
65 * @default false
66 */
67 auto: boolean;
68
69 /**
70 * When set to 'siblings' will only deactivate elements that are DOM siblings with the activated element.
71 * When set to 'all' the component will deactivate all other elements initialized at the same time.
72 * @default 'siblings'
73 */
74 deactivate: 'siblings' | 'all';
75
76 /**
77 * Whether to record history events for tab changes.
78 * @default false
79 */
80 history: boolean;
81
82 /**
83 * Do not load content remotely on first tab load.
84 * Useful when open tab is rendered on server.
85 * @default false
86 */
87 ignoreFirstLoad: boolean;
88
89 /**
90 * Whether inline scripts in tab HTML should be parsed on tab load.
91 * Defaults to 'once', parsing only on first load.
92 * Can also be set to 'true' or 'false' to always parse or never parse inline scripts.
93 * @default 'once'
94 */
95 evaluateScripts: 'once' | boolean;
96
97 /**
98 * When 'true' and no active tab exists, the first available tab will be activated.
99 * When a string is given and no active tab exists, the tab those named path matches the string will be activated.
100 * When 'false' no active tab detection will happen.
101 * @default true
102 */
103 autoTabActivation: boolean | string;
104
105 /**
106 * Tab should reload content every time it is opened.
107 * @default false
108 */
109 alwaysRefresh: boolean;
110
111 /**
112 * Can be set to either 'response', 'DOM' or 'html'.
113 * Using 'DOM' will cache the a clone of the DOM tree, preserving all events as they existed on render.
114 * 'response' will cache the original response on load, this way callbacks always receive the same content.
115 * Using 'html' will cache the resulting html after all callbacks, making sure any changes to content are preserved.
116 * @default 'response'
117 */
118 cacheType: 'response' | 'DOM' | 'html';
119
120 /**
121 * Tab should cache content after loading locally to avoid server trip on second load.
122 * @default true
123 */
124 cache: boolean;
125
126 /**
127 * Settings object for '$.api' call.
128 * @see {@link https://fomantic-ui.com/behaviors/api.html#/settings}
129 * @default false
130 */
131 apiSettings: false | FomanticUI.APISettings | JQueryAjaxSettings;
132
133 /**
134 * Can be set to 'hash' or 'state'.
135 * 'hash' will use an in-page link to create history events.
136 * 'state' will use DOM History and load pages from server on refresh.
137 * @see {@link https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history}
138 * @default 'hash'
139 */
140 historyType: 'hash' | 'state';
141
142 /**
143 * When using historyType 'state' you must specify the base URL for all internal links.
144 * @default false
145 */
146 path: boolean;
147
148 /**
149 * Tabs are limited to those found inside this context.
150 * @default false
151 */
152 context: false | string;
153
154 /**
155 * If enabled limits tabs to children of passed context.
156 * @default false
157 */
158 childrenOnly: boolean;
159
160 /**
161 * Maximum amount of nested tabs allowed (avoids recursion).
162 * @default 25
163 */
164 maxDepth: boolean;
165
166 // endregion
167
168 // region Callbacks
169
170 /**
171 * Callback only the first time a tab is loaded.
172 */
173 onFirstLoad(this: JQuery, tabPath: string, parameterArray: string, historyEvent: string): void;
174
175 /**
176 * Callback every time a tab is loaded.
177 */
178 onLoad(this: JQuery, tabPath: string, parameterArray: string, historyEvent: string): void;
179
180 /**
181 * Called when a tab begins loading remote content.
182 */
183 onRequest(this: JQuery, tabPath: string): void;
184
185 /**
186 * Called after a tab becomes visible.
187 */
188 onVisible(this: JQuery, tabPath: string): void;
189
190 /**
191 * Called before a tab is about to be changed.
192 * Returning 'false' will cancel the tab change.
193 */
194 onBeforeChange(this: JQuery, tabPath: string): boolean;
195
196 // endregion
197
198 // region DOM Settings
199
200 /**
201 * Functions used to return content.
202 */
203 templates: Tab.TemplateSettings;
204
205 /**
206 * DOM Selectors used internally.
207 * Selectors used to find parts of a module.
208 */
209 selector: Tab.SelectorSettings;
210
211 /**
212 * DOM metadata used by module.
213 */
214 metadata: Tab.MetadataSettings;
215
216 /**
217 * Class names used to determine element state.
218 */
219 className: Tab.ClassNameSettings;
220
221 // endregion
222
223 // region Debug Settings
224
225 /**
226 * Name used in log statements
227 * @default 'Tab'
228 */
229 name: string;
230
231 /**
232 * Event namespace. Makes sure module teardown does not effect other events attached to an element.
233 * @default 'tab'
234 */
235 namespace: string;
236
237 /**
238 * Silences all console output including error messages, regardless of other debug settings.
239 * @default false
240 */
241 silent: boolean;
242
243 /**
244 * Debug output to console
245 * @default false
246 */
247 debug: boolean;
248
249 /**
250 * Show console.table output with performance metrics
251 * @default true
252 */
253 performance: boolean;
254
255 /**
256 * Debug output includes all internal behaviors
257 * @default false
258 */
259 verbose: boolean;
260
261 error: Tab.ErrorSettings;
262
263 // endregion
264 }
265
266 namespace Tab {
267 type TemplateSettings = Partial<Pick<Settings.Templates, keyof Settings.Templates>>;
268 type SelectorSettings = Partial<Pick<Settings.Selectors, keyof Settings.Selectors>>;
269 type MetadataSettings = Partial<Pick<Settings.Metadatas, keyof Settings.Metadatas>>;
270 type ClassNameSettings = Partial<Pick<Settings.ClassNames, keyof Settings.ClassNames>>;
271 type ErrorSettings = Partial<Pick<Settings.Errors, keyof Settings.Errors>>;
272
273 namespace Settings {
274 interface Templates {
275 /**
276 * Returns page title
277 * @default Function
278 */
279 determineTitle: Function;
280 }
281
282 interface Selectors {
283 /**
284 * @default '.ui.tab'
285 */
286 tabs: string;
287
288 /**
289 * @default '.ui:not(.menu)'
290 */
291 parent: string;
292 }
293
294 interface Metadatas {
295 /**
296 * @default 'tab'
297 */
298 tab: string;
299
300 /**
301 * @default 'loaded'
302 */
303 loaded: string;
304
305 /**
306 * @default 'promise'
307 */
308 promise: string;
309 }
310
311 interface ClassNames {
312 /**
313 * @default 'loading'
314 */
315 loading: string;
316
317 /**
318 * @default 'active'
319 */
320 active: string;
321 }
322
323 interface Errors {
324 /**
325 * @default 'You attempted to load content without API module'
326 */
327 api: string;
328
329 /**
330 * @default 'The method you called is not defined'
331 */
332 method: string;
333
334 /**
335 * @default 'Activated tab cannot be found for this context.'
336 */
337 missingTab: string;
338
339 /**
340 * @default 'The tab you specified is missing a content url.'
341 */
342 noContent: string;
343
344 /**
345 * @default 'History enabled, but no path was specified'
346 */
347 path: string;
348
349 /**
350 * @default 'Max recursive depth reached'
351 */
352 recursion: string;
353
354 /**
355 * @default 'The state library has not been initialized'
356 */
357 state: string;
358 }
359 }
360 }
361}