Skip to content
This repository was archived by the owner on Nov 14, 2018. It is now read-only.

Commit bc0f4d3

Browse files
lossirlossir
lossir
authored and
lossir
committed
last version
last version jL from work
1 parent bce5376 commit bc0f4d3

File tree

11 files changed

+1322
-39
lines changed

11 files changed

+1322
-39
lines changed

jL.plugin.carousel.js

+53-39
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Time 19:32
66
*
77
* @author Lossir [email protected]
8-
* @version 2.0
8+
* @version 2.1
99
*
1010
* @augments jL
1111
* @requires jL,jQuery
@@ -21,7 +21,7 @@
2121
* Родительское окно
2222
* @type {HTMLElement|jQuery}
2323
*
24-
* @defaultvalue this
24+
* @defaultValue this
2525
*/
2626
'window' : this,
2727
/**
@@ -35,7 +35,7 @@
3535
*
3636
* @param {Object} control Объект содержит метода упраления слайд-шоу
3737
*
38-
* @defaultvalue null
38+
* @defaultValue null
3939
*/
4040
callback : null,
4141
/**
@@ -82,63 +82,63 @@
8282
* Цикличность
8383
* @type {Boolean}
8484
*
85-
* @defaultvalue true
85+
* @defaultValue true
8686
*/
8787
loop : true,
8888
/**
8989
* Автоматическая смена слайдов [в миллисекундах]
9090
* @type {null|Number}
9191
*
92-
* @defaultvalue null
92+
* @defaultValue null
9393
*/
9494
auto : null,
9595
/**
9696
* Стиль смены сладов
9797
* @type {String} "now","all"
9898
*
99-
* @defaultvalue "now"
99+
* @defaultValue "all"
100100
*/
101101
style : "all",
102102
/**
103103
* Скорость смены сладов
104104
* @type {Number}
105105
*
106-
* @defaultvalue 300
106+
* @defaultValue 300
107107
*/
108108
speed : 300,
109109
/**
110110
* Класс, добавляемый показываемым слайдам
111111
* @type {String|undefined}
112112
*
113-
* @defaultvalue "selected"
113+
* @defaultValue "selected"
114114
*/
115115
selected : "selected",
116116
/**
117117
* Ориентация движений horizontal || vertical
118118
* @type {String}
119119
*
120-
* @defaultvalue "horizontal"
120+
* @defaultValue "horizontal"
121121
*/
122122
orientation: "horizontal",
123123
/**
124124
* Количество элементов, показываемых за раз
125125
* @type {Number}
126126
*
127-
* @defaultvalue 1
127+
* @defaultValue 1
128128
*/
129129
limit : 1,
130130
/**
131131
* Количество элементов, сдвигаемых за раз
132132
* @type {Number}
133133
*
134-
* @defaultvalue 1
134+
* @defaultValue 1
135135
*/
136136
shift : 1,
137137
/**
138138
* Порядковый номер слайда, первого в списке показываемых
139139
* @type {Number}
140140
*
141-
* @defaultvalue 0
141+
* @defaultValue 0
142142
*/
143143
start : 0,
144144
/**
@@ -160,14 +160,6 @@
160160
items = settings.items,
161161
orientation = settings.orientation,
162162
widthItem = 100 / limit,
163-
autoTimerId = 0,
164-
autoTimer = function () {
165-
clearInterval(autoTimerId);
166-
autoTimerId = setInterval(function () {
167-
// console.log('timer');
168-
control('+');
169-
}, settings.auto)
170-
},
171163
/**
172164
* Управление слайдами
173165
*
@@ -183,7 +175,7 @@
183175
/**
184176
* Добавляет класс выделенным пунктам
185177
*/
186-
selected = function () {
178+
selected = function () {
187179
items.removeClass(settings.selected)
188180
.eq(currentItemsIndexStart).addClass(settings.selected);
189181

@@ -197,7 +189,7 @@
197189
*
198190
* @returns {Number}
199191
*/
200-
loopTest = function () {
192+
loopTest = function () {
201193
if (currentItemsIndexStart > shift) {
202194
return settings.loop && prevItemsIndexStart == shift
203195
? 0
@@ -220,21 +212,20 @@
220212
if (action < shift) shift = action;
221213
currentItemsIndexStart = shift;
222214
}
223-
else
215+
else {
224216
if (/(\+|\-)/.test(action)) {
225217
currentItemsIndexStart += +(action + 1) > 0
226218
? settings.shift
227219
: -settings.shift;
228220
currentItemsIndexStart = loopTest();
229221
}
230222
else return;
231-
232-
/* Если первый элемента не изменился - ничего не делаем */
233-
if (currentItemsIndexStart == prevItemsIndexStart)return;
223+
}
234224

235225
if (settings.selected)selected();
236226

237-
if (settings.auto)autoTimer();
227+
/* Если первый элемента не изменился - ничего не делаем */
228+
if (currentItemsIndexStart == prevItemsIndexStart)return;
238229

239230
/* Определяем индексы всех элементов прошлого и текущего показа */
240231
prevItemsIndex = currentItemsIndex;
@@ -266,20 +257,43 @@
266257
}
267258
});
268259

260+
},
261+
controlActionOn = function() {
262+
var ready = true,
263+
sett,
264+
autoTimerId = 0,
265+
test = function (action) {
266+
/* Делаем проверку, чтобы вызовы событий смены слайдов не накладывались и не сбивались */
267+
if (ready) {
268+
control(action);
269+
ready = false;
270+
clearTimeout(sett);
271+
if (settings.auto)autoTimer();
272+
sett = setTimeout(function () {
273+
ready = true;
274+
}, settings.speed);
275+
}
276+
},
277+
autoTimer = function () {
278+
clearInterval(autoTimerId);
279+
autoTimerId = setInterval(function () {
280+
test('+');
281+
}, settings.auto)
282+
};
283+
if (settings.controlBack) settings.controlBack.on('click', function () {
284+
test('-')
285+
});
286+
if (settings.controlForward) settings.controlForward.on('click', function () {
287+
test('+')
288+
});
289+
if (settings.controlDot) settings.controlDot.on('click', function () {
290+
test($(this).index())
291+
});
292+
if (settings.auto)autoTimer();
293+
test(start);
269294
};
270-
271-
if (settings.controlBack) settings.controlBack.on('click', function () {
272-
control('-')
273-
});
274-
if (settings.controlForward) settings.controlForward.on('click', function () {
275-
control('+')
276-
});
277-
if (settings.controlDot) settings.controlDot.on('click', function () {
278-
control($(this).index())
279-
});
280-
295+
controlActionOn();
281296
resize();
282-
control(start);
283297
}
284298
};
285299
return $(this).each(function () {

0 commit comments

Comments
 (0)