root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / wizard-carousel.js @ 989de44a
History | View | Annotate | Download (5.1 kB)
1 |
/*
|
---|---|
2 |
// all functions use pixels
|
3 |
ui.wizard ={
|
4 |
current_step: undefined,
|
5 |
vm: {total_step: 4},
|
6 |
current_position: undefined,
|
7 |
relocation: undefined,
|
8 |
|
9 |
// OK
|
10 |
// sets the width and height of the carousel and its divs
|
11 |
set_dimensions: function() {
|
12 |
console.log('set dimentions');
|
13 |
ui.wizard.relocation = $(window).width();
|
14 |
console.log(ui.wizard.relocation);
|
15 |
$('.vm-wizard-carousel').children('div').width(ui.wizard.relocation);
|
16 |
},
|
17 |
|
18 |
// sets the width and height of the carousel and its divs when the screen is resized (in PIXELS)
|
19 |
adjust_to_resized_screen: function() {
|
20 |
$(window).resize(function() {
|
21 |
console.log('resized');
|
22 |
ui.wizard.set_dimensions();
|
23 |
|
24 |
if(ui.wizard.current_position<=0) {
|
25 |
// the carousel moves to left -> this is the case that acts on resize
|
26 |
ui.wizard.current_position = -((ui.wizard.current_step-1)*ui.wizard.relocation);
|
27 |
}
|
28 |
else
|
29 |
ui.wizard.current_position = (ui.wizard.current_step-1)*ui.wizard.relocation;
|
30 |
|
31 |
$('.vm-wizard-carousel').css('left', ui.wizard.current_position+'px');
|
32 |
})
|
33 |
},
|
34 |
|
35 |
|
36 |
|
37 |
move_to_step: function(prev_btn, next_btn) {
|
38 |
var speed =500;
|
39 |
// when the button "next" is pressed show the next step (if there is a next step)
|
40 |
next_btn.click(function(e){
|
41 |
e.preventDefault();
|
42 |
console.log('you clicked next!')
|
43 |
if(ui.wizard.current_step < ui.wizard.vm.total_step){
|
44 |
prev_btn.find('span').html('PREVIOUS');
|
45 |
ui.wizard.current_step++;
|
46 |
ui.wizard.current_position -=ui.wizard.relocation;
|
47 |
$('.vm-wizard-carousel').animate({left: ui.wizard.current_position+'px'}, speed);
|
48 |
ui.wizard.indicate_step(ui.wizard.current_step);
|
49 |
ui.wizard.set_movement_tags(ui.wizard.current_step, prev_btn, next_btn);
|
50 |
|
51 |
if(ui.wizard.current_step == 3) {
|
52 |
setTimeout(function() { $('.vm-name').find('input').focus() }, speed/2);
|
53 |
}
|
54 |
|
55 |
}
|
56 |
else {
|
57 |
console.log('This is the last step.');
|
58 |
}
|
59 |
})
|
60 |
|
61 |
// when the button "previous" is pressed show the previous step (if there is a previous step)
|
62 |
prev_btn.click(function(e){
|
63 |
e.preventDefault();
|
64 |
if(ui.wizard.current_step > 1){
|
65 |
ui.wizard.current_step--;
|
66 |
ui.wizard.current_position +=ui.wizard.relocation;
|
67 |
$('.vm-wizard-carousel').animate({left: ui.wizard.current_position+'px'}, speed);
|
68 |
ui.wizard.indicate_step(ui.wizard.current_step);
|
69 |
ui.wizard.set_movement_tags(ui.wizard.current_step, prev_btn, next_btn);
|
70 |
}
|
71 |
else {
|
72 |
console.log('This is the 1st step.')
|
73 |
}
|
74 |
})
|
75 |
},
|
76 |
|
77 |
// sets the width and height of the steps and of the carousel (in PIXELS)
|
78 |
initialize_relocation: function(){
|
79 |
console.log('initialize_relocation');
|
80 |
ui.wizard.adjust_to_resized_screen();
|
81 |
ui.wizard.set_dimensions();
|
82 |
},
|
83 |
// for the carousel index
|
84 |
indicate_step: function(step) {
|
85 |
$('.wizard .top .sub-menu[data-step]').hide();
|
86 |
$('.wizard .top .sub-menu[data-step='+step+']').fadeIn();
|
87 |
$('.nums').children().removeClass('current');
|
88 |
$('.nums').children().find('a:contains("'+ui.wizard.current_step+'")').parent('li').addClass('current');
|
89 |
},
|
90 |
|
91 |
|
92 |
set_movement_tags: function(step, left_btn, right_btn) {
|
93 |
if (step==1) {
|
94 |
left_btn.find('span').html('CANCEL');
|
95 |
}
|
96 |
else if(step==ui.wizard.vm.total_step) {
|
97 |
right_btn.find('span').html('CREATE');
|
98 |
}
|
99 |
else {
|
100 |
left_btn.find('span').html('PREVIOUS');
|
101 |
right_btn.find('span').html('NEXT');
|
102 |
}
|
103 |
}
|
104 |
}
|
105 |
|
106 |
|
107 |
$(document).ready(function(){
|
108 |
|
109 |
ui.wizard.current_step =1;
|
110 |
ui.wizard.current_position =0;
|
111 |
|
112 |
var new_vm_btn =$('.new-btn, .add-new');
|
113 |
var prev_btn = $('.bottom').find('.nav.prev');
|
114 |
var next_btn = $('.bottom').find('.nav.next');
|
115 |
$('.wizard .nums').click(function(e){
|
116 |
e.preventDefault();
|
117 |
})
|
118 |
|
119 |
ui.wizard.initialize_relocation();
|
120 |
ui.wizard.move_to_step(prev_btn, next_btn);
|
121 |
ui.wizard.set_movement_tags(ui.wizard.current_step, prev_btn, next_btn);
|
122 |
|
123 |
|
124 |
});
|
125 |
*/
|
126 |
|
127 |
/*
|
128 |
Wrapper element must have set width and overflow hidden properties;
|
129 |
Item elements should have no margin
|
130 |
*/
|
131 |
function Carousel(options) { |
132 |
var defaults = {
|
133 |
'wrapper': $('.carousel-wrapper'), |
134 |
'container': $('.carousel-container'), |
135 |
'item': $('.carousel-item'), |
136 |
'next': $('.carousel-next'), |
137 |
'prev': $('.carousel-prev'), |
138 |
'speed': 1000, |
139 |
'current_step': 1, |
140 |
} |
141 |
this.options = _.defaults(options,defaults);
|
142 |
this.wrapper = options.wrapper;
|
143 |
this.container = options.container;
|
144 |
this.item = options.item;
|
145 |
this.next = options.next;
|
146 |
this.prev = options.prev;
|
147 |
this.speed = options.speed;
|
148 |
this.current_step = options.current_step;
|
149 |
this.total_items = this.item.length; |
150 |
this.initEvents();
|
151 |
} |
152 |
|
153 |
Carousel.prototype.setDimensions = function (){ |
154 |
this.wrapper.css('width', 100*this.total_items+'%'); |
155 |
this.container.find(this.item).css('width', 100/this.total_items+'%'); |
156 |
} |
157 |
|
158 |
Carousel.prototype.initEvents = function () { |
159 |
var self = this; |
160 |
console.log(this.options);
|
161 |
this.setDimensions();
|
162 |
|
163 |
this.next.click(function(e){ |
164 |
e.preventDefault(); |
165 |
}) |
166 |
} |
167 |
|
168 |
|
169 |
|
170 |
$(document).ready(function(){ |
171 |
carousel_options = { |
172 |
'wrapper': $('.wizard-content'), |
173 |
'container': $('.vm-wizard-carousel'), |
174 |
'item': $('.step'), |
175 |
'next' : $('.bottom').find('.nav.next'); |
176 |
'prev' : $('.bottom').find('.nav.prev'); |
177 |
} |
178 |
|
179 |
$('.wizard-content').width($(window).width()); |
180 |
var carousel = new Carousel(carousel_options); |
181 |
window.car = carousel; |
182 |
}); |