@@ -17,56 +17,55 @@ Finds out where a tiddler originates from and what other tiddlers originate from
17
17
titlesPointingToBase = [ ] ;
18
18
19
19
function addToResultsIfNotFoundAlready ( list , title ) {
20
- if ( list . includes ( title ) ) {
20
+ if ( list . indexOf ( title ) !== - 1 ) {
21
21
return false ;
22
22
}
23
23
list . push ( title ) ;
24
24
return true
25
25
}
26
26
27
- function collectTitlesPointingFrom ( tiddler , title , currentDepth = 0 ) {
27
+ function collectTitlesPointingFrom ( tiddler , title , currentDepth ) {
28
28
if ( ( options . depth ) && ( currentDepth ++ > options . depth ) ) {
29
29
return ;
30
30
}
31
31
if ( addToResultsIfNotFoundAlready ( titlesPointingFromBase , title ) ) {
32
32
if ( tiddler ) {
33
33
$tw . utils . each ( tiddler . getFieldList ( options . fieldName ) , function ( targetTitle ) {
34
- collectTitlesPointingFrom ( $tw . wiki . getTiddler ( targetTitle ) , targetTitle , currentDepth ) ;
34
+ collectTitlesPointingFrom ( options . wiki . getTiddler ( targetTitle ) , targetTitle , currentDepth ) ;
35
35
} ) ;
36
36
}
37
37
}
38
38
}
39
39
40
- function collectTitlesPointingTo ( title , currentDepth = 0 ) {
40
+ function collectTitlesPointingTo ( title , currentDepth ) {
41
41
if ( ( options . depth ) && ( currentDepth ++ > options . depth ) ) {
42
42
return ;
43
43
}
44
44
if ( addToResultsIfNotFoundAlready ( titlesPointingToBase , title ) ) {
45
- $tw . utils . each ( $tw . wiki . findListingsOfTiddler ( title , options . fieldName ) , function ( targetTitle ) {
45
+ $tw . utils . each ( options . wiki . findListingsOfTiddler ( title , options . fieldName ) , function ( targetTitle ) {
46
46
collectTitlesPointingTo ( targetTitle , currentDepth ) ;
47
47
} ) ;
48
48
}
49
49
}
50
50
51
51
if ( ( options . direction === "from" ) || ( options . direction === "with" ) ) {
52
- collectTitlesPointingFrom ( baseTiddler , baseTitle ) ;
52
+ collectTitlesPointingFrom ( baseTiddler , baseTitle , 0 ) ;
53
53
}
54
54
if ( ( options . direction === "to" ) || ( options . direction === "with" ) ) {
55
- collectTitlesPointingTo ( baseTitle ) ;
55
+ collectTitlesPointingTo ( baseTitle , 0 ) ;
56
56
}
57
57
return $tw . utils . pushTop ( titlesPointingFromBase , titlesPointingToBase ) ;
58
58
}
59
59
60
60
/*
61
- Export our filter function
62
-
63
- TODO: May I add tests? (editions/test/tiddlers/tests)
64
- */
61
+ Export our filter function
62
+ */
65
63
exports . kin = function ( source , operator , options ) {
66
64
var results = [ ] ,
67
65
needsExclusion = operator . prefix === "!" ,
68
66
suffixes = operator . suffixes || [ ] ,
69
- suffixOptions = {
67
+ filterOptions = {
68
+ wiki : options . wiki ,
70
69
fieldName : ( ( suffixes [ 0 ] || [ ] ) [ 0 ] || "tags" ) . toLowerCase ( ) ,
71
70
direction : ( ( suffixes [ 1 ] || [ ] ) [ 0 ] || "with" ) . toLowerCase ( ) ,
72
71
depth : Number ( ( suffixes [ 2 ] || [ ] ) [ 0 ] ) ,
@@ -78,8 +77,8 @@ Finds out where a tiddler originates from and what other tiddlers originate from
78
77
79
78
if ( operator . operand !== "" ) {
80
79
var baseTitle = operator . operand ,
81
- baseTiddler = $tw . wiki . getTiddler ( baseTitle ) ,
82
- foundTitles = collectTitlesRecursively ( baseTiddler , baseTitle , suffixOptions ) ;
80
+ baseTiddler = options . wiki . getTiddler ( baseTitle ) ,
81
+ foundTitles = collectTitlesRecursively ( baseTiddler , baseTitle , filterOptions ) ;
83
82
84
83
source ( function ( tiddler , title ) {
85
84
if ( needsExclusion !== foundTitles . includes ( title ) ) {
@@ -88,7 +87,7 @@ Finds out where a tiddler originates from and what other tiddlers originate from
88
87
} ) ;
89
88
} else {
90
89
source ( function ( tiddler , title ) {
91
- results = $tw . utils . pushTop ( results , collectTitlesRecursively ( tiddler , title , suffixOptions ) ) ;
90
+ results = $tw . utils . pushTop ( results , collectTitlesRecursively ( tiddler , title , filterOptions ) ) ;
92
91
} ) ;
93
92
}
94
93
0 commit comments