Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow for server side paging of data #943

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ Adds Aria Live attribute to slider.
default: true
options: boolean (true / false)
```

**ariaHidden**
Adds Aria Hidden attribute to any nonvisible slides.
```
Expand Down Expand Up @@ -485,6 +485,16 @@ arguments:
currentIndex: element index of the current slide
```

**onNeedData**
Executes when the next page to be displayed will require more data to be fetched
```
default: function($slideElement, callback) { callback(); }
options: function($slideElement, callback) { // your code here }
arguments:
$slideElement: jQuery element of the destination element
callback: function to be called once DOM is updated with new elements
```

**onSlideBefore**
Executes immediately before each slide transition.
```
Expand Down Expand Up @@ -618,7 +628,7 @@ slider.destroySlider();
From the command line:

1. Install `grunt-cli` and `bower` globally with `npm install -g grunt-cli bower`.
2. Run `npm install`. npm will look at `package.json` and automatically install the necessary dependencies.
2. Run `npm install`. npm will look at `package.json` and automatically install the necessary dependencies.
3. Run `bower install`, which installs front-end packages defined in `bower.json`.

When completed, you'll be able to run the various Grunt commands provided from the command line.
Expand Down Expand Up @@ -648,7 +658,7 @@ Everyone is welcome to help [contribute](CONTRIBUTING.md) and improve this proje
* Fix: Slider runs into undefined state when reloadSlider is called before initialization was finished #833

### Version 4.2.4
NOTICE: We have switched to a Grunt based build process in order to leverage [Assemble](http://assemble.io) for local documentation building. Please review the above notes about Grunt for the commands available.
NOTICE: We have switched to a Grunt based build process in order to leverage [Assemble](http://assemble.io) for local documentation building. Please review the above notes about Grunt for the commands available.

* Fix: Fixed transition from first to last slide during infinite loop #778
* Fix: Reload on multiple sliders doesn't work? #755
Expand All @@ -661,7 +671,7 @@ NOTICE: We have switched to a Grunt based build process in order to leverage [As
* Enhancement: Slider getter through jquery object #739
* Enhancement: Add aria attributes #751
* Enhancement: Slider element in every callback and a new method getSliderElement (#780)
* Enhancement: Local Documentiation and examples. I have added buildable documentation to the repo. This will expand over time and allow for community corrections as needed. Please see above Grunt notes on how to build.
* Enhancement: Local Documentiation and examples. I have added buildable documentation to the repo. This will expand over time and allow for community corrections as needed. Please see above Grunt notes on how to build.


### Version 4.2.3
Expand Down Expand Up @@ -745,4 +755,4 @@ You now have all the necessary dependencies to run the build process.
* Slider now only needs to load visible slides (by default) in order to initialize which results in much faster loading. A "preloadImages" setting allows for configuration.


Long live Zep.
Long live Zep.
21 changes: 20 additions & 1 deletion src/js/jquery.bxslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
onSliderLoad: function() { return true; },
onSlideBefore: function() { return true; },
onSlideAfter: function() { return true; },
onNeedData: function(slideElement, callback) { callback(false); },
onSlideNext: function() { return true; },
onSlidePrev: function() { return true; },
onSliderResize: function() { return true; }
Expand Down Expand Up @@ -482,6 +483,13 @@
return pagerQty;
};

var needData = function() {
var curr = (slider.active.index + 1) * getNumberSlidesShowing(),
needed = curr + getNumberSlidesShowing();

return !slider.settings.infiniteLoop && needed > slider.children.length;
};

/**
* Returns the number of individual slides by which to shift the slider
*/
Expand Down Expand Up @@ -1323,7 +1331,7 @@
* @param direction (string)
* - INTERNAL USE ONLY - the direction of travel ("prev" / "next")
*/
el.goToSlide = function(slideIndex, direction) {
var _goToSlide = function(slideIndex, direction) {
// onSlideBefore, onSlideNext, onSlidePrev callbacks
// Allow transition canceling based on returned value
var performTransition = true,
Expand Down Expand Up @@ -1433,6 +1441,17 @@
if (slider.settings.ariaHidden) { applyAriaHiddenAttributes(slider.active.index * getMoveBy()); }
};

el.goToSlide = function(slideIndex, direction) {
if (needData()) {
slider.settings.onNeedData(slider.children.eq(slider.active.index), function() {
slider.children = el.children(slider.settings.slideSelector);
_goToSlide(slideIndex, direction);
});
} else {
_goToSlide(slideIndex, direction);
}
};

/**
* Transitions to the next slide in the show
*/
Expand Down