Skip to content

Commit e98e1f4

Browse files
committed
Updating counter
1 parent 239c5d5 commit e98e1f4

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

jquery.cyclify.js

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@
1818
$cycles = this.find('.cycle-cycles div'),
1919
max = $cycles.length,
2020
min = 0,
21+
current_index = 0,
2122
options = $.extend(defaults, options);
23+
24+
function set_current_cycle(num) {
25+
current_index = num;
26+
$cycles.removeClass('current-cycle');
27+
$cycles.hide();
28+
$($cycles[num]).show(options.delay, options.transition).addClass('current-cycle');
2229

30+
}
31+
2332
function current_cycle_num() {
24-
var rval;
25-
$cycles.each(function(i, elem) {
26-
if($(elem).is(':visible')) {
27-
rval = i;
28-
return false; // returning false stops each() from within callback
29-
}
30-
});
31-
return rval;
33+
return current_index;
3234
}
3335
function callback_if_necessary() {
3436
if(typeof options.success === 'function') {
@@ -39,10 +41,9 @@
3941
var next = function next() {
4042
var cycle_num = current_cycle_num(),
4143
$current = $($cycles[cycle_num]);
44+
4245
if(cycle_num < (max - 1)) {
43-
$current.hide(options.delay, options.transition, function() {
44-
$($cycles[cycle_num + 1]).show(options.delay, options.transition);
45-
});
46+
set_current_cycle(cycle_num + 1);
4647
callback_if_necessary();
4748
} else {
4849
if(options.loop) {
@@ -52,32 +53,22 @@
5253
};
5354
var prev = function prev() {
5455
var cycle_num = current_cycle_num(),
55-
$current = $($cycles[cycle_num]);
56+
$current = $($cycles[cycle_num]);
5657
if(cycle_num > min) {
57-
$current.hide( options.delay, options.transition, function() {
58-
$($cycles[cycle_num - 1]).show(options.delay, options.transition);
59-
});
60-
callback_if_necessary();
58+
set_current_cycle(cycle_num - 1);
59+
callback_if_necessary();
6160
} else {
6261
if(options.loop) {
6362
end();
6463
}
6564
}
6665
};
6766
var begin = function begin() {
68-
var cycle_num = current_cycle_num(),
69-
$current = $($cycles[cycle_num]);
70-
$current.hide(options.delay, options.transition, function() {
71-
$($cycles[0]).show(options.delay, options.transition);
72-
});
73-
callback_if_necessary();
67+
set_current_cycle(0);
68+
callback_if_necessary();
7469
};
7570
var end = function end() {
76-
var cycle_num = current_cycle_num(),
77-
$current = $($cycles[cycle_num]);
78-
$current.hide(options.delay, options.transition, function() {
79-
$($cycles[max - 1]).show(options.delay, options.transition);
80-
});
71+
set_current_cycle(max - 1);
8172
callback_if_necessary();
8273
};
8374

@@ -94,8 +85,8 @@
9485
$end.die().live('click', function() {
9586
end();
9687
});
88+
set_current_cycle(0);
9789
begin();
98-
$cycles.not(":first-child").hide();
9990
}
10091

10192
init();
@@ -104,7 +95,7 @@
10495
next : next,
10596
prev : prev,
10697
begin : begin,
107-
end : end
98+
end : end,
10899
}
109100
}
110101
});

0 commit comments

Comments
 (0)