Project

General

Profile

1
$(function() {
2
    // wizard
3
    altair_wizard.advanced_wizard();
4
    altair_wizard.vertical_wizard();
5
});
6

    
7
// wizard
8
altair_wizard = {
9
    content_height: function(this_wizard,step) {
10
        var this_height = $(this_wizard).find('.step-'+ step).actual('outerHeight');
11
        $(this_wizard).children('.content').animate({ height: this_height }, 140, bez_easing_swiftOut);
12
    },
13
    advanced_wizard: function() {
14
        var $wizard_advanced = $('#wizard_advanced'),
15
            $wizard_advanced_form = $('#wizard_advanced_form');
16

    
17
        if ($wizard_advanced.length) {
18
            $wizard_advanced.steps({
19
                headerTag: "h3",
20
                bodyTag: "section",
21
                transitionEffect: "slideLeft",
22
                trigger: 'change',
23
                onInit: function(event, currentIndex) {
24
                    altair_wizard.content_height($wizard_advanced,currentIndex);
25
                    // reinitialize textareas autosize
26
                    altair_forms.textarea_autosize();
27
                    // reinitialize checkboxes
28
                    altair_md.checkbox_radio($(".wizard-icheck"));
29
                    $(".wizard-icheck").on('ifChecked', function(event){
30
                        console.log(event.currentTarget.value);
31
                    });
32
                    // reinitialize uikit margin
33
                    altair_uikit.reinitialize_grid_margin();
34
                    // reinitialize selects
35
                    altair_forms.select_elements($wizard_advanced);
36
                    // reinitialize switches
37
                    $wizard_advanced.find('span.switchery').remove();
38
                    altair_forms.switches();
39
                    // reinitialize dynamic grid
40
                    altair_forms.dynamic_fields($wizard_advanced,true,true);
41
                    // resize content when accordion is toggled
42
                    $('.uk-accordion').on('toggle.uk.accordion',function() {
43
                        $window.resize();
44
                    });
45

    
46
                    setTimeout(function() {
47
                        $window.resize();
48
                    },100);
49
                },
50
                onStepChanged: function (event, currentIndex) {
51
                    altair_wizard.content_height($wizard_advanced,currentIndex);
52
                    setTimeout(function() {
53
                        $window.resize();
54
                    },100)
55
                },
56
                onStepChanging: function (event, currentIndex, newIndex) {
57
                    var step = $wizard_advanced.find('.body.current').attr('data-step'),
58
                        $current_step = $('.body[data-step=\"'+ step +'\"]');
59

    
60
                    // check input fields for errors
61
                    $current_step.find('.parsley-row').each(function() {
62
                        $(this).find('input,textarea,select').each(function() {
63
                            $(this).parsley().validate();
64
                        });
65
                    });
66

    
67
                    // adjust content height
68
                    $window.resize();
69

    
70
                    return $current_step.find('.md-input-danger').length ? false : true;
71
                },
72
                onFinished: function() {
73
                    var form_serialized = JSON.stringify( $wizard_advanced_form.serializeObject(), null, 2 );
74
                    UIkit.modal.alert('<p>Wizard data:</p><pre>' + form_serialized + '</pre>');
75
                }
76
            })/*.steps("setStep", 2)*/;
77

    
78
            $window.on('debouncedresize',function() {
79
                var current_step = $wizard_advanced.find('.body.current').attr('data-step');
80
                altair_wizard.content_height($wizard_advanced,current_step);
81
            });
82

    
83
            // wizard
84
            $wizard_advanced_form
85
                .parsley()
86
                .on('form:validated',function() {
87
                    setTimeout(function() {
88
                        altair_md.update_input($wizard_advanced_form.find('.md-input'));
89
                        // adjust content height
90
                        $window.resize();
91
                    },100)
92
                })
93
                .on('field:validated',function(parsleyField) {
94

    
95
                    var $this = $(parsleyField.$element);
96
                    setTimeout(function() {
97
                        altair_md.update_input($this);
98
                        // adjust content height
99
                        var currentIndex = $wizard_advanced.find('.body.current').attr('data-step');
100
                        altair_wizard.content_height($wizard_advanced,currentIndex);
101
                    },100);
102

    
103
                });
104

    
105
        }
106
    },
107
    vertical_wizard: function() {
108
        var $wizard_vertical = $('#wizard_vertical');
109
        if ($wizard_vertical.length) {
110
            $wizard_vertical.steps({
111
                headerTag: "h3",
112
                bodyTag: "section",
113
                enableAllSteps: true,
114
                enableFinishButton: false,
115
                transitionEffect: "slideLeft",
116
                stepsOrientation: "vertical",
117
                onInit: function(event, currentIndex) {
118
                    altair_wizard.content_height($wizard_vertical,currentIndex);
119
                },
120
                onStepChanged: function (event, currentIndex) {
121
                    altair_wizard.content_height($wizard_vertical,currentIndex);
122
                }
123
            });
124
        }
125
    }
126

    
127
};
(29-29/114)