diff --git a/readme.md b/readme.md index c88f4dd0..d52d64c8 100644 --- a/readme.md +++ b/readme.md @@ -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. ``` @@ -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. ``` @@ -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. @@ -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 @@ -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 @@ -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. \ No newline at end of file +Long live Zep. diff --git a/src/js/jquery.bxslider.js b/src/js/jquery.bxslider.js index a0a834b6..5217682a 100644 --- a/src/js/jquery.bxslider.js +++ b/src/js/jquery.bxslider.js @@ -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; } @@ -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 */ @@ -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, @@ -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 */