|
1 | 1 | /**
|
2 |
| - * bxSlider v4.2.4 |
| 2 | + * bxSlider v4.2.5 |
3 | 3 | * Copyright 2013-2015 Steven Wanderski
|
4 | 4 | * Written while drinking Belgian ales and listening to jazz
|
5 | 5 |
|
|
346 | 346 | * Returns the calculated height of the viewport, used to determine either adaptiveHeight or the maxHeight value
|
347 | 347 | */
|
348 | 348 | var getViewportHeight = function() {
|
349 |
| - var height = el.outerHeight(), |
350 |
| - currentIndex = null, |
| 349 | + var height = 0; |
351 | 350 | // first determine which children (slides) should be used in our height calculation
|
352 |
| - children = $(); |
| 351 | + var children = $(); |
353 | 352 | // if mode is not "vertical" and adaptiveHeight is false, include all children
|
354 | 353 | if (slider.settings.mode !== 'vertical' && !slider.settings.adaptiveHeight) {
|
355 | 354 | children = slider.children;
|
|
360 | 359 | // if carousel, return a slice of children
|
361 | 360 | } else {
|
362 | 361 | // get the individual slide index
|
363 |
| - currentIndex = slider.settings.moveSlides === 1 ? slider.active.index : slider.active.index * getMoveBy(); |
| 362 | + var currentIndex = slider.settings.moveSlides === 1 ? slider.active.index : slider.active.index * getMoveBy(); |
364 | 363 | // add the current slide to the children
|
365 | 364 | children = slider.children.eq(currentIndex);
|
366 | 365 | // cycle through the remaining "showing" slides
|
367 |
| - for (var i = 1; i <= slider.settings.maxSlides - 1; i++) { |
| 366 | + for (i = 1; i <= slider.settings.maxSlides - 1; i++) { |
368 | 367 | // if looped back to the start
|
369 | 368 | if (currentIndex + i >= slider.children.length) {
|
370 |
| - children = children.add(slider.children.eq(currentIndex + i - slider.children.length)); |
| 369 | + children = children.add(slider.children.eq(i - 1)); |
371 | 370 | } else {
|
372 | 371 | children = children.add(slider.children.eq(currentIndex + i));
|
373 | 372 | }
|
|
564 | 563 | if (type === 'slide') {
|
565 | 564 | // set the property value
|
566 | 565 | el.css(slider.animProp, propValue);
|
567 |
| - // bind a callback method - executes when CSS transition completes |
568 |
| - el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(e) { |
569 |
| - //make sure it's the correct one |
570 |
| - if (!$(e.target).is(el)) { return; } |
571 |
| - // unbind the callback |
572 |
| - el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); |
| 566 | + if (duration !== 0) { |
| 567 | + // bind a callback method - executes when CSS transition completes |
| 568 | + el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(e) { |
| 569 | + //make sure it's the correct one |
| 570 | + if (!$(e.target).is(el)) { return; } |
| 571 | + // unbind the callback |
| 572 | + el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); |
| 573 | + updateAfterSlideTransition(); |
| 574 | + }); |
| 575 | + } else { //duration = 0 |
573 | 576 | updateAfterSlideTransition();
|
574 |
| - }); |
| 577 | + } |
575 | 578 | } else if (type === 'reset') {
|
576 | 579 | el.css(slider.animProp, propValue);
|
577 | 580 | } else if (type === 'ticker') {
|
578 | 581 | // make the transition use 'linear'
|
579 | 582 | el.css('-' + slider.cssPrefix + '-transition-timing-function', 'linear');
|
580 | 583 | el.css(slider.animProp, propValue);
|
581 |
| - // bind a callback method - executes when CSS transition completes |
582 |
| - el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(e) { |
583 |
| - //make sure it's the correct one |
584 |
| - if (!$(e.target).is(el)) { return; } |
585 |
| - // unbind the callback |
586 |
| - el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); |
587 |
| - // reset the position |
| 584 | + if (duration !== 0) { |
| 585 | + el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(e) { |
| 586 | + //make sure it's the correct one |
| 587 | + if (!$(e.target).is(el)) { return; } |
| 588 | + // unbind the callback |
| 589 | + el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); |
| 590 | + // reset the position |
| 591 | + setPositionProperty(params.resetValue, 'reset', 0); |
| 592 | + // start the loop again |
| 593 | + tickerLoop(); |
| 594 | + }); |
| 595 | + } else { //duration = 0 |
588 | 596 | setPositionProperty(params.resetValue, 'reset', 0);
|
589 |
| - // start the loop again |
590 | 597 | tickerLoop();
|
591 |
| - }); |
| 598 | + } |
592 | 599 | }
|
593 | 600 | // use JS animate
|
594 | 601 | } else {
|
|
1281 | 1288 | }
|
1282 | 1289 | };
|
1283 | 1290 |
|
| 1291 | + /** |
| 1292 | + * Returns index according to present page range |
| 1293 | + * |
| 1294 | + * @param slideOndex (int) |
| 1295 | + * - the desired slide index |
| 1296 | + */ |
| 1297 | + var setSlideIndex = function(slideIndex) { |
| 1298 | + if (slideIndex < 0) { |
| 1299 | + if (slider.settings.infiniteLoop) { |
| 1300 | + return getPagerQty() - 1; |
| 1301 | + }else { |
| 1302 | + //we don't go to undefined slides |
| 1303 | + return slider.active.index; |
| 1304 | + } |
| 1305 | + // if slideIndex is greater than children length, set active index to 0 (this happens during infinite loop) |
| 1306 | + } else if (slideIndex >= getPagerQty()) { |
| 1307 | + if (slider.settings.infiniteLoop) { |
| 1308 | + return 0; |
| 1309 | + } else { |
| 1310 | + //we don't move to undefined pages |
| 1311 | + return slider.active.index; |
| 1312 | + } |
| 1313 | + // set active index to requested slide |
| 1314 | + } else { |
| 1315 | + return slideIndex; |
| 1316 | + } |
| 1317 | + }; |
| 1318 | + |
1284 | 1319 | /**
|
1285 | 1320 | * ===================================================================================
|
1286 | 1321 | * = PUBLIC FUNCTIONS
|
|
1304 | 1339 | position = {left: 0, top: 0},
|
1305 | 1340 | lastChild = null,
|
1306 | 1341 | lastShowingIndex, eq, value, requestEl;
|
| 1342 | + // store the old index |
| 1343 | + slider.oldIndex = slider.active.index; |
| 1344 | + //set new index |
| 1345 | + slider.active.index = setSlideIndex(slideIndex); |
1307 | 1346 |
|
1308 | 1347 | // if plugin is currently in motion, ignore request
|
1309 |
| - if (slider.working || slider.active.index === slideIndex) { return; } |
| 1348 | + if (slider.working || slider.active.index === slider.oldIndex) { return; } |
1310 | 1349 | // declare that plugin is in motion
|
1311 | 1350 | slider.working = true;
|
1312 |
| - // store the old index |
1313 |
| - slider.oldIndex = slider.active.index; |
1314 |
| - // if slideIndex is less than zero, set active index to last child (this happens during infinite loop) |
1315 |
| - if (slideIndex < 0) { |
1316 |
| - slider.active.index = getPagerQty() - 1; |
1317 |
| - // if slideIndex is greater than children length, set active index to 0 (this happens during infinite loop) |
1318 |
| - } else if (slideIndex >= getPagerQty()) { |
1319 |
| - slider.active.index = 0; |
1320 |
| - // set active index to requested slide |
1321 |
| - } else { |
1322 |
| - slider.active.index = slideIndex; |
1323 |
| - } |
1324 | 1351 |
|
1325 | 1352 | performTransition = slider.settings.onSlideBefore.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index);
|
1326 | 1353 |
|
| 1354 | + // If transitions canceled, reset and return |
1327 | 1355 | if (typeof (performTransition) !== 'undefined' && !performTransition) {
|
1328 | 1356 | slider.active.index = slider.oldIndex; // restore old index
|
1329 | 1357 | slider.working = false; // is not in motion
|
1330 | 1358 | return;
|
1331 | 1359 | }
|
| 1360 | + |
1332 | 1361 | if (direction === 'next') {
|
1333 | 1362 | // Prevent canceling in future functions or lack there-of from negating previous commands to cancel
|
1334 | 1363 | if (!slider.settings.onSlideNext.call(el, slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index)) {
|
|
1341 | 1370 | }
|
1342 | 1371 | }
|
1343 | 1372 |
|
1344 |
| - // If transitions canceled, reset and return |
1345 |
| - if (typeof (performTransition) !== 'undefined' && !performTransition) { |
1346 |
| - slider.active.index = slider.oldIndex; // restore old index |
1347 |
| - slider.working = false; // is not in motion |
1348 |
| - return; |
1349 |
| - } |
1350 |
| - |
1351 | 1373 | // check if last slide
|
1352 | 1374 | slider.active.last = slider.active.index >= getPagerQty() - 1;
|
1353 | 1375 | // update the pager with active class
|
|
1399 | 1421 | slider.active.last = false;
|
1400 | 1422 | // normal non-zero requests
|
1401 | 1423 | } else if (slideIndex >= 0) {
|
1402 |
| - requestEl = slideIndex * getMoveBy(); |
| 1424 | + //parseInt is applied to allow floats for slides/page |
| 1425 | + requestEl = slideIndex * parseInt(getMoveBy()); |
1403 | 1426 | position = slider.children.eq(requestEl).position();
|
1404 | 1427 | }
|
1405 | 1428 |
|
1406 | 1429 | /* If the position doesn't exist
|
1407 | 1430 | * (e.g. if you destroy the slider on a next click),
|
1408 | 1431 | * it doesn't throw an error.
|
1409 | 1432 | */
|
1410 |
| - if (typeof (position) !== undefined) { |
| 1433 | + if (typeof (position) !== 'undefined') { |
1411 | 1434 | value = slider.settings.mode === 'horizontal' ? -(position.left - moveBy) : -position.top;
|
1412 | 1435 | // plugin values to be animated
|
1413 | 1436 | setPositionProperty(value, 'slide', slider.settings.speed);
|
| 1437 | + } else { |
| 1438 | + slider.working = false; |
1414 | 1439 | }
|
1415 | 1440 | }
|
1416 | 1441 | if (slider.settings.ariaHidden) { applyAriaHiddenAttributes(slider.active.index * getMoveBy()); }
|
|
0 commit comments