mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-22 17:28:44 +00:00
Add untrack method to filter tracker
This commit is contained in:
@@ -15,6 +15,7 @@ Class to track the results of a filter string
|
|||||||
function FilterTracker(wiki) {
|
function FilterTracker(wiki) {
|
||||||
this.wiki = wiki;
|
this.wiki = wiki;
|
||||||
this.trackers = [];
|
this.trackers = [];
|
||||||
|
this.nextTrackerId = 1;
|
||||||
this.wiki.addEventListener("change",this.handleChangeEvent.bind(this));
|
this.wiki.addEventListener("change",this.handleChangeEvent.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ FilterTracker.prototype.handleChangeEvent = function(changes) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Add a tracker to the filter tracker
|
Add a tracker to the filter tracker. Returns null if any of the parameters are invalid, or a tracker id if the tracker was added successfully
|
||||||
filterString: the filter string to track
|
filterString: the filter string to track
|
||||||
fnEnter: function to call when a title enters the filter results. Called even if the tiddler does not actually exist. Called as (title), and should return a truthy value that is stored in the tracker as the "enterValue"
|
fnEnter: function to call when a title enters the filter results. Called even if the tiddler does not actually exist. Called as (title), and should return a truthy value that is stored in the tracker as the "enterValue"
|
||||||
fnLeave: function to call when a title leaves the filter results. Called as (title,enterValue)
|
fnLeave: function to call when a title leaves the filter results. Called as (title,enterValue)
|
||||||
@@ -32,17 +33,28 @@ fnChange: function to call when a tiddler changes in the filter results. Only ca
|
|||||||
*/
|
*/
|
||||||
FilterTracker.prototype.track = function(filterString,fnEnter,fnLeave,fnChange) {
|
FilterTracker.prototype.track = function(filterString,fnEnter,fnLeave,fnChange) {
|
||||||
// Add the tracker details
|
// Add the tracker details
|
||||||
var index = this.trackers.length;
|
var tracker = {
|
||||||
this.trackers.push({
|
id: this.nextTrackerId++,
|
||||||
filterString: filterString,
|
filterString: filterString,
|
||||||
fnEnter: fnEnter,
|
fnEnter: fnEnter,
|
||||||
fnLeave: fnLeave,
|
fnLeave: fnLeave,
|
||||||
fnChange: fnChange,
|
fnChange: fnChange,
|
||||||
previousResults: [], // Results from the previous time the tracker was processed
|
previousResults: [], // Results from the previous time the tracker was processed
|
||||||
resultValues: {} // Map by title to the value returned by fnEnter
|
resultValues: {} // Map by title to the value returned by fnEnter
|
||||||
});
|
};
|
||||||
|
this.trackers.push(tracker);
|
||||||
// Process the tracker
|
// Process the tracker
|
||||||
this.processTracker(index);
|
this.processTracker(this.trackers.length - 1);
|
||||||
|
return tracker.id;
|
||||||
|
};
|
||||||
|
|
||||||
|
FilterTracker.prototype.untrack = function(id) {
|
||||||
|
for(var t=0; t<this.trackers.length; t++) {
|
||||||
|
if(this.trackers[t].id === id) {
|
||||||
|
this.trackers.splice(t,1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
FilterTracker.prototype.processTrackers = function() {
|
FilterTracker.prototype.processTrackers = function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user