Skip to content
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
8 changes: 8 additions & 0 deletions dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ default: 'bx-wrapper'
options: string
```

**stateful**
Adds browser history state for any paging action, which views previous slides based on pager when users use browser 'back' or 'forward' buttons. Also appends the specified string to the address URL history. This is most useful for linking a specific slide, or when dynamic content is being loaded based on which slide is being viewed.

```
default: false
options: string
```

###Pager

**pager**
Expand Down
47 changes: 47 additions & 0 deletions dist/jquery.bxslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
pagerSelector: null,
buildPager: null,
pagerCustom: null,
stateful: false,

// CONTROLS
controls: true,
Expand Down Expand Up @@ -340,6 +341,7 @@
if (slider.settings.keyboardEnabled && !slider.settings.ticker) {
$(document).keydown(keyPress);
}
if (slider.settings.stateful){ changeState(0, true); }
};

/**
Expand Down Expand Up @@ -1316,6 +1318,47 @@
}
};

var changeState = function(slideNumber, firstLoad){
url = location.search;
theParam = slider.settings.stateful.toString(); // allows you to change the query string based on
if(url){
searchIndex = url.indexOf('&' + theParam + '=');
// Decides if the param is listed in the url query, appends it if necessary.
if(searchIndex !== -1){
queryString = url.substring(0, searchIndex);
queryString += '&';
}else if(url.indexOf('?' + theParam + '=') > -1){
queryString = '?';
}else{
queryString = url + '&';
}
}else{
queryString = '?';
}
if(firstLoad){ // on first loading, and boolean.
slideSetTo = unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(theParam).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));

goState = true;
// set up event listener
window.onpopstate = function(e) {
// make sure pushstate doesn't trigger when using browser buttons
goState = false;
el.goToSlide(parseInt(e.state));
};
if(slideSetTo){
goState = false;
window.history.replaceState(slideSetTo, slideSetTo, queryString + theParam + "=" + slideSetTo); // ensures state is set when someone comes in with query string.
el.goToSlide(slideSetTo);
}

}else {
if(goState){ // won't run if using back or forward button, otherwise it's a redundant call.
window.history.pushState(slideNumber, slideNumber, queryString + theParam + "=" + slideNumber);
}
goState = true;
}
};

/**
* ===================================================================================
* = PUBLIC FUNCTIONS
Expand Down Expand Up @@ -1439,6 +1482,9 @@
}
}
if (slider.settings.ariaHidden) { applyAriaHiddenAttributes(slider.active.index * getMoveBy()); }

// if stateful is enabled
if (slider.settings.stateful){ changeState(slider.active.index, false); }
};

/**
Expand Down Expand Up @@ -1592,6 +1638,7 @@
$(this).removeData('bxSlider');
};


/**
* Reload the slider (revert all DOM changes, and re-initialize)
*/
Expand Down
Loading