|
5 | 5 | * Time 19:32
|
6 | 6 | *
|
7 | 7 | * @author Lossir [email protected]
|
8 |
| - * @version 2.0 |
| 8 | + * @version 2.1 |
9 | 9 | *
|
10 | 10 | * @augments jL
|
11 | 11 | * @requires jL,jQuery
|
|
21 | 21 | * Родительское окно
|
22 | 22 | * @type {HTMLElement|jQuery}
|
23 | 23 | *
|
24 |
| - * @defaultvalue this |
| 24 | + * @defaultValue this |
25 | 25 | */
|
26 | 26 | 'window' : this,
|
27 | 27 | /**
|
|
35 | 35 | *
|
36 | 36 | * @param {Object} control Объект содержит метода упраления слайд-шоу
|
37 | 37 | *
|
38 |
| - * @defaultvalue null |
| 38 | + * @defaultValue null |
39 | 39 | */
|
40 | 40 | callback : null,
|
41 | 41 | /**
|
|
82 | 82 | * Цикличность
|
83 | 83 | * @type {Boolean}
|
84 | 84 | *
|
85 |
| - * @defaultvalue true |
| 85 | + * @defaultValue true |
86 | 86 | */
|
87 | 87 | loop : true,
|
88 | 88 | /**
|
89 | 89 | * Автоматическая смена слайдов [в миллисекундах]
|
90 | 90 | * @type {null|Number}
|
91 | 91 | *
|
92 |
| - * @defaultvalue null |
| 92 | + * @defaultValue null |
93 | 93 | */
|
94 | 94 | auto : null,
|
95 | 95 | /**
|
96 | 96 | * Стиль смены сладов
|
97 | 97 | * @type {String} "now","all"
|
98 | 98 | *
|
99 |
| - * @defaultvalue "now" |
| 99 | + * @defaultValue "all" |
100 | 100 | */
|
101 | 101 | style : "all",
|
102 | 102 | /**
|
103 | 103 | * Скорость смены сладов
|
104 | 104 | * @type {Number}
|
105 | 105 | *
|
106 |
| - * @defaultvalue 300 |
| 106 | + * @defaultValue 300 |
107 | 107 | */
|
108 | 108 | speed : 300,
|
109 | 109 | /**
|
110 | 110 | * Класс, добавляемый показываемым слайдам
|
111 | 111 | * @type {String|undefined}
|
112 | 112 | *
|
113 |
| - * @defaultvalue "selected" |
| 113 | + * @defaultValue "selected" |
114 | 114 | */
|
115 | 115 | selected : "selected",
|
116 | 116 | /**
|
117 | 117 | * Ориентация движений horizontal || vertical
|
118 | 118 | * @type {String}
|
119 | 119 | *
|
120 |
| - * @defaultvalue "horizontal" |
| 120 | + * @defaultValue "horizontal" |
121 | 121 | */
|
122 | 122 | orientation: "horizontal",
|
123 | 123 | /**
|
124 | 124 | * Количество элементов, показываемых за раз
|
125 | 125 | * @type {Number}
|
126 | 126 | *
|
127 |
| - * @defaultvalue 1 |
| 127 | + * @defaultValue 1 |
128 | 128 | */
|
129 | 129 | limit : 1,
|
130 | 130 | /**
|
131 | 131 | * Количество элементов, сдвигаемых за раз
|
132 | 132 | * @type {Number}
|
133 | 133 | *
|
134 |
| - * @defaultvalue 1 |
| 134 | + * @defaultValue 1 |
135 | 135 | */
|
136 | 136 | shift : 1,
|
137 | 137 | /**
|
138 | 138 | * Порядковый номер слайда, первого в списке показываемых
|
139 | 139 | * @type {Number}
|
140 | 140 | *
|
141 |
| - * @defaultvalue 0 |
| 141 | + * @defaultValue 0 |
142 | 142 | */
|
143 | 143 | start : 0,
|
144 | 144 | /**
|
|
160 | 160 | items = settings.items,
|
161 | 161 | orientation = settings.orientation,
|
162 | 162 | 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 |
| - }, |
171 | 163 | /**
|
172 | 164 | * Управление слайдами
|
173 | 165 | *
|
|
183 | 175 | /**
|
184 | 176 | * Добавляет класс выделенным пунктам
|
185 | 177 | */
|
186 |
| - selected = function () { |
| 178 | + selected = function () { |
187 | 179 | items.removeClass(settings.selected)
|
188 | 180 | .eq(currentItemsIndexStart).addClass(settings.selected);
|
189 | 181 |
|
|
197 | 189 | *
|
198 | 190 | * @returns {Number}
|
199 | 191 | */
|
200 |
| - loopTest = function () { |
| 192 | + loopTest = function () { |
201 | 193 | if (currentItemsIndexStart > shift) {
|
202 | 194 | return settings.loop && prevItemsIndexStart == shift
|
203 | 195 | ? 0
|
|
220 | 212 | if (action < shift) shift = action;
|
221 | 213 | currentItemsIndexStart = shift;
|
222 | 214 | }
|
223 |
| - else |
| 215 | + else { |
224 | 216 | if (/(\+|\-)/.test(action)) {
|
225 | 217 | currentItemsIndexStart += +(action + 1) > 0
|
226 | 218 | ? settings.shift
|
227 | 219 | : -settings.shift;
|
228 | 220 | currentItemsIndexStart = loopTest();
|
229 | 221 | }
|
230 | 222 | else return;
|
231 |
| - |
232 |
| - /* Если первый элемента не изменился - ничего не делаем */ |
233 |
| - if (currentItemsIndexStart == prevItemsIndexStart)return; |
| 223 | + } |
234 | 224 |
|
235 | 225 | if (settings.selected)selected();
|
236 | 226 |
|
237 |
| - if (settings.auto)autoTimer(); |
| 227 | + /* Если первый элемента не изменился - ничего не делаем */ |
| 228 | + if (currentItemsIndexStart == prevItemsIndexStart)return; |
238 | 229 |
|
239 | 230 | /* Определяем индексы всех элементов прошлого и текущего показа */
|
240 | 231 | prevItemsIndex = currentItemsIndex;
|
|
266 | 257 | }
|
267 | 258 | });
|
268 | 259 |
|
| 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); |
269 | 294 | };
|
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(); |
281 | 296 | resize();
|
282 |
| - control(start); |
283 | 297 | }
|
284 | 298 | };
|
285 | 299 | return $(this).each(function () {
|
|
0 commit comments