forked from xtwoend/elFinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elFinder.history.js
100 lines (93 loc) · 1.67 KB
/
elFinder.history.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* @class elFinder.history
* Store visited folders
* and provide "back" and "forward" methods
*
* @author Dmitry (dio) Levashov
*/
elFinder.prototype.history = function(fm) {
var self = this,
/**
* Update history on "open" event?
*
* @type Boolean
*/
update = true,
/**
* Directories hashes storage
*
* @type Array
*/
history = [],
/**
* Current directory index in history
*
* @type Number
*/
current,
/**
* Clear history
*
* @return void
*/
reset = function() {
history = [fm.cwd().hash];
current = 0;
update = true;
},
/**
* Open prev/next folder
*
* @Boolen open next folder?
* @return jQuery.Deferred
*/
go = function(fwd) {
if ((fwd && self.canForward()) || (!fwd && self.canBack())) {
update = false;
return fm.exec('open', history[fwd ? ++current : --current]).fail(reset);
}
return $.Deferred().reject();
};
/**
* Return true if there is previous visited directories
*
* @return Boolen
*/
this.canBack = function() {
return current > 0;
}
/**
* Return true if can go forward
*
* @return Boolen
*/
this.canForward = function() {
return current < history.length - 1;
}
/**
* Go back
*
* @return void
*/
this.back = go;
/**
* Go forward
*
* @return void
*/
this.forward = function() {
return go(true);
}
// bind to elfinder events
fm.open(function(e) {
var l = history.length,
cwd = fm.cwd().hash;
if (update) {
current >= 0 && l > current + 1 && history.splice(current+1);
history[history.length-1] != cwd && history.push(cwd);
current = history.length - 1;
}
update = true;
})
.reload(reset);
}