-
-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathplugin.ts
More file actions
38 lines (32 loc) · 1.22 KB
/
plugin.ts
File metadata and controls
38 lines (32 loc) · 1.22 KB
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
import { WizardOptions } from './types';
import { Wizard } from './wizard';
import { transitions } from './transitions';
// Define the plugin
function smartWizard(this: JQuery, options?: Partial<WizardOptions>): JQuery | undefined {
if (options === undefined || typeof options === 'object') {
return this.each(function () {
if (!$.data(this, "smartWizard")) {
$.data(this, "smartWizard", new Wizard($(this), options));
}
});
} else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
const instance = $.data(this[0], 'smartWizard');
if (options === 'destroy') {
$.data(this, 'smartWizard', null);
instance?.destroy();
return this;
}
if (instance instanceof Wizard && typeof instance[options] === 'function') {
return (instance[options] as Function).apply(instance, Array.prototype.slice.call(arguments, 1));
} else {
return this;
}
}
}
// Extend jQuery
$.fn.extend({
smartWizard
});
// Define plugin defaults and transitions
($.fn.smartWizard as any).transitions = transitions;
export default Wizard;