blob: ffd6659b8082d5396f66957b8215f233e697a383 (
plain)
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
|
// Collection of permalink-related functions (permalinks.js)
HashOverConstructor.prototype.permalinks = {
// Returns the permalink of a comment's parent
getParent: function (permalink, flatten)
{
flatten = flatten || false;
var parent = permalink.split ('r');
var length = parent.length - 1;
// Limit depth if in stream mode
if (this.parent.setup['stream-mode'] === true && flatten === true) {
length = Math.min (this.parent.setup['stream-depth'], length);
}
// Check if there is a parent after flatten
if (length > 0) {
// If so, remove child from permalink
parent = parent.slice (0, length);
// Return parent permalink as string
return parent.join ('r');
}
return null;
},
// Find a comment by its permalink
getComment: function (permalink, comments)
{
// Run through all comments
for (var i = 0, il = comments.length; i < il; i++) {
// Return comment if its permalink matches
if (comments[i].permalink === permalink) {
return comments[i];
}
// Recursively check replies when present
if (comments[i].replies !== undefined) {
var comment = this.getComment (permalink, comments[i].replies);
if (comment !== null) {
return comment;
}
}
}
// Otherwise return null
return null;
},
// Generate file from permalink
getFile: function (permalink)
{
return permalink.slice(1).replace(/r/g, '-').replace ('-pop', '');
}
};
|