Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Controls bug fix #135

Closed
wants to merge 1 commit into from

2 participants

@stoicsquirrel

Fixed bug reported in #128 where next page arrow control appears when there is only one page if infiniteLoop is false and hideControlOnEnd is true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2013
  1. @stoicsquirrel

    Fixes #128. Arrow controls now disappear if there is only one page of…

    stoicsquirrel authored
    … slides, regardless of settings.
This page is out of date. Refresh to see the latest.
Showing with 85 additions and 83 deletions.
  1. +85 −83 jquery.bxslider.js
View
168 jquery.bxslider.js
@@ -11,9 +11,9 @@
;(function($){
var plugin = {};
-
+
var defaults = {
-
+
// GENERAL
mode: 'horizontal',
slideSelector: '',
@@ -39,7 +39,7 @@
oneToOneTouch: true,
preventDefaultSwipeX: true,
preventDefaultSwipeY: false,
-
+
// PAGER
pager: true,
pagerType: 'full',
@@ -47,7 +47,7 @@
pagerSelector: null,
buildPager: null,
pagerCustom: null,
-
+
// CONTROLS
controls: true,
nextText: 'Next',
@@ -59,7 +59,7 @@
stopText: 'Stop',
autoControlsCombine: false,
autoControlsSelector: null,
-
+
// AUTO
auto: false,
pause: 4000,
@@ -67,13 +67,13 @@
autoDirection: 'next',
autoHover: false,
autoDelay: 0,
-
+
// CAROUSEL
minSlides: 1,
maxSlides: 1,
moveSlides: 0,
slideWidth: 0,
-
+
// CALLBACKS
onSliderLoad: function() {},
onSlideBefore: function() {},
@@ -83,15 +83,15 @@
}
$.fn.bxSlider = function(options){
-
+
if(this.length == 0) return this;
-
+
// support mutltiple elements
if(this.length > 1){
this.each(function(){$(this).bxSlider(options)});
return this;
}
-
+
// create a namespace to be used throughout the plugin
var slider = {};
// set a reference to our slider element
@@ -105,14 +105,14 @@
var windowWidth = $(window).width();
var windowHeight = $(window).height();
-
-
+
+
/**
* ===================================================================================
* = PRIVATE FUNCTIONS
* ===================================================================================
*/
-
+
/**
* Initializes namespace settings to be used throughout plugin
*/
@@ -290,7 +290,7 @@
// if touchEnabled is true, setup the touch events
if (slider.settings.touchEnabled && !slider.settings.ticker) initTouch();
}
-
+
/**
* Returns the calculated height of the viewport, used to determine either adaptiveHeight or the maxHeight value
*/
@@ -354,7 +354,7 @@
}
return width;
}
-
+
/**
* Returns the calculated width to be applied to each slide
*/
@@ -378,7 +378,7 @@
}
return newElWidth;
}
-
+
/**
* Returns the number of slides currently visible in the viewport (includes partially visible slides)
*/
@@ -402,7 +402,7 @@
}
return slidesShowing;
}
-
+
/**
* Returns the number of pages (one full viewport of slides is one "page")
*/
@@ -429,7 +429,7 @@
}
return pagerQty;
}
-
+
/**
* Returns the number of indivual slides by which to shift the slider
*/
@@ -441,7 +441,7 @@
// if moveSlides is 0 (auto)
return getNumberSlidesShowing();
}
-
+
/**
* Sets the slider's (el) left or top position
*/
@@ -474,18 +474,18 @@
}
}
}
-
+
/**
* Sets the el's animating property position (which in turn will sometimes animate el).
* If using CSS, sets the transform property. If not using CSS, sets the top / left property.
*
- * @param value (int)
+ * @param value (int)
* - the animating property's value
*
* @param type (string) 'slider', 'reset', 'ticker'
* - the type of instance for which the function is being
*
- * @param duration (int)
+ * @param duration (int)
* - the amount of time (in ms) the transition should occupy
*
* @param params (array) optional
@@ -542,7 +542,7 @@
}
}
}
-
+
/**
* Populates the pager with proper amount of pages
*/
@@ -567,7 +567,7 @@
// populate the pager element with pager links
slider.pagerEl.html(pagerHtml);
}
-
+
/**
* Appends the pager to the controls element
*/
@@ -590,7 +590,7 @@
// assign the pager click binding
slider.pagerEl.delegate('a', 'click', clickPagerBind);
}
-
+
/**
* Appends prev / next controls to the controls element
*/
@@ -618,7 +618,7 @@
slider.controls.el.addClass('bx-has-controls-direction').append(slider.controls.directionEl);
}
}
-
+
/**
* Appends start / stop auto controls to the controls element
*/
@@ -647,7 +647,7 @@
// update the auto controls
updateAutoControls(slider.settings.autoStart ? 'stop' : 'start');
}
-
+
/**
* Appends image captions to the DOM
*/
@@ -660,11 +660,11 @@
if (title != undefined) $(this).append('<div class="bx-caption"><span>' + title + '</span></div>');
});
}
-
+
/**
* Click next binding
*
- * @param e (event)
+ * @param e (event)
* - DOM event object
*/
var clickNextBind = function(e){
@@ -673,11 +673,11 @@
el.goToNextSlide();
e.preventDefault();
}
-
+
/**
* Click prev binding
*
- * @param e (event)
+ * @param e (event)
* - DOM event object
*/
var clickPrevBind = function(e){
@@ -686,22 +686,22 @@
el.goToPrevSlide();
e.preventDefault();
}
-
+
/**
* Click start binding
*
- * @param e (event)
+ * @param e (event)
* - DOM event object
*/
var clickStartBind = function(e){
el.startAuto();
e.preventDefault();
}
-
+
/**
* Click stop binding
*
- * @param e (event)
+ * @param e (event)
* - DOM event object
*/
var clickStopBind = function(e){
@@ -712,7 +712,7 @@
/**
* Click pager binding
*
- * @param e (event)
+ * @param e (event)
* - DOM event object
*/
var clickPagerBind = function(e){
@@ -724,11 +724,11 @@
if(pagerIndex != slider.active.index) el.goToSlide(pagerIndex);
e.preventDefault();
}
-
+
/**
* Updates the pager links with an active class
*
- * @param slideIndex (int)
+ * @param slideIndex (int)
* - index of slide to make active
*/
var updatePagerActive = function(slideIndex){
@@ -742,7 +742,7 @@
// apply the active class for all pagers
slider.pagerEl.each(function(i, el) { $(el).find('a').eq(slideIndex).addClass('active'); });
}
-
+
/**
* Performs needed actions after a slide transition
*/
@@ -769,7 +769,7 @@
// onSlideAfter callback
slider.settings.onSlideAfter(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index);
}
-
+
/**
* Updates the auto controls state (either active, or combined switch)
*
@@ -777,42 +777,44 @@
* - the new state of the auto show
*/
var updateAutoControls = function(state){
- // if autoControlsCombine is true, replace the current control with the new state
+ // if autoControlsCombine is true, replace the current control with the new state
if(slider.settings.autoControlsCombine){
slider.controls.autoEl.html(slider.controls[state]);
- // if autoControlsCombine is false, apply the "active" class to the appropriate control
+ // if autoControlsCombine is false, apply the "active" class to the appropriate control
}else{
slider.controls.autoEl.find('a').removeClass('active');
slider.controls.autoEl.find('a:not(.bx-' + state + ')').addClass('active');
}
}
-
+
/**
* Updates the direction controls (checks if either should be hidden)
*/
var updateDirectionControls = function(){
- // if infiniteLoop is false and hideControlOnEnd is true
- if(!slider.settings.infiniteLoop && slider.settings.hideControlOnEnd){
- // if first slide
- if (slider.active.index == 0){
- slider.controls.prev.addClass('disabled');
- slider.controls.next.removeClass('disabled');
- // if last slide
- }else if(slider.active.index == getPagerQty() - 1){
- slider.controls.next.addClass('disabled');
- slider.controls.prev.removeClass('disabled');
- // if any slide in the middle
- }else{
- slider.controls.prev.removeClass('disabled');
- slider.controls.next.removeClass('disabled');
- }
// if slider has only one page, disable controls
- }else if(getPagerQty() == 1){
+ if(getPagerQty() == 1){
slider.controls.prev.addClass('disabled');
slider.controls.next.addClass('disabled');
+ }else{
+ // if infiniteLoop is false and hideControlOnEnd is true
+ if(!slider.settings.infiniteLoop && slider.settings.hideControlOnEnd){
+ // if first slide
+ if (slider.active.index == 0){
+ slider.controls.prev.addClass('disabled');
+ slider.controls.next.removeClass('disabled');
+ // if last slide
+ }else if(slider.active.index == getPagerQty() - 1){
+ slider.controls.next.addClass('disabled');
+ slider.controls.prev.removeClass('disabled');
+ // if any slide in the middle
+ }else{
+ slider.controls.prev.removeClass('disabled');
+ slider.controls.next.removeClass('disabled');
+ }
+ }
}
}
-
+
/**
* Initialzes the auto process
*/
@@ -846,7 +848,7 @@
});
}
}
-
+
/**
* Initialzes the ticker process
*/
@@ -889,7 +891,7 @@
// start the ticker loop
tickerLoop();
}
-
+
/**
* Runs a continuous loop, news ticker-style
*/
@@ -909,7 +911,7 @@
var params = {resetValue: resetValue};
setPositionProperty(animateProperty, 'ticker', speed, params);
}
-
+
/**
* Initializes touch events
*/
@@ -921,11 +923,11 @@
}
slider.viewport.bind('touchstart', onTouchStart);
}
-
+
/**
* Event handler for "touchstart"
*
- * @param e (event)
+ * @param e (event)
* - DOM event object
*/
var onTouchStart = function(e){
@@ -944,11 +946,11 @@
slider.viewport.bind('touchend', onTouchEnd);
}
}
-
+
/**
* Event handler for "touchmove"
*
- * @param e (event)
+ * @param e (event)
* - DOM event object
*/
var onTouchMove = function(e){
@@ -977,11 +979,11 @@
setPositionProperty(value, 'reset', 0);
}
}
-
+
/**
* Event handler for "touchend"
*
- * @param e (event)
+ * @param e (event)
* - DOM event object
*/
var onTouchEnd = function(e){
@@ -1044,20 +1046,20 @@
el.redrawSlider();
}
}
-
+
/**
* ===================================================================================
* = PUBLIC FUNCTIONS
* ===================================================================================
*/
-
+
/**
* Performs slide transition to the specified slide
*
- * @param slideIndex (int)
+ * @param slideIndex (int)
* - the destination slide's index (zero-based)
*
- * @param direction (string)
+ * @param direction (string)
* - INTERNAL USE ONLY - the direction of travel ("prev" / "next")
*/
el.goToSlide = function(slideIndex, direction){
@@ -1145,7 +1147,7 @@
setPositionProperty(value, 'slide', slider.settings.speed);
}
}
-
+
/**
* Transitions to the next slide in the show
*/
@@ -1155,7 +1157,7 @@
var pagerIndex = parseInt(slider.active.index) + 1;
el.goToSlide(pagerIndex, 'next');
}
-
+
/**
* Transitions to the prev slide in the show
*/
@@ -1165,11 +1167,11 @@
var pagerIndex = parseInt(slider.active.index) - 1;
el.goToSlide(pagerIndex, 'prev');
}
-
+
/**
* Starts the auto show
*
- * @param preventControlUpdate (boolean)
+ * @param preventControlUpdate (boolean)
* - if true, auto controls state will not be updated
*/
el.startAuto = function(preventControlUpdate){
@@ -1182,11 +1184,11 @@
// if auto controls are displayed and preventControlUpdate is not true
if (slider.settings.autoControls && preventControlUpdate != true) updateAutoControls('stop');
}
-
+
/**
* Stops the auto show
*
- * @param preventControlUpdate (boolean)
+ * @param preventControlUpdate (boolean)
* - if true, auto controls state will not be updated
*/
el.stopAuto = function(preventControlUpdate){
@@ -1198,14 +1200,14 @@
// if auto controls are displayed and preventControlUpdate is not true
if (slider.settings.autoControls && preventControlUpdate != true) updateAutoControls('start');
}
-
+
/**
* Returns current slide index (zero-based)
*/
el.getCurrentSlide = function(){
return slider.active.index;
}
-
+
/**
* Returns number of slides in show
*/
@@ -1263,9 +1265,9 @@
el.destroySlider();
init();
}
-
+
init();
-
+
// returns the current jQuery object
return this;
}
Something went wrong with that request. Please try again.