* @class elFinder.history
* and provide "back" and "forward" methods
* @author Dmitry (dio) Levashov
elFinder.prototype.history = function(fm) {
* Update history on "open" event?
* Directories hashes storage
* Current directory index in history
history = [fm.cwd().hash];
* Browser native history object
nativeHistory = (fm.options.useBrowserHistory && window.history && window.history.pushState)? window.history : null,
* @Boolen open next folder?
* @return jQuery.Deferred
if ((fwd && self.canForward()) || (!fwd && self.canBack())) {
return fm.exec('open', history[fwd ? ++current : --current]).fail(reset);
return $.Deferred().reject();
* Sets the native history.
* @param String thash target hash
setNativeHistory = function(thash) {
if (nativeHistory && (! nativeHistory.state || nativeHistory.state.thash !== thash)) {
nativeHistory.pushState({thash: thash}, null, location.pathname + location.search + (thash? '#elf_' + thash : ''));
* Return true if there is previous visited directories
this.canBack = function() {
* Return true if can go forward
this.canForward = function() {
return current < history.length - 1;
this.forward = function() {
// bind to elfinder events
fm.bind('init', function() {
if (nativeHistory && !nativeHistory.state) {
setNativeHistory(fm.startDir());
current >= 0 && l > current + 1 && history.splice(current+1);
history[history.length-1] != cwd && history.push(cwd);
current = history.length - 1;
.reload(fm.options.reloadClearHistory && reset);