Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / wizard-carousel.js @ 4c5e78b5

History | View | Annotate | Download (4.1 kB)

1
/*        
2
        // for the carousel index
3
        indicate_step: function(step) {
4
                $('.wizard .top .sub-menu[data-step]').hide();
5
                $('.wizard .top .sub-menu[data-step='+step+']').fadeIn();
6
        },
7

8
}
9
*/
10

    
11
/*
12
kpap:
13
Πώς κάνω extend κάτι;
14
Πχ θέλω στο carousel να ενσωματώσω το πάνω μενου...
15
*/
16

    
17

    
18
/*
19
Wrapper element must have set width and overflow hidden properties;
20
Item elements should have no margin
21
*/
22
function Carousel(options) {
23
        var defaults = {
24
                'wrapper': $('.carousel-wrapper'),
25
                'container': $('.carousel-container'),
26
                'item': $('.carousel-item'),
27
                'next': $('.carousel-next'),
28
                'prev': $('.carousel-prev'),
29
                'speed': 1000,
30
                'current_step': 1,
31
                // αυτά δεν τα θέλω εδώ
32
                'cancel_text': 'CANCEL',
33
                'previous_text': 'PREVIOUS',
34
                'submit_text': 'SUBMIT',
35
                'next_text': 'NEXT',
36
        }
37

    
38
        this.options = _.defaults(options,defaults);
39
        // TODO with _.map
40
        this.wrapper = options.wrapper;
41
        this.container = options.container;
42
        this.item = options.item;
43
        this.next = options.next;
44
        this.prev = options.prev;
45
        this.speed = options.speed;
46
        this.cancel_text = options.cancel_text;
47
        this.previous_text = options.previous_text;
48
        this.submit_text = options.submit_text;
49
        this.next_text = options.next_text;
50
        this.current_step = options.current_step;
51
        this.total_items = this.item.length;
52
        this.initEvents();
53
}
54

    
55
Carousel.prototype.alterNav = function () {
56
        var self = this;
57
        this.prev.find('span').html(this.previous_text);
58
        this.next.find('span').html(this.next_text);
59
        if ( this.current_step == 1) {
60
                self.prev.find('span').html(self.cancel_text);
61
        }
62
        else if (this.current_step == this.total_items ) {
63
                self.next.find('span').html(self.submit_text);
64
        }
65
        $('.nums').children('li').removeClass('current');
66
        $('.nums li:nth-child('+self.current_step+')').addClass('current');
67
}
68

    
69
Carousel.prototype.alterSubMenu = function () {
70
        $('.wizard .top .sub-menu[data-step]').hide();
71
        $('.wizard .top .sub-menu[data-step='+this.current_step+']').fadeIn();
72
}
73

    
74
Carousel.prototype.resetForm = function () {
75
        console.log('dummy form reset');
76
}
77

    
78
Carousel.prototype.submitForm = function () {
79
        console.log('dummy form submit');
80
}
81

    
82
Carousel.prototype.closeOverlay = function () {
83
        $('.overlay-area, .overlay-div').hide();
84
}
85

    
86
Carousel.prototype.setDimensions = function (){
87
        this.wrapper.css('width', 100*this.total_items+'%');
88
        this.container.find(this.item).css('width', 100/this.total_items+'%');
89
}
90

    
91
Carousel.prototype.move = function () {
92
        var percentage = -(this.current_step-1)/this.total_items*100+'%';
93
        this.container.stop().animate({ 'left': percentage }, this.speed);
94
        this.alterNav();
95
        this.alterSubMenu();
96
}
97

    
98
// if is_clicked is true, -duh- something has been clicked
99
Carousel.prototype.moveNext = function (is_clicked) {
100
        var self = this;
101
        if (this.current_step < this.total_items) {
102
                self.current_step = self.current_step + 1;
103
                self.move();
104
        } else {
105
                if (is_clicked) {
106
                        self.closeOverlay();
107
                        self.submitForm();                        
108
                }
109
        }
110
} 
111

    
112
// if is_clicked is true, -duh- something has been clicked
113
Carousel.prototype.movePrev = function (is_clicked) {
114
        var self = this;
115
        if (this.current_step > 1) {
116
                this.current_step = this.current_step - 1;
117
                self.move();
118
        } else {
119
                if (is_clicked) {
120
                        self.closeOverlay();
121
                        self.resetForm();                        
122
                }
123
        }
124
} 
125

    
126
Carousel.prototype.initEvents = function () {
127
        var self = this;
128
        this.setDimensions();
129

    
130
        this.next.click(function(e){
131
                e.preventDefault();
132
                self.moveNext(true);
133
        })
134

    
135
        this.prev.click(function(e){
136
                e.preventDefault();
137
                self.movePrev(true);
138
        })
139

    
140
        $('body').keydown(function(e) {
141
          if(e.keyCode == 37) { // left
142
                  e.preventDefault();
143
            self.movePrev(false);
144
          }
145
          else if(e.keyCode == 39) { // right
146
                  e.preventDefault();
147
            self.moveNext(false);
148
          }
149
          else if(e.keyCode == 27) { // ESC
150
                  e.preventDefault();
151
                  self.closeOverlay();
152
          }
153
        });
154
}
155

    
156
$(document).ready(function(){ 
157
        carousel_options = { 
158
                'wrapper': $('.wizard-content'),
159
                'container': $('.vm-wizard-carousel'),
160
                'item': $('.step'),
161
                'next' : $('.bottom').find('.nav.next'),
162
                'prev' : $('.bottom').find('.nav.prev'),
163
        }
164

    
165
        $('.wizard-content').width($(window).width());
166
        var carousel = new Carousel(carousel_options);
167
});